MATLAB Answers


Measure distance between two object with same color automatically

Asked by bimo prasetyo on 6 Oct 2019
Latest activity Commented on by Image Analyst
on 10 Oct 2019
how do I measure distances in object which has the same colors from this image, for example the distance between "red" and "red. Thanks for your help.multicolor.jpg

  1 Comment

YOu should group object with the same color i think

Sign in to comment.

1 Answer

Answer by Image Analyst
on 6 Oct 2019

First you need to segment the image to find all the "red" regions. I have some demos for color segmentation in my File Exchange. Or you could use the Color Thresholder app on the apps tab of the tool ribbon.
Once you have a mask of the red regions, you can ask regionprops() for the centroids.
Then, with the centroids, you can use pdist2(), in the Statistics and Machine Learning Toolbox, to find the distance of every blob to every other blob.


Show 1 older comment
Explain what "connect" means to you. Do you want to draw a line between the two centroids?
yes Image Analyst , I want to draw a line between two centroids which the line represents their distances. I hope you can correct the coding above or give the correct coding.
Use the Color Thresholder app on the Apps tab of the tool ribbon to create a mask. Then call regionprops(mask, 'Centroid') to get the centroids. Then use plot() or line() to draw a line between each pair of centroids. Can you try it?

Sign in to comment.