【发布时间】: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()绘制时,高斯峰大约是中心并且是圆形的。