Matlab Report
Matlab Report
ON
EDGE DETECTION
2022
CANDIDATES’ DECLARATION
Approach:
For edge detection, we take the help of convolution:
Convolution = I * m where I is the image, m is the
mask and * is convolutional operator. To perform
convolution on an image following steps are required:
1. Flip the mask horizontally and then vertically.
This will result in 180-degree rotation of an
image.
2. Slide the mask onto the image such that every
pixel in the image coincides with the centre of the
mask at least once.
3. Multiply the corresponding elements with the
pixel values below it and then add them.
4. Repeat this procedure until all pixel values of the
image have been calculated for updation.
THE CODE:
I=double(imread('image.jpg'));
In=I;
mask1=[1, 0, -1;1, 0, -1;1, 0, -1];
mask2=[1, 1, 1;0, 0, 0;-1, -1, -1];
mask3=[0, -1, -1;1, 0, -1;1, 1, 0];
mask4=[1, 1, 0;1, 0, -1;0, -1, -1];
mask1=flipud(mask1);
mask1=fliplr(mask1);
mask2=flipud(mask2);
mask2=fliplr(mask2);
mask3=flipud(mask3);
mask3=fliplr(mask3);
mask4=flipud(mask4);
mask4=fliplr(mask4);
neighbour_matrix2=mask2.*In(i-1:i+1, j-1:j+1);
avg_value2=sum(neighbour_matrix2(:));
neighbour_matrix3=mask3.*In(i-1:i+1, j-1:j+1);
avg_value3=sum(neighbour_matrix3(:));
neighbour_matrix4=mask4.*In(i-1:i+1, j-1:j+1);
avg_value4=sum(neighbour_matrix4(:));
end
end
figure, imshow(uint8(I))
Refrences:
2. Google
5. Wikipedia