-1
這是我的預期輸出。如何在Matlab中實現帶通Butterworth濾波器?
但是,我得到下面的輸出。
什麼是錯我的源代碼?
源代碼
的main.m
clear_all();
I = gray_imread('woman.png');
d0 = 1;
d1 = 100;
n = 20;
J = butter_bandpass(I, d0, d1,n);
J = histeq(J);
K = {I, J};
imshowpair(I, J, 'montage');
butter_bandpass.m
function output_image = butter_bandpass(I, dL, dH,n)
I_double = double(I);
[Height, Width] = size(I_double);
I_double = uint8(I_double);
I_fft = fft2(I_double,2*Height-1,2*Width-1);
I_fft = fftshift(I_fft);
LowPass = ones(2*Height-1,2*Width-1);
HighPass = ones(2*Height-1,2*Width-1);
Kernel = ones(2*Height-1,2*Width-1);
for i = 1:2*Height-1
for j =1:2*Width-1
D = ((i-(Height+1))^2 + (j-(Width+1))^2)^.5;
LowPass(i,j)= 1/(1 + (D/dH)^(2*n));
HighPass(i,j)= 1 - (1/(1 + (D/dL)^(2*n)));
% Create Butterworth filter.
Kernel(i,j) = LowPass(i,j).*HighPass(i,j);
end
end
% apply filter to image
output_image = I_fft + Kernel.*I_fft;
% revert the image to spatial domain
output_image = ifftshift(output_image);
output_image = ifft2(output_image,2*Height-1,2*Width-1);
output_image = real(output_image(1:Height,1:Width));
output_image = uint8(output_image);
end
爲什麼要補充'I_fft'其篩選的結果?它不應該只是'Kernel。* I_fft'嗎?這就是頻域中卷積的定義。 @rayryeng, – rayryeng
,仍然不起作用。 – anonymous
你也是直方圖均衡。爲什麼? – rayryeng