Princess Ash
Princess Ash

Reputation: 1

What does the derivative do to an image

for the code below, I was asked a question why did I took derivative in laplacian filter. and what the derivative actually do to an image. also can u tell me what the line 18 means i.e. original_image - filtered_image

close all
clear all
j=imread('blur.png');
A = j(:,:,1);
figure,imshow(A); title('Original Image')
Original_image=A;
Filtered_Image=zeros(size(A));
F=[1 1 1;1 -8 1; 1 1 1];
A=double(A);
for k=1:size(A,1)-2
for j=1:size(A,2)-2
Filtered_Image(k,j)=sum(sum(F.*A(k:k+2,j:j+2)));

end
end
Filtered_Image= uint8(Filtered_Image);
figure,imshow(Filtered_Image);title('Filtered Image');
Deblurred_image=Original_image-5*Filtered_Image;
figure,imshow(Deblurred_image);title('Deblurred Image');

Upvotes: 0

Views: 705

Answers (1)

andrew
andrew

Reputation: 2469

F is a Laplacian of Gaussian (LoG) kernel (2nd derivative), it is used to find edges inside of an image.

We usually use derivatives to find edges in an image because the derivative tells the rate of change. In an image an edge is usually marked by sharp changes in intensity which means they also have a large derivative. The first derivative usually shows a max or min at an edge. We usually threshold the first derivative to find an edge. Second derivative detectors, like the LoG are actually mark edges by a zero crossing. Look at the 2nd derivative kernal, it increases the contrast of the pixels arund an edge, the edge itself is 0. Both methods are meant to exaggerate edges enter image description here

back to your question. If our filtered image is the result of our LoG operation that means Filtered_Image contains the edges of our image. So if we subtract the edges from the image original - filtered we are actually emphasizing the edges.

Upvotes: 3

Related Questions