Lattice drawing using blob centroids
조회 수: 3 (최근 30일)
이전 댓글 표시
How do I draw a line/lattice in between centroids determined from blob analysis? I have made a blob detection for a network of coins and I would like to have a lattice be drawn to show which coins are connected in the network.
This is a sample of what I am trying to do. The lattice showwn here was just manually drawn.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/912525/image.png)
And this is my code to get the centroids of the coins.
diskElem = strel('disk',110);
IBWopen = imopen(BW,diskElem);
hBlobAnalysis = vision.BlobAnalysis('MinimumBlobArea', 10000,'MaximumBlobArea',150000);
[objArea,objCentroid,bboxOut] = step(hBlobAnalysis, IBWopen);
댓글 수: 0
채택된 답변
Image Analyst
2022년 3월 3일
You can use pdist2(), in the stats toolbox, to find the distance between all centroids. From that you can easily find the smallest distance and I'd then extract all points that are closer than 1.5 times that distance and draw a line between them. Something like (untested)
props = regionprops(IBWopen , 'Centroid', 'EquivDiameter');
meanDiam = mean([props.EquivDiameter])
xy = vertcat(props.Centroid);
distances = pdist2(xy, xy);
hold on;
for k = 1 : size(distances, 1)
thisRow = distances(row, :);
closeIndexes = find(thisRow > 0 & thisRow < 1.5 * meanDiam);
% Draw lines
for k2 = 1 : length(closeIndexes)
x1 = xy(row, 1);
y1 = xy(row, 2);
x2 = xy(closeIndexes(k2), 1);
y2 = xy(closeIndexes(k2), 2);
plot([x1, x2], [y1, y2], 'k-', 'LineWidth', 2)
end
end
hold off;
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!