Measure distance between two object with same color automatically
古いコメントを表示
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.

1 件のコメント
darova
2019 年 10 月 6 日
YOu should group object with the same color i think
回答 (1 件)
Image Analyst
2019 年 10 月 6 日
0 投票
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.
5 件のコメント
bimo prasetyo
2019 年 10 月 7 日
Image Analyst
2019 年 10 月 7 日
Explain what "connect" means to you. Do you want to draw a line between the two centroids?
bimo prasetyo
2019 年 10 月 8 日
Image Analyst
2019 年 10 月 10 日
編集済み: Image Analyst
2020 年 1 月 22 日
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 this?
props = regionprops(mask, 'Centroid');
allCentroidsXY = vertcat(props.Centroid);
numBlobs = length(props);
hold on; % Don't let lines blow away image.
for k1 = 1 : (numBlobs - 1)
x1 = allCentroidsXY(k1, 1);
y1 = allCentroidsXY(k1, 2);
for k2 = (k1 + 1) : numBlobs
x2 = allCentroidsXY(k2, 1);
y2 = allCentroidsXY(k2, 2);
line([x1, x2], [y1, y2], 'Color', 'r', 'LineWidth', 2)
end
end
Hend Tayeb
2020 年 1 月 22 日
I tried it and its working! thank you
カテゴリ
ヘルプ センター および File Exchange で Image Thresholding についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!