# Laplacian filter in matlab

I want to compute the output image by first dividing the image into 8*8 blocks and applying laplace filter separately and combine them but I am not getting the correct output Here is the code:

I=imread('moon.tif');
figure;
imshow(I);
title('Original Image');
g=[0 1 0;1 -4 1;0 1 0];
[N, M] = size(I);
output = zeros(N,M);
for i=1:8:N
for j=1:8:M
a = min(i+7,N);
b = min(j+7,M);
img = I(i:a,j:b);
r = imfilter(im2double(img),g);
output(i:a,j:b) = im2double(img)-r;
end
end
figure;
imshow(output);


Here is the output I am getting blocks by blocks discontinuous But when I run this code

I=imread('moon.tif');
figure;
imshow(I);
title('Original Image');
g=[0 1 0;1 -4 1;0 1 0];
resp=imfilter(I,g);
output = I-resp;
figure;
imshow(output);
title('Sharpened image');


I am getting the correct output. How to get this by dividing the image into 8x8 blocks and combining them

• Are you after how to implement image processing algorithm by image tiling or juts understanding how convolution works? – Royi Feb 25 at 17:42
• @Royi I want to apply the filter to 8*8 blocks of image and check the PSNR – YASHWANTH M Feb 26 at 7:50
• Laplacian filter works in a rolling window manner (Convolution). Hence I'm asking if the 8 x 8 is for working in a tiling method? If not, what you're asking doesn't make sense. – Royi Feb 26 at 9:09
• @Royi yes it is – YASHWANTH M Feb 27 at 12:23