I believe there's something wrong when I convert it back using ifft2(). I am trying to use the ideal low-pass filter by creating a matrix L that has a circle with 1's with the radius 50. It would be great if you guys can tell me what the issue is. Thanks!
I0 = imread('image.png');
g = I0(:,:,1);
Rg = imref2d(size(g));
G = fft2(g);
AG1 = log(1+abs(G));
MaxVal = max(max(AG1));
AG2 = uint8(255*(AG1/MaxVal));
SAG2 = fftshift(AG2);
%zero matrix L with a circle with value 1's with radius 50
[xGrid,yGrid] = meshgrid(1:400,1:400);
L = sqrt((xGrid - 200).^2 + (yGrid - 200).^2) <= 50;
U = uint8(double(SAG2).*L);
a=ifft2(U);
u = uint8(real(ifft2(U)));
imshow(u,'InitialMagnification',300);
You are taking a whole bunch of unnecessary actions. As mentioned in the comments, all the int8
castings are redundant. You are also missing an ifftshift
in the calculation of u
. Here is a short version that does the low-passing you want:
I0 = imread('your_file.png');
g = I0(:,:,1);
G = fft2(g);
SAG2 = fftshift(G);
%zero matrix L with a circle with value 1's with radius 50
[xGrid,yGrid] = meshgrid(1:400,1:400);
L = sqrt((xGrid - 200).^2 + (yGrid - 200).^2) <= 50;
U = SAG2 .* L;
u = real(ifft2(ifftshift(U)));
figure
imshow(u,[]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.