已阅: 74
目的
原理
- 使用傅里叶变化,转成频域。
- 将频率低的部分移动至中心。
- 以中心为原点设定距离阈值。
- 根据距离阈值进行频率滤波。
- 滤波后将频率低的部分复位。
- 使用傅里叶逆变换,得结果。
- 代码框架:
F = fft2(imgGray); %傅里叶变换
F1 = fftshift(F); %低频移中心
G(u, v) = H(u, v) .* F1(u, v); %滤波函数H与频率域F1点乘
G2 = fftshift(G); %低频复位
imgResult = ifft2(G2); %傅里叶逆变换
实验结果
代码
clear;
img = imread('lena_color.jpg');
imgGray = rgb2gray(img);
[height, width] = size(imgGray);
histArray = zeros(1, 256);
%The Fourier transform
FTransform = fft2(imgGray);
FTransformCenter = fftshift(FTransform);
%Ideal low-pass
IdealLowPass = zeros(height, width);
IdealHighPass = zeros(height, width);
mid_width = width / 2;
mid_height = height / 2;
DLThreshold = 30;
DLThresholdExp2 = DLThreshold ^ 2;
DHThreshold = 10;
DHThresholdExp2 = DHThreshold ^ 2;
for row = 1:height
for col = 1:width
%Ideal low-pass
temp = ((row - mid_height)^2 + (col - mid_width)^2);
if temp < DLThresholdExp2
IdealLowPass(row, col) = 1;
end
if temp > DHThresholdExp2
IdealHighPass(row, col) = 1;
end
end
end
DLprocessCenter = IdealLowPass .* FTransformCenter;
DLprocess = fftshift(DLprocessCenter);
ImgDLprocess = uint8(ifft2(DLprocess));
DHprocessCenter = IdealHighPass .* FTransformCenter;
DHprocess = fftshift(DHprocessCenter);
ImgDHprocess = uint8(ifft2(DHprocess));
subplot(1, 3, 1)
imshow(imgGray), title('Origin');
subplot(1, 3, 2)
imshow(ImgDLprocess), title('The Fourier transform base on Ideal low-pass');
subplot(1, 3, 3)
imshow(ImgDHprocess), title('The Fourier transform base on Ideal high-pass');
共有 0 条评论