MATLAB Answers

show the position of centroids on the image

139 views (last 30 days)
Hassan on 17 Dec 2011
I have a binary image, BW and a grayscale image, I. I want to select only regions in the binary image with the same value that have an area > 50. for example there are 50 regions with area>50 and BW==1. I wonder how to show the position of the centroids of these regions with their number (1:50) on the image. Any suggestion?

Accepted Answer

Image Analyst
Image Analyst on 17 Dec 2011
Size filtering and finding and displaying centroids is done in my demo "BlobsDemo" as well as some other useful things.

More Answers (2)

bym on 17 Dec 2011
from the documentation:
I = imread('coins.png');
figure, imshow(I)
bw = im2bw(I, graythresh(getimage));
figure, imshow(bw)
bw2 = imfill(bw,'holes');
L = bwlabel(bw2);
s = regionprops(L, 'centroid');
centroids = cat(1, s.Centroid);
%Display original image and superimpose centroids.
plot(imgca,centroids(:,1), centroids(:,2), 'r*')
Hassan on 19 Dec 2011
thanks Image Analyst. your code was quite useful.

Sign in to comment.

Walter Roberson
Walter Roberson on 18 Dec 2011
If centroid #K is at position x, y, then to label that point on the graph with that number, use
  1 Comment
Hassan on 19 Dec 2011
thanks Walter. this was what I wanted to complete proecsm's code for my work.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!