# Tile 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
Commented Feb 25, 2021 at 17:42
• @Royi I want to apply the filter to 8*8 blocks of image and check the PSNR Commented Feb 26, 2021 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
Commented Feb 26, 2021 at 9:09
• @Royi yes it is Commented Feb 27, 2021 at 12:23

If you want to work with tiles of 8x8 you need to take bigger tiles.
Assuming the filter radius is r (In your case r = 1) then the tiles should be (8 + 2r)x(8 + 2r).
So in the above, take tiles of 10x10 and use only their center part.
So you process 8x8 tile by taking 10x10 window, apply the filter and return the center of 8x8 pixels.