简体   繁体   English

为什么在 matlab 中使用逆傅立叶变换 ifft2() 时图像变暗?

[英]Why do I get a dark image when using inverse fourier transform ifft2() in matlab?

I believe there's something wrong when I convert it back using ifft2().我相信当我使用 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.我正在尝试通过创建一个矩阵 L 来使用理想的低通滤波器,该矩阵 L 具有一个半径为 50 的 1 的圆。如果你们能告诉我问题出在哪里,那就太好了。 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.正如评论中提到的,所有的int8铸件都是多余的。 You are also missing an ifftshift in the calculation of u .您在u的计算中也缺少一个ifftshift 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,[]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM