How can I determine or generate the appropriate threshold value from the Fourier(Frequency) domain of an image ?

4 ビュー (過去 30 日間)
I am working on a code to extract the edges of any image using Fourier Transform but i have two(2) disturbing issues. Please find my codes and pictures of the stages of the image attached below. It is open for corrections and comments.
(i) I need the edges to display as black and others(background, etc) as white as against the edges been displayed as white as i have in the resulting image.
(ii) I also need a situation whereby when i convert an image to its frequency domain, I want to be able to determine the best threshold value through the frequency domain(probably having my codes generate the appropriate threshold value) rather than assuming a threshold value(e.g.30) for the edge extraction as this did not really effectively eradicate or smoothen out the ripples in the resulting image.
% Read in a standard image Standardimage = 'AEESS2.jpg'; Originalimage = imread(Standardimage);
% Display the original image imshow(Originalimage);
%Convert Original image to grayscale and display. grayImage = rgb2gray(Originalimage); imshow(grayImage);
% Display the original grayscale image. subplot(2, 2, 1); imshow(grayImage, [0 255]); title('Original Grayscale Image in its Spatial Domain', 'FontSize', 10); % Enlarge the figure to full screen. % set(gcf, 'Position', get(0,'Screensize')); set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Compute the FFT. FFTImage = fft2(grayImage); % Shift the zero frequency location from (0,0)to the center of the display % and take log in order to have a clearer display. centeredFFTImage = log(fftshift(real(FFTImage))); % Display the FFT image. subplot(2, 2, 2); imshow(centeredFFTImage, []); title('Visually Enhanced Frequency Domain of the Original Grayscale Image', 'FontSize', 9);
% 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;
% Shift the zero frequency location from (0,0)to the center of the display % and take log in order to have a clearer display. centeredFFTImage = log(fftshift(real(FFTImage))); subplot(2, 2, 3); imshow(centeredFFTImage, []); title('Visually Enhanced Frequency Domain of the Filtered image', 'FontSize', 10);
% Taking the Inverse FFT to convert the high pass filtered %image back to Spatial domain. output = ifft2(FFTImage); % Display the output. subplot(2, 2, 4); imshow(real(output), [0 255]); title('High Pass Filtered Image converted back to the Spatial Domain', 'FontSize', 10);

採用された回答

Image Analyst
Image Analyst 2013 年 12 月 31 日
For (i), just threshold
binaryImage = filteredImage < 2; % or whatever.
Edges will be black and everything else will be white.
for (ii) you need to determine this by trial and error. There is no divine method that says exactly when an edge turns from a sharp edge to a more gradual wrinkle - that's a judgement call on your part. So you need to determine how big the blackening rectangle in your Fourier domain should be.
  7 件のコメント
Image Analyst
Image Analyst 2014 年 1 月 5 日
An edge is a gradient, so it will have a positive spike before the edge and a negative spike after the edge, or vice versa. You can get either one, and depending on how you threshold it, the spike (either positive or negative) can be either black or white.
edges = edgeImage > 4;
edges = edgeImage < -4;
It doesn't matter much. Try each if you want.
Dipps
Dipps 2014 年 1 月 9 日
Good Day, Thanks so much for your answers and help, God bless your Heart. Please i need you to do me a favor. I have attached the original image i used in the code. Kindly copy and paste the codes in your Matlab window and held edit and include the additional codes that will turn or convert the edge lines from white to black and the other background to white. This will give you an idea of where i seem to be having problem because i keep getting an unsual image results. You can then post me the edited code here.
Thanks in expectant of your kind response. God Bless you.
Regards.
here is the code;
% Read in a standard image Standardimage = 'AEESS2.jpg'; Originalimage = imread(Standardimage);
% Display the original image imshow(Originalimage);
%Convert Original image to grayscale and display. grayImage = rgb2gray(Originalimage); imshow(grayImage);
% Display the original grayscale image. subplot(2, 2, 1); imshow(grayImage, [0 255]); title('Original Grayscale Image in its Spatial Domain', 'FontSize', 10); % Enlarge the figure to full screen. % set(gcf, 'Position', get(0,'Screensize')); set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Compute the FFT. FFTImage = fft2(grayImage); % Shift the zero frequency location from (0,0)to the center of the display % and take log in order to have a clearer display. centeredFFTImage = log(fftshift(real(FFTImage))); % Display the FFT image. subplot(2, 2, 2); imshow(centeredFFTImage, []); title('Visually Enhanced Frequency Domain of the Original Grayscale Image', 'FontSize', 9);
% 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;
% Shift the zero frequency location from (0,0)to the center of the display % and take log in order to have a clearer display. centeredFFTImage = log(fftshift(real(FFTImage))); subplot(2, 2, 3); imshow(centeredFFTImage, []); title('Visually Enhanced Frequency Domain of the Filtered image', 'FontSize', 10);
% Taking the Inverse FFT to convert the high pass filtered %image back to Spatial domain. output = ifft2(FFTImage); % Display the output. subplot(2, 2, 4); imshow(real(output), [0 255]); title('High Pass Filtered Image converted back to the Spatial Domain', 'FontSize', 10);
Thanks once again.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by