Grid detection of irregular objects

2 views (last 30 days)
I would like to fit the holes in the following image to extract the holes' centers, the angle of rotation for the image (the angle in this image happens to be small), and the radii of the holes if they're fit to circles:
After perusing for solutions, I've realized that I'm not able to make much progress without converting this image to black and white, so I've done that:
It seems that detectCircleGridPoints with the asymmetric argument will be the way to go, but I can neither get it to detect any of the objects (perhaps since they're not perfect circles) nor to return the angle of rotation for the image or radii of the detected circles. Any advice for utilizing detectCircleGridPoints or some other approach for acquiring the centers, angle of rotation, and radii would be greatly appreciated! Here is my code:
% Read image
I = imread('rawimage.png');
% Convert image to bw
I = imbinarize(rgb2gray(I), 'adaptive', 'ForegroundPolarity', 'bright', 'Sensitivity', 0.5);
I = imopen(I, strel('disk', 5));
I = imfill(I,'holes');
I = bwareaopen(I, 1000);
I = im2uint8(I);
% Apply grid fit
patternDims = [4, 17];
imagePoints = detectCircleGridPoints(I,patternDims,PatternType="asymmetric");
% Visualize results
J = insertText(I,imagePoints,1:size(imagePoints,1));
J = insertMarker(J,imagePoints,'x',Color="green",Size=5);
title("Detected a Circle Grid of Dimensions " + mat2str(patternDims))

Accepted Answer

Image Analyst
Image Analyst on 2 Jul 2022
Not sure which of your poorly-named variables is your binary image mask, but you can use regionprops on it to get the equivalent circular diameter and the centroid.
mask = bwconvhull(mask, 'Objects'); % Take convex hull to get rid of dents in the perimeters.
props = regionprops(mask, 'EquivDiameter', 'Centroid')
As far as getting the angle of the rows of dots, you can use radon. Demo attached.
Write back if you still need help.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by