How to detect a thick grid in an image
Show older comments
I need to determine the lattice constant in pixels and the angle with respect to the axes of the thick grid in a lot of images like the one below.
So i want to plot lines like in the image below and get the distance between two lines and the angle with respect to the axes.

This is my first try at image processing and my first idea was using fourier transformation because of the periodicity of the grid.
Without fully understanding how fourier works in 2D, i tried fft2() and filtered out frequencies with low amplitudes
%create image
I=imread('image','jpg');
I2= im2bw(I,0.2);
BW=-(I2-1);%invert image
%fourier
A=fft2(BW);
ma=max(abs(A),[],'all');
A(abs(A)<0.3*ma)=0;%remove small intensities
imagesc(ifft2(A))
Sadly after inverse fft for the frequencies with the highest amplitudes, the angles are always a little bit off.

The yellow lines are the invese fourier transformation of the frequency with the highest amplitude. As you can see the the yellow lines dont quite match the grid.
I alternativly tried to use hough() alongside edge(), but i only managed to properly detect thin lines this way.
I would be thankful for suggestions of better methods or corrections for the methods i used.
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!