MATLAB implementation of the first and second derivative of the image

Laplace operator based on second derivative

I=imread('11.jpg');
[H,W]=size(I);
M=double(I);
J=M;
for i=2:H-1
for j=2:W-1
J(i,j)=4*M(i,j)-[M(i+1,j)+M(i-1,j)+M(i,j+1)+M(i,j-1)];
end;
end;
subplot(1,2,1);imshow(I);title('2');
subplot(1,2,2);imshow(uint8(J));title('1');

Sobel operator based on first derivative

[I,map]=imread('9_1.jpg ');
[H,W]=size(I);
M=double(I);
J=M;
for i=2:H-1
for j=2:W-1
  J(i,j)=abs(M(i-1,j+1)-M(i-1,j-1)+2*M(i,j+1)-2*M(i,j-1)+M(i+1,j+1)-M(i+1,j-1))+abs(M(i-1,j-1)-M(i+1,j-1)+2*M(i-1,j)-2*M(i+1,j)+M(i-1,j+1)-M(i+1,j+1));
end;
end;
subplot(1,2,1);imshow(I);title('original');
subplot(1,2,2);imshow(uint8(J));title('sobel');

The effects of the first and second derivatives are summarized as follows:




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325650943&siteId=291194637