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!



