Filter löschen
Filter löschen

edge detection using fourier transform

16 Ansichten (letzte 30 Tage)
adam
adam am 8 Aug. 2011
Kommentiert: Image Analyst am 9 Mär. 2016
i want to get edges of an image only using fourier transform(high pass filtering)without spatial filtering(like sobel).how can i do that

Antworten (3)

David Young
David Young am 3 Nov. 2011
See the code in my answer to this question.

Daniel Baboiu
Daniel Baboiu am 3 Nov. 2011
Fourier filtering methods are equivalent to spatial filtering methods (like Sobel). To get the derivatives, you have to find the corresponding filter in the Fourier domain:
fx*exp(-(fx^2+fy^2)/fw^2) - for the derivative in the x direction
fy*exp(-(fx^2+fy^2)/fw^2) - for the derivative in the y direction
where fx and fy are the corresponding spatial frequencies, and fw is the width of the Gaussian filter in the Fourier domain. Check "Numerical Recipes" and the link below for more details.

Image Analyst
Image Analyst am 3 Nov. 2011
Just take the FFT, then zero out the "corners" (or the center if you used fftshift) to get rid of the low spatial frequencies. Then inverse FFT and you're done. A parameter you decide on is how much you want to zero out - that says how much of the low spatial frequencies you're going to remove and how much high spatial frequencies will remain. Just copy and paste the demo below:
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'coins.png';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image - Spatial Domain', 'FontSize', fontSize);
% Enlarge figure to full screen.
% set(gcf, 'Position', get(0,'Screensize'));
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Take the FFT.
fftImage = fft2(grayImage);
% Shift it and take log so we can see it easier.
centeredFFTImage = log(fftshift(real(fftImage)));
% Display the FFT image.
subplot(2, 2, 2);
imshow(centeredFFTImage, []);
title('log(FFT Image) - Frequency Domain', 'FontSize', fontSize);
% Zero out the corners
window = 30;
fftImage(1:window, 1:window) = 0;
fftImage(end-window:end, 1:window) = 0;
fftImage(1:window, end-window:end) = 0;
fftImage(end-window:end, end-window:end) = 0;
% Display the filtered FFT image.
% Shift it and take log so we can see it easier.
centeredFFTImage = log(fftshift(real(fftImage)));
subplot(2, 2, 3);
imshow(centeredFFTImage, []);
title('Filtered log(FFT Image) - Frequency Domain', 'FontSize', fontSize);
% Inverse FFT to get high pass filtered image.
output = ifft2(fftImage);
% Display the output.
subplot(2, 2, 4);
imshow(real(output), []);
title('High Pass Filtered Image - Back in the Spatial Domain', 'FontSize', fontSize);
  2 Kommentare
John BG
John BG am 9 Mär. 2016
Dear Image Analyst,
would it be possible to have the images that you imshow along your answer to be interleaved in the text so readers get, never better said, a clear picture of procedure and result?
Regards
Image Analyst
Image Analyst am 9 Mär. 2016
John, sure:

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by