我正試圖在彩色圖像上應用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