Image Analyst please give me some idea.How can i do that for both regular and near regular texture image.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
I have the following image .I want to find the frequency or time interval of the periodic pattern.
5 views (last 30 days)
Show older comments

I mean i want to find the periodic frequency peak.I know may be i have to use fft2 of matlab.But i could not ablle to see the frequency peak after applying the fft2.
</matlabcentral/answers/uploaded_files/45290/Capture.PNG> I want to find that kind of response from my image by using fft.Please help me.I have no idea how to do it. Thanks in advance

1 Comment
Answers (2)
Image Analyst
on 13 Feb 2016
I would not use fft2() because the frequency is so low that its spike will be located very close to the main peak at DC and you might not get good resolution. What I'd probably try is to use normalized cross correlation to find template match locations. Then threshold the correlation image and find the location of the weighted centroids with regionprops() and then inspect each centroid to find the average distance to the closest 6 neighbors. I attach a normxcorr2 demo. Using regionprops to get centroids and finding distances from each centroid to all the others is trivial by using a for loop, or even pdist2() if you have the Stats toolbox. Give it a shot and let us know how it went.
20 Comments
sheli whitson
on 13 Feb 2016
mean first i will find the repeating structures then find the center of the repeating structure ,then calculate the distances between each image center?right?
sheli whitson
on 13 Feb 2016
If i want to do it by fft how can i do that?I actually want to do it by fft.
Image Analyst
on 13 Feb 2016
Didn't you try fft2()??? I'm sure you must have, but what happened when you did it??? Please attach your code or error message. I can't know what went wrong with your code if you don't tell me what it is.
See attached demos.
sheli whitson
on 17 Feb 2016
Edited: Image Analyst
on 17 Feb 2016
Sorry image analyst for the late reply.Here is my code.
grayImage=imread('Capture12.png') ;
[rows columns numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
f = rgb2gray(grayImage);
end
fsx=50;
fsy=50;
dx=1/fsx;
dy=1/fsy;
[m,n]=size(f);
x=dx*(0:n-1);
y=dy*(0:m-1);
dfx=fsx/n;
dfy=fsy/m;
fx=(-fsx/2:dfx:fsx/2-dfx);
fy=(-fsy/2:dfy:fsy/2-dfy);
fftOriginal = fft2((f));
imshow(log(fftshift(fftOriginal)),[]);
Here is my result

When i tried to plot the fft image with respect to fx it is showing that result.

I do not know what exactly this image is showing. I actually want to find out the peak points that represent the repeated structures so that i can know the interval of repeated objects. How can i get that by using fft?
Image Analyst
on 17 Feb 2016
Well there you go. Now you know why I said to do it in the spatial domain, not the frequency domain.
Image Analyst
on 17 Feb 2016
It's harder because, as you can see, the pattern is more complicated. I'd start with flattening the pattern with adapthisteq(), then I'd assume the pattern is aligned with the rows and columns so I'd sum the image vertically and horizontally. Then use findpeaks to try to find the major peaks. Attached is an fft filtering demo (not sure if it uses that algorithm though).
sheli whitson
on 17 Feb 2016
Edited: sheli whitson
on 17 Feb 2016
Thank you.I will try your idea.The attached algorithms did not use this concept.
sheli whitson
on 17 Feb 2016
Hello Image Analyst , How can i sum the image vertically and horizontally?
Image Analyst
on 17 Feb 2016
verticalProfile = sum(grayImage, 2);
horizontalProfile = sum(grayImage, 1);
sheli whitson
on 17 Feb 2016
Here is my code .I actually did not under stand what to do with vertical and horizontal profile and how to use find peaks and what to plot.I read matlab findpeaks demo but did not understand how to use it in my case. grayImage=imread('Capture12.png'); figure; imshow(grayImage)
[rows columns numberOfColorChannels] = size(grayImage) if numberOfColorChannels > 1 f = rgb2gray(grayImage); end
J = adapthisteq(f); [m,n]=size(f) figure imshow(J) figure, imhist(J)
vprofile = sum(J, 2); hprofile = sum(J, 1);
fsx=50; fsy=50; dx=1/fsx; dy=1/fsy; [m,n]=size(f); x=dx*(0:n-1); y=dy*(0:m-1); dfx=fsx/n; dfy=fsy/m; fx=(-fsx/2:dfx:fsx/2-dfx); fy=(-fsy/2:dfy:fsy/2-dfy); r=fftshift(fft2(J)); dBspots = 20*log10(abs(r(m/2+1:m)));
[pks,locs] = findpeaks(dBspots,'MinPeakDistance',6);
Please help me.Thanks in advance.
Image Analyst
on 17 Feb 2016
You were supposed to call adapthisteq() on the spectrum, not the gray scale spatial domain image. And you were supposed to pass the profiles, not dBspots into findpeaks().
sheli whitson
on 18 Feb 2016
Edited: sheli whitson
on 18 Feb 2016
grayImage=imread('Capture12.png');
figure;
imshow(grayImage)
[rows columns numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1 f = rgb2gray(grayImage);
end
fsx=size(f,1);
fsy=size(f,2);
dx=1/fsx;
dy=1/fsy;
[m,n]=size(f);
x=dx*(0:n-1);
y=dy*(0:m-1);
dfx=fsx/n;
dfy=fsy/m;
fx=(-fsx/2:dfx:fsx/2-dfx);
fy=(-fsy/2:dfy:fsy/2-dfy);
r=log10(fftshift(fft2(f)));
plot(fx,r)
J=imread('untitled.tif');
[rows columns numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
g = rgb2gray(J);
end
j=adapthisteq(g);
vprofile=sum(j,2);
hprofile=sum(j,1);
[pk,MaxFreq] = findpeaks(vprofile,'NPeaks',1,'SortStr','descend');
Than what to plot? I plot(pk) and get an empty image.
Image Analyst
on 18 Feb 2016
I don't have time tonight to look at your code. In the meantime, read this and fix the formatting: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup so I can read it.
sheli whitson
on 18 Feb 2016
Edited: sheli whitson
on 18 Feb 2016
Here is my updated code
grayImage = imread('capture.png');
[rows columns numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1 f = rgb2gray(grayImage); end
h = size(f,2);
w = size(f,1);
g = zeros(h, w);
for x = 1:w
for y = 1:h
g(y,x) = g(y,x) +f(x,y);%image with zero frequency
end
end
% dft 2d NFFTY = 2^nextpow2(h); NFFTX = 2^nextpow2(w); % eliminate zero frequency component
av = sum(g(:)) / length(g(:));
g = g - av;
% sampling rate of 1
samplingfreq = 1000;
spatialfreqsx = samplingfreq/2*linspace(0,1,NFFTX/2+1);
spatialfreqsy = samplingfreq/2*linspace(0,1,NFFTY/2+1);
spectrum2D = fft2(g, NFFTY,NFFTX);
figure;
plot(spatialfreqsy, abs(spectrum2D(1:NFFTY/2+1, 1:NFFTX/2+1)));
xlabel('fy HZ')
ylabel('abs(y)')
figure;
plot(spatialfreqsx,abs(spectrum2D(1:NFFTY/2+1, 1:NFFTX/2+1)))
xlabel('fx HZ')
ylabel('abs(y)')
figure;
plot(spatialfreqsy,10*log10(
abs(spectrum2D(1:NFFTY/2+1, 1:NFFTX/2+1))));
xlabel('fy db')
ylabel('abs(y)')
figure;
plot(spatialfreqsx,10*log(abs(spectrum2D(1:NFFTY/2+1, 1:NFFTX/2+1))))
xlabel('fx db')
ylabel('abs(y)')

<<

>>

sheli whitson
on 18 Feb 2016
Here is my new image.

I want to know why I am getting the blue curve.It seems that blue curve is representing the peak points .Am I right?
sheli whitson
on 26 Feb 2016
Edited: sheli whitson
on 26 Feb 2016
Hello Image Analyst, I need your help.I am still trying to do this thing. Here is my code and i am getting some peaks.But I am not sure what exactly these peaks are showing .Can you please explain that?
clear all; close all; grayImage = imread('image1.png');
[rows , colums , numberOfColorChannels] =size(grayImage);
if numberOfColorChannels > 1
f = im2double(rgb2gray(grayImage));
end
figure; imshow(f)
[n,m] = size(f); % sampling freq Fs = 1; % zero padding
m = 2^nextpow2(m);
n = 2^nextpow2(n);
% Frequency spacing in pixels per pixel
fx = Fs*((-m/2:m/2-1)/m);
fy = Fs*((-n/2:n/2-1)/n);
% fftshift centers the zero frequency
spectrum2D = fftshift(fft2(f, n,m));
%spectrum2D = fftshift(fft2(f, n,m))
spectrum2D_abs = abs(spectrum2D);
% show fft2 results
figure;
imagesc(1+log10(spectrum2D_abs))
colormap gray
% frequency peaks
figure;
plot(fx(m/2+1:end),log10(spectrum2D_abs(n/2+1,m/2+1:end)))
xlabel('fx-Hz'); ylabel('Power/frequency/')
figure;
plot((fy(n/2+1:end)),100*log10(spectrum2D_abs(n/2+1 :end,m/2+1)),'r')
xlabel('fyHz');

ylabel('Power/frequency')

Another thing I want to know ,can i find the peak of repeating things by doing 1 dimensional fft (first taking row then column).I would be grateful if you could give me a demo code of applying 1d fft in 2 dimensional image.
Image Analyst
on 27 Feb 2016
Like I said, I don't think FFT is the way to go. Believe it or not we actually did this problem this week with some crystalline "balls" in a lattice structure in SEM images. We used delaunay triangles and found the mean and standard deviation of the separations between each ball and the neighbors defined by the delaunay triangulation. From the spacing, you can invert it to get the frequency.
sheli whitson
on 27 Feb 2016
Edited: sheli whitson
on 27 Feb 2016
Hello Image Analyst,
Now i am thinking to do it like that paper mentioned(fig-2b) if there are repeating structures i will get one peak for those structures and if there is another type of repeating structures i will get another peak so that i can decide how many different repeating structures are present in my image.But they did not mention how they plot the result.So how can get similar types of plots ? Is that possible to do that by using fft like they did or by using your technique?Finally I will apply similar techniques on other images .
Thank you very much .If fft technique is not working i have to show someone the prove.That is why I am trying to do it by using fft.I hope you understand .Thanks again for your help. I am looking forward to hear from you.
sheli whitson
on 28 Feb 2016
Edited: sheli whitson
on 28 Feb 2016
Hello Image Analyst,
Do you have any suggestion how can i get similar peaks by using the attached paper's technique?I actually could not under stand what they plot(fig-2b). Thanks in advance
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)