Lattice drawing using blob centroids
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sean Ivan Roxas
il 3 Mar 2022
Commentato: Sean Ivan Roxas
il 6 Mar 2022
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 Commenti
Risposta accettata
Image Analyst
il 3 Mar 2022
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;
2 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!