how i know the value of a pixel in a centroid of image
Show older comments
i wanna ask, could we see the value of a centroid of an image
for example ; s = regionprops(BW, 'centroid');
can i know the pixel value of s ?
and 2nd i wanna ask.. i always try to combine 2 function or 2 jobs in 1 m.file but i always fail
for example i want to threshold picture and then i want to do some imageprocessing after threshold could i doing that in 1 m.file or i should seperate it into few m.file ?
can anyone help ? i'm a newbie in matlab :)
any help is appreciate
the code for the 2nd question :
I = imread('coins.png');
level = graythresh(I);
BW = im2bw(I,level);
s = regionprops(BW, 'centroid');
centroids = cat(1, s.Centroid);
imshow(BW)
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold off
Accepted Answer
More Answers (1)
Sean de Wolski
on 6 May 2011
0 votes

All figures were closed, all variables cleared. Perhaps you need to clear your figure?
5 Comments
danny agus
on 6 May 2011
Sean de Wolski
on 6 May 2011
You're probably running on an older (or newer) version. I'm on 2009b Mac. Use the bwconncomp code as I suggested:
I = imread('coins.png');
level = graythresh(I);
BW = im2bw(I,level);
CC = bwconncomp(BW);
s = regionprops(CC, 'centroid');
centroids = cat(1, s.Centroid);
imshow(BW)
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold off
danny agus
on 6 May 2011
Sean de Wolski
on 6 May 2011
That explains the difference. Try this:
I = imread('coins.png');
level = graythresh(I);
BW = im2bw(I,level);
L = bwlabel(BW);
s = regionprops(L, 'centroid');
centroids = cat(1, s.Centroid);
imshow(BW)
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold off
danny agus
on 6 May 2011
Categories
Find more on Work with Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!