How to find specific frequency from image?
33 views (last 30 days)
Show older comments
I have taken the Fourier transform of the following image (showing zoomed image to better explain my question):
and got the following result after taking the log:
basic idea is to remove the frequencies of the white and black circles with the low pass filter i.e., get the frequency values of brighter points of vertical and horizontal white lines in Fourier image.
Attached is the shifted magnitude after FFT:
I am using 'ginput' command to select value from fourier image but am getting no luck in that and exponent to remove log results in Inf. Any suggestions on how to remove these frequencies and how to get their values?
2 Comments
Anton Semechko
on 11 Sep 2018
First issue. The DFT of the image should have the same dimensions as the original image. In your case, it does not. Post your code here so we can see how you computed the DFT.
Answers (2)
Image Analyst
on 11 Sep 2018
If you just want to set black circles (islands) in a sea of white to white, and white circles in a sea of black to black, I think the simplest, and most accurate, way is to do it in the spatial domain. Just find the spots using thresholding and bwareafilt(), then set those to the opposite color. Very simple.
Image Analyst
on 11 Sep 2018
OK, try this, if you just want to get rid of the circles:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
folder = pwd;
baseFileName = 'capture.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Display the image.
subplot(2, 3, 1);
imshow(rgbImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
grayImage = rgbImage; % Initialize.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = grayImage(:, :, 1); % Take red channel.
end
% Display the image.
subplot(2, 3, 2);
imshow(grayImage, []);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
drawnow;
% Display the histogram.
subplot(2, 3, 2);
imhist(grayImage);
grid on;
title('Histogram of Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Find the black spots
binaryImage = grayImage > 128;
blackSpots = ~binaryImage;
% Find the size of the black spots.
props = regionprops(blackSpots, 'Area');
allAreas = [props.Area]
% They seem to be in the 100-500 pixel range.
% Extract blobs of only that size.
blackSpots = bwareafilt(blackSpots, [100, 500]);
% Display the black spots image.
subplot(2, 3, 3);
imshow(blackSpots, []);
caption = sprintf('Black Spots Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
drawnow;
% Set these to white
binaryImage(blackSpots) = true;
% Display the binary image.
subplot(2, 3, 4);
imshow(binaryImage, []);
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo;
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
drawnow;
% Now get rid of black spots
% They seem to be in the 100-500 pixel range.
% Extract blobs of only that size.
binaryImage = bwareafilt(binaryImage, [500, inf]);
% Display the final image.
subplot(2, 3, 5);
imshow(binaryImage);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('Final Image.');
title(caption, 'FontSize', fontSize);
drawnow;
6 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!