4
$\begingroup$

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);

enter image description here

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');

enter image description here

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

$\endgroup$
4
  • $\begingroup$ Are you after how to implement image processing algorithm by image tiling or juts understanding how convolution works? $\endgroup$
    – Royi
    Commented Feb 25, 2021 at 17:42
  • $\begingroup$ @Royi I want to apply the filter to 8*8 blocks of image and check the PSNR $\endgroup$ Commented Feb 26, 2021 at 7:50
  • $\begingroup$ 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. $\endgroup$
    – Royi
    Commented Feb 26, 2021 at 9:09
  • $\begingroup$ @Royi yes it is $\endgroup$ Commented Feb 27, 2021 at 12:23

1 Answer 1

1
$\begingroup$

The problem is when filtering images there are boundary effects.

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.

Then you will have the same output as working on the whole image.

For code implementing the idea look at Apply 2D Convolution on an Image Using Tiles.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.