According to Page#14 of this link, the equation for a high-pass Butterworth filter is,
And, according to Page#17, the output should be something like the following,
Now, I have looked at this answer in SO, and has written the following Matlab code using the formula given in the linked pdf document.
The output looks different than that of the one given above.
What is the possible problem in my source code?
Source Code
main.m
clear_all();
I = gray_imread('cameraman.png');
n = 1;
Dh = 10;
[J, Kernel] = butterworth_hp(I, Dh, n);
imshowpair(I, J, 'montage');
butterworth_hp.m
function [out, kernel] = butterworth_hp(I, Dh, n)
height = size(I, 1);
width = size(I, 2);
I_fft_shifted = fftshift(fft2(double(I)));
[u, v] = meshgrid(-floor(width/2):floor(width/2)-1,-floor(height/2):floor(height/2)-1);
kernel = butter_hp_kernel(u, v, Dh, n);
I_fft_shift_filtered = I_fft_shifted .* kernel;
out = real(ifft2(ifftshift(I_fft_shift_filtered)));
out = (out - min(out(:))) / (max(out(:)) - min(out(:)));
out = uint8(255*out);
function k = butter_hp_kernel(u, v, D0, n)
uv = u.^2+v.^2;
Duv = uv.^0.5;
frac = D0./Duv;
p = 2*n;
denom = frac.^p;
A = 0.414;
k = 1./(1+A*denom);
I have solved this problem.
The key to solving this problem was the function
ifftshow()
.Source Code
main.m
ifftshow.m
butter_hp_kernel.m
butterworth_hpf.m