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);
Best Answer