【问题标题】:Gaussian Circularly Symmetric Filter Applied to a Frequency Domain Image应用于频域图像的高斯圆对称滤波器
【发布时间】:2020-11-24 10:00:14
【问题描述】:

我在将高斯滤镜应用于图像时遇到问题,其中一项要求是确保它是圆对称滤镜。我不确定是否需要添加零填充序列,但请查看下面的代码,如果您能帮助我,请告诉我!谢谢!

请注意:我无法使用任何工具箱功能,否则这将非常简单明了。

L=256;
L1 = 255;
%load 'iptest_im.mat'
%ipFreq(iptest01)



[ImageX,ImageY] = size(A);


load 'iptest_im.mat';
A = iptest01;
A=double(A);  % Just in Case
Fourier=fft2(A);  
ABS_Fourier=abs(Fourier);

%Gaussian 
Gaussian=zeros(ImageX,ImageY);
sigma=5; % Sigma Values for Gaussian Filter **** WHERE YOU CHANGE
for i = 1:ImageX
    for j = 1:ImageY
            D = (i-ImageX/2)^2 + (j-ImageY/2)^2;
            Gaussian(i,j) = L1*exp(-(D)/(2*(sigma)^2));      
    end
end

GaussianFilt = fft2(Gaussian);
FourierFilt = Fourier .* GaussianFilt;


%Display for No shift
FFT_NoShift = abs((log10(FourierFilt+1)));
minA=min(min(FFT_NoShift));
FFT_NoShift = FFT_NoShift-minA; % shift
maxA = max(max(FFT_NoShift));
if maxA~=0
    FFT_NoShift=FFT_NoShift*L1/maxA; % compress or expand
end

%Display for Shift
FFT_Shifted = fftshift(abs(log10(FourierFilt+1)));
minA=min(min(FFT_Shifted));
FFT_Shifted = FFT_Shifted-minA; % shift
maxA = max(max(FFT_Shifted));
if maxA~=0
    FFT_Shifted=FFT_Shifted*L1/maxA; % compress or expand
end

InvFFT = abs(ifft2(FourierFilt));
%InvFFT = abs(ifft2(FFT_Shifted1));
%InvFFT = abs(ifft2(FFT_NoShift1));
 

【问题讨论】:

  • 在我看来是对称的,因为当用imshow() 绘制时,高斯峰大约是中心并且是圆形的。

标签: matlab frequency gaussian


【解决方案1】:

在谱分量相乘之前将高斯滤波器的傅里叶变换归一化为 1

在乘以频率分量之前对高斯核进行归一化将有助于进行适当的缩放。在这里,我使用高斯核的最大值将其所有分量归一化为 1。如果需要,您还可以将 fftshift() 应用于所有傅立叶频率分量,但可以得到相同的结果。要么移动所有光谱分量,要么不移动。您可能可以应用一些对数缩放,但我不完全确定围绕它的实现细节。

Greyscale_Image = rgb2gray(imread("peppers.png"));
[ImageX,ImageY] = size(Greyscale_Image);

Fourier_Transform = fft2(Greyscale_Image);

Gaussian = zeros(ImageX, ImageY);
sigma = 5; 
for i = 1: ImageX
    for j = 1:ImageY
            D = (i-ImageX/2)^2 + (j-ImageY/2)^2;
            Gaussian(i,j) = exp(-(D)/(2*(sigma)^2));      
    end
end

GaussianFilt = round(abs(fft2(Gaussian)));
%Normalizes the Guassian filter%
GaussianFilt = GaussianFilt./max(GaussianFilt,[],'all');


Reconstructed = uint8(ifft2(Fourier_Transform.*GaussianFilt));
imshow(Reconstructed);

使用 MATLAB R2019b 运行

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多