High Pass filter fft2 on the coin image
10 views (last 30 days)
Show older comments
So I am trying to convertet the following image using a low pass filter and subtracting it from the orginal image to get only a high pass filter image. But I cannot figure a way in which to subtract the images. I have displayed the code that I have written so far below. As you will see I have use a low pass filter matrix, a applied it to the freq domiain , I am at a loss in what to do next. Any help would be much appreciated.

My code is as follows
%reading in the image
A=imread('coins.png');
%applying fouire transform shift to zero postion and fouire transform for
%2D
D = fftshift(fft2(A));
%defing the filter, Low pass filter
h = (1/9).*[1,1,1;1,1,1;1,1,1];
%apllying filter to the freqencey domian
B1=filter2(h1,D);
B1 = uint8(round(B1));
G=ifft2(B1);
E=imshow(log((abs(G))));]
1 Comment
Brian Hart
on 15 Nov 2018
Hi Jason,
Short answer, you can subtract them. You may have been running in to some data type issues (A is a uint8, and E is a double). The code below displays the subtraction result (although it's not interesting yet).
Longer answer, there are some scaling details involved with doing the FFT, which I forget. But basically you're subtracting small values from big values, so you don't see much difference. The colorbars can be useful for debugging this kind of thing.
Sorry to not be more helpful.
%reading in the image
A=imread('coins.png');
figure;imagesc(A);colormap gray;colorbar
%applying fouire transform shift to zero postion and fouire transform for
%2D
D = fftshift(fft2(A));
%defing the filter, Low pass filter
h1 = (1/9).*[1,1,1;1,1,1;1,1,1];
%apllying filter to the freqencey domian
B1=filter2(h1,D);
B1 = uint8(round(B1));
G=ifft2(B1);
E=(log((abs(G))));
figure;imagesc(E);colormap gray;colorbar
figure;imagesc(double(A)-E);colormap gray;colorbar
Answers (0)
See Also
Categories
Find more on Image Filtering and Enhancement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!