Professional Documents
Culture Documents
1/ Write the function to calculate the Laplacian of Gaussian (LoG) kernel as follows:
The Laplacian L(x,y) of an image with pixel intensity values I(x,y) is given by:
( ( )
− x 2− y2 '
∆2(G ( x , y ) )=
1 −x− y
)
2
2σ
2 2
e
πσ 2σ
(( ) ( ) )
−x 2− y 2 2 2 −x 2− y 2
1 −1 2σ
2 −2 x −2 y 2σ
2
¿ 2
e + e
πσ σ2 4 σ2
( )
2 2
2 2 −x −y
−1 x +y 2σ
2
¿ 4
1− 2
e =log (x , y )
πσ 2σ
Matlab code:
For Gaussian filter:
2/ Generate a LoG kernel with Gaussian =1.0, using a size of 77. Apply this kernel to an
image (using convolution) and show the result (the original and filtered images).
7x7 LoG Mask:
1 2 3 4 5 6 7
1 0 0 1 1 1 0 0
2 0 1 3 3 3 1 0
3 1 3 0 -7 0 3 1
4 1 3 -7 -24 -7 3 1
5 1 3 0 -7 0 3 1
6 0 1 3 3 3 1 0
7 0 0 1 1 1 0 0
Matlab Code:
clc;
clear all;
close all;
image = imread('Coff.jpg');
I = rgb2gray(image);
for i=1:m
for j=1:n
temp = Im(i:i+6 , j:j+6);
temp = double(temp);
conv = temp.*kernel;
output(i,j) = sum(conv(:));
end
end
output = uint8(output);
Mask = [0 0 1 1 1 0 0; 0 1 3 3 3 1 0; 1 3 0 -7 0 3 1; 1 3
-7 -24 -7 3 1; 1 3 0 -7 0 3 1; 0 1 3 3 3 1 0; 0 0 1 1 1 0
0];
output2 = imfilter(output,Mask);
%Show original and Gaus filtered image and Laplacian
image
figure(1);
set(gcf,'position',get(0,'Screensize'));
subplot(131),imshow(image),title('Origin');
subplot(132),imshow(output),title('After Gaussian
Filter');
subplot(133),imshow(output2),title('After Laplacian
Filter');
Result:
Reference: https://academic.mu.edu/phys/matthysd/web226/Lab02.htm