How I can detect a set of dots is either rhombic or square lattice

algorithm, computer-vision, opencv, textures

Solution

One way to do it might be following:

Detect the circle using Hough transform but of course the centerpoints are approximate;

Choose arbitrary number of points to test. Number of points depends on how accurate you must be / how fast you need to process an image. Multiple points are needed to implement voting to reduce impact of errors. You can use any method to choose points - either complete random or semi random (random with certain point distribution across the image);

To detect orientation of grid for each point chosen do nearest neighbor search and find 4 nearest neighbors. Those neighbors will be on edges of the grid lines that goes through particular point. Depending on data-set size you could find neighbors by yourself with two `for` loops or you could use OpenCV `knnSearch` method from FLANN library (Fast Library for Approximate Nearest Neighbors);

When you have 4 nearest neighbors for each point, you need to determine orientation of lattice at specified point. For that you need to calculate vertical and horizontal distance between each sample point and it's neighbor. If the lattice is squared then Min(deltaX, deltaY) should be close to 0. If it is rhombic, then it will be about half of distance between each two points. Process all the neighbors and make a decision whether lattice it is square or rhombic at this point. Do that for every test point and collect results;

Process results and make final decision on lattice orientation depending on votes from each test point.

Problem

Suppose I have 2D images which contain dots and I can approximately detect each centerpoints of the dots, how I can detect it's either square lattice (square grid) or rhombic (rotated 45 degree)? Fortunately my images are regular and not deformed. The rhombic case is actually similar to square but it's only rotated 45 degree. The only issues are: - I can detect the circle using hough transform but of course the centerpoints are approximate. - The points do not necessarily fill the entire image (see image below) I have been thinking something similar to checkerboard pattern calibration in OpenCV (but of course no camera parameters),

Original source