Reputation: 13
I am currently learning how to filter images using Fourier transform in Matlab. I managed to apply a low pass filter on an image, the problem is, I cannot do the same with high pass filter. Here are codes and images that I got. Could you help me?
clc
clear
A=imread('3.tif'); % image size is 200 x 200
B=fftshift(fft2(A));
mask=zeros(200);
mask(80:120,80:120)=1;
C=mask.*B;
D=ifft2(C);
D=uint8(D);
imshow(D);
Here the results:
https://i.sstatic.net/Y2UaI.png
The problem occures when I try to apply an inverse mask, like so:
clc
clear
A=imread('3.tif'); % image size is 200 x 200
B=fftshift(fft2(A));
mask=zeros(200);
mask=mask+255;
mask(80:120,80:120)=0;
C=mask.*B;
D=ifft2(C);
D=uint8(D);
imshow(D);
Results:
https://i.sstatic.net/NzYNG.png
What is wrong?
Upvotes: 1
Views: 5476
Reputation: 4549
Change this on the second code:
mask=zeros(200);
mask=mask+255;
... to this
mask=ones(200);
You also forgot to call ifftshift
on both codes:
D=ifft2(ifftshift(C));
Here is what I got:
Upvotes: 3