- Easy way: round the coordinates returned from regionprops and use those as indices to get the centroid. Harder way is to interpolate that point based on its 4 nearest neighbors.
- You absolutely can do it all in one m-file. It really depends on the application whether you want to or not. If it's a simple one line threshold (eg. bw = x>50) then definitely do it in one file. If it's something more complicated (eg. distance to the nearest location on the convex hull of an image of connected tauri) then you probably want a second m-file designed specifically for that.
how i know the value of a pixel in a centroid of image
3 views (last 30 days)
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
0 Comments
Accepted Answer
Sean de Wolski
on 5 May 2011
10 Comments
More Answers (1)
Sean de Wolski
on 6 May 2011
All figures were closed, all variables cleared. Perhaps you need to clear your figure?
5 Comments
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!