How to find specific frequency from image?

30 views (last 30 days)
waqas
waqas on 11 Sep 2018
Commented: waqas on 17 Oct 2018
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
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.
waqas
waqas on 11 Sep 2018
Hi Anton,
Yeah I have uploaded zoomed image as it is not possible to see black and white dots without that. Size of image and DFT are the same in original code.
A = imread('QR_short.png');
figure(1);
imshow(A);
if ~islogical(A)
B = rgb2gray(A);
else
B=A;
end
% C = edge(B,'canny');
% imshow(C)
C= B;
fft_im = fft2(B);
ffts=fftshift(fft_im);
freqPeaks= figure(2);
plot(abs(ffts));
S= log(abs(ffts));
figure(3);
fourier_fig = imshow(S,[]);
zoom(figure(3))
[kx,ky]= ginput(3);
P.S I am new to DIP.

Sign in to comment.

Answers (2)

Image Analyst
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.
  1 Comment
waqas
waqas on 11 Sep 2018
I have a QR code in the image which i need to extract. Therefore I need to remove these black dots. Would your method work for that?

Sign in to comment.


Image Analyst
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
waqas
waqas on 13 Sep 2018
Thank you for the files. I am working on them. I do have one question. Since circles are the most frequent objects therefore there frequency would be closer central and will be low frequency value as well. Therefore I am choosing smaller values for the location of spikes with a little modification in the code. However, I am unable to understand to how to understand this part.
% Exclude the central DC spike. Everything from row 115 to 143.
brightSpikes(1000:1500, :) = 0;
imshow(brightSpikes);
title('Bright spikes other than central spike', 'FontSize', fontSize);
waqas
waqas on 17 Oct 2018
Hi Image Analyst,
I found the solution of the problem with notch filter but that only works for the case when image is perfectly in-plane (or we take original pattern). If we take the image with a camera at some angle, to mimic distortion, then notch filter does not work.
I tried to work around with your code of mask filter and am only filtering the highest frequencies other than DC component but the end result is just a noisy signal. Can you you guide on where exactly am I making the mistake?
Attached are the image and the updated code. (changed the format from tiff to jpg)

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!