clc;
A=imread('Penguins.jpg');
subplot(2,2,1);
imshow(A);
title('Main Image');
B=rgb2gray(A);
subplot(2,2,2);
imshow(B);
title('gray Image');
C=double(B);
for i=1:size(C,1)-2
for j=1:size(C,2)-2
%Sobel mask for x-direction:
Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
%Sobel mask for y-direction:
Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
%The gradient of the image
%B(i,j)=abs(Gx)+abs(Gy);
B(i,j)=sqrt(Gx.^2+Gy.^2);
end
end
subplot(2,2,3);
imshow(B);
title('Sobel gradient');
% D = edge(B,'canny',0.5,0.2);
% subplot(2,2,4);
% imshow(~D);
Thresh=100;
B=max(B,Thresh);
B(B==round(Thresh))=0;
B=uint8(B);
subplot(2,2,4);
imshow(~B);
title('Edge detected Image');