Centroids distance in pixel
古いコメントを表示
Hello everyone,
I am writing to ask for a suggestions.
I am working on high resolution images ( 5MP ) showing a evenly space dots grid. I would need to compute the euclidean distance between the dots centroids.
I used the "imfindcircles" function, which uses the CHT algorithm, to obtain the centers and radii of the dots of the images with good accuracy, Here the code lines and the resulting image:
[centers,radii] = imfindcircles(maskedImage,[4 18],'ObjectPolarity','dark','Sensitivity',0.9,'Method','twostage','EdgeThreshold',0.4);
viscircles(centers, radii,'LineStyle','--');

The varialble "centers" found is a matrix of two columns defining the x and y coordinates of all the centroids of the dots found in the image. I have not understood which is the order meaning of the dots centroids coordinates in this variable, it seems to be quite random.
Now what I would need to do is to compute the distance between each dot centroid and the centroids of the four closest dots. I would then obtain a matrix in which I will have 4 columns relatives to the four distances found for each dot. Attached an image for better explanation:

Do you have any idea of which could be an easy way to proceed? Is there any built in function I can use?
Please, let me know if something is not clear or I need to provide more information.
Thanks so much for your help!
1 件のコメント
If you want, it might help if you attached a lower-res example of one such image.
That said, there are a number of similar questions
This one was looking for the nearest neighbor, but could easily be changed to the 4-neighbors using mink() instead of min(). Sorting them by relative direction might be a bit of a complication.
採用された回答
その他の回答 (2 件)
KSSV
2021 年 8 月 25 日
0 投票
Read about the function knnsearch, this will give you the specified number of nearest points from a set of points for a given point along with distance.
Image Analyst
2021 年 8 月 25 日
編集済み: Image Analyst
2021 年 8 月 25 日
Looks like you could easily just threshold this to find the blobs
mask = grayImage < someThreshold;
Then call regionprops to get centroids
props = regionprops(mask, 'Centroid');
xy = vertcat(props.Centroid)
The numbering is not random, though it may seem like it. It numbers blobs from left to right as it scans the image and encounters them. And from top to bottom in the event two blobs start in the same column, like blobs 11 and 12 in the image below. See attached demo.

Use knnsearch() or pdist2() to find distance between points or sets of points, if you have the Statistics and Machine Learning Toolbox.
カテゴリ
ヘルプ センター および File Exchange で Read, Write, and Modify Image についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



