Lattice drawing using blob centroids
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sean Ivan Roxas
el 3 de Mzo. de 2022
Comentada: Sean Ivan Roxas
el 6 de Mzo. de 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.
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 comentarios
Respuesta aceptada
Image Analyst
el 3 de Mzo. de 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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!