我正试图在彩色图像上应用FFT。我提取了三个分量:红色,绿色和蓝色,然后我分别应用fft2
,然后我在每个平面上应用高斯滤波器。现在我试图在模糊后显示红色,绿色和蓝色的组件。之后,我申请ifft2
以获得结果。使用FFT和IFFT对彩色图像进行低通滤波
我的问题是我看到每个组件中的灰色图像。我试图只显示颜色平面,但我的代码不起作用。另外,我想将这三个组件结合在一起以返回到全彩色图像。我在下面写了下面的代码。谁能告诉我我做错了什么?
% Calculate FFT for R , G , B images
I = imread ('lena.jpg');
% Extract three images
Red = I (: , : , 1);
Green = I (: , : , 2);
Blue = I(: , : , 3);
f_r = fftshift (Red);
F_r = fft2 (f_r);
f_g = fftshift (Green);
F_g = fft2 (f_g);
f_b = fftshift (Blue);
F_b = fft2 (f_b);
% Calculate the gaussian filter then find its FFT
h = fspecial('gaussian', [512 512] , 3.0);
h = fftshift (h);
H = fft2(h); % Fourier Transform of 2D Gaussian
FF_R = H .* F_r ;
FF_G = H .* F_g;
FF_B = H .* F_b;
% This is to get red, green and blue images
b = zeros(512, 512);
% Inverse IFFT _RED
Ir = ifftshift(FF_R);
Irr= ifft2 (Ir);
I_R = fftshift (Irr);
IFF_R = 1 + log (abs(I_R));
figure , imshow (IFF_R , [ ]);
Con1 = im2uint8(IFF_R);
just_red_2 = cat(3, Con1, b, b);
figure, imshow (just_red_2);
% Inverse IFFT _Green
Ig = ifftshift(FF_G);
Igg= ifft2 (Ig);
I_G = fftshift (Igg);
figure , imshow (1+ log(abs(I_G)), [ ]);
just_green_2 = cat(3, b, I_G, b);
%figure, imshow (1 + log(abs(just_green_2)));
% Inverse IFFT Blue
Ib = ifftshift(FF_B);
Ibb= ifft2 (Ib);
I_B = fftshift (Ibb);
figure , imshow (1+ log(abs(I_B)), [ ]);
just_blue_2 = cat(3, b,b, I_B);
%figure, imshow (1 + log(abs(just_blue_2)));
%Combine the three component togather
%full_image2 = cat (3, FF_R , FF_G , FF_B);
full_image2 = cat (3, just_red_2 (:,:,1) , just_green_2(:,:,2) , just_blue_2(:, :, 3));
%full_image2 (: , : , 1) = FF_R (: , : , 1);
%full_image2 (: , : , 2) = FF_G (: , : , 2);
%full_image2 (: , : , 3) = FF_B (: , : , 3);
Full = ifft2 (ifftshift(full_image2));
figure, imshow (Full , [ ])
Final = fftshift(Full);
figure , imshow (full_image2)
感谢您的重播....其实这是要求申请FFT分别对高斯和3个图像进行乘法运算然后返回到颜色! ...如果我切换步骤,是否有任何问题? – Seereen2004 2014-11-04 22:05:13
@ Seereen2004 - 那么,您可以先对图像执行一次“ifftshift”,然后在此之后应用“fft”将光谱带到左上角。我不明白“切换步骤”的含义。 – rayryeng 2014-11-04 22:06:21
当我尝试你的代码我没有得到正确的图像! ......它需要再次移动......而我看到绿色是最多的! – Seereen2004 2014-11-04 22:14:26