Putting index on centroids determined from image processing

How can index each centroid determined from blob analysis?
hBlobAnalysis = vision.BlobAnalysis('MinimumBlobArea', 10000,'MaximumBlobArea',150000);
[objArea,objCentroid,bboxOut] = step(hBlobAnalysis, IBWopen);
So I have this part of my code that basically gets the centroid coordinates, what I would like to do is assign an index to each centroid determined and use it for an interative code later on.

Réponses (1)

You can do it this way
binaryImage = bwareafilt(binaryImage, [10000, 150000]);
props = regionprops(binaryImage, 'Centroid', 'BoundingBox');
xy = vertcat(props.Centroid);
imshow(binaryImage); % Display image.
hold on;
% Show boxes and centroids.
for k = 1 : length(props)
rectangle('Position', props(k).BoundingBox, 'EdgeColor', 'r');
xt = xy(k, 1);
yt = xy(k, 2);
str = sprintf(' (%.1f, %.1f)', xt, yt);
text(xt, yt, str, 'HorizontalAlignment', 'left', 'VerticalAlignment', 'middle')
plot(xt, yt, 'r+', 'MarkerSize', 30, 'LineWidth', 2)
end

4 commentaires

Thanks for responding, but I think you did not get exactly what I am trying to do. Attached above is the resulting image from the blob detection, as you can see on the right image, I have created a network wherein the nodes are the centroids of the coins and edges are created from the distance between the coins and its diameter (you actually helped me create this part as well). What I am trying to do now is to index each coin starting from the leftmost coin (index 1) to the rightmost coin (index N). Then I would create a vector that would contain the voltages of each coin (V_1,...,V_N) and another vector that would contain the current (I_1,...,I_N) such that it would update iteratively starting from the left coin then to its connected coins and so on until it reaches the rightmost coin. Then finally I will solve for the effective resistance via R = V/I.
Well of course I did not have your original image because you forgot to attach it. You said "gets the centroid coordinates, what I would like to do is assign an index to each centroid" so that is what I did. If your blobs are touching each other then you need to call imerode() to separate them.
The blob detection that I made is already okay as it is. Is there any way to index the coordinates? as in mathematically represent it?
I don't usually use the Computer Vision toolbox way of finding blobs. Are you in a loop? Can't you just index the values
[objArea(k), objCentroid(k), bboxOut(k,:)] = step(hBlobAnalysis, IBWopen);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by