这是我想出的代码。我发现了许多其他滤波方法,但我试图仅使用傅立叶变换对图像进行滤波。我试图将图像分割为三个通道,然后对每个图像进行fft和对数变换,但当我试图重新组合逆移位器图像时,我无法获得滤波后的图像。请在此处输入图像描述
clear all;
rgbImage = imread('simg.jpg');
clear all;
rgbImage = imread('simg.jpg');
figure(1);imshow(rgbImage); title('Original Image');
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(3, 4, 1);
imshow(rgbImage);
title('Original color Image', 'FontSize', 12);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the individual red, green, and blue color channels.
subplot(3, 4, 2);
imshow(redChannel);
title('Red Channel', 'FontSize', 12);
subplot(3, 4, 3);
imshow(greenChannel);
title('Green Channel', 'FontSize', 12);
subplot(3, 4, 4);
imshow(blueChannel);
title('Blue Channel', 'FontSize', 12);
fr1 = fft2(redChannel);
fr2 = fft2(greenChannel);
fr3 = fft2(blueChannel);
%FSF = cat(3,fr1,fr2,fr3);
Fsh1 = fftshift(fr1);
Fsh2 = fftshift(fr2);
Fsh3 = fftshift(fr3);
%subplot(3, 4, 5);
%imshow((Fsh1));
%title('Fsh1', 'FontSize', 12);
log1 = log(1+abs(Fsh1));
log2 = log(1+abs(Fsh2));
log3 = log(1+abs(Fsh3));
%subplot(3, 4, 6);
%imshow(real(log1));
%title('log1', 'FontSize', 12);
%FSF = cat(3, log1, log2, log3);
%FSF = cat(3,Fsh1,Fsh2,Fsh3);
%subplot(3, 4, 7);
%imshow(real(FSF));
%title('fsf', 'FontSize', 12);
frr1 = ifftshift(Fsh1);
frr2 = ifftshift(Fsh2);
frr3 = ifftshift(Fsh3);
FR = cat(3,frr1,frr2,frr3);
subplot(3, 4, 6);
imshow(abs(FR));
subplot(3, 4, 7);
logR = log(1+abs(FR));
imshow(real(FR));
f = ifft2(FR);
subplot(3, 4, 8);
imshow(abs(f))
title('final', 'FontSize', 12);
这似乎是一个数字类型的问题,它应该是uint8。尝试:
final = uint8(abs(f));
imshow(final)