Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Jeff
Posts:
107
Registered:
2/27/10


Regionprops
Posted:
Jan 10, 2013 5:47 PM


"Duarte " <du.art.silv@gmail.com> wrote in message <kcmqrd$486$1@newscl01ah.mathworks.com>... > I'm trying to find the centroid of a thresholded xray image and for some reason only the xx coordinate is accurately found. I'm using the following code: > > link for example image: http://imageshack.us/a/img252/6186/p1s1ev11bw73.png > > I=imread('P1S1_E_V11_BW_73.tif'); > L=bwlabel(I); > s = regionprops(L, 'Centroid'); > imshow(L) > hold on > for k = 1:numel(s) > plot(s(k).Centroid(1), s(k).Centroid(2), 'r*') > end > hold off > > This code gives all the centroids of all labeled areas and seems to only get the one I need wrong as can be seen in the following link: > > > http://imageshack.us/photo/myimages/842/matlabcentroidtest.png/ > > I've also tried to extract just the labeled area of interest but I still get the same wrong centroid coordinates: > > I=imread('P1S1_E_V11_BW_73.tif'); > L=bwlabel(I); > LL=zeros(800); > for i=1:800 > for j=1:800 > if L(i,j)==20 > LL(i,j)=20; > end > end > end > sL = regionprops(LL, 'Centroid'); > imshow(LL) > hold on > for k = 1:numel(sL) > plot(sL(k).Centroid(1), sL(k).Centroid(2), 'r*') > end > hold off > > The result is basically the same. The next image shows the coordinates I get from the matlab found centroid and the representation of the actual centroid: > > http://imageshack.us/a/img687/1169/centeraccuratelocation.jpg > > Thanks
The centroid that is being returned is based upon the bounding box of the WHITE ring object. The many, and uneven, protrusions will affect the bounding box. It looks like what you want is the centroid of the interior dark circle. Take the inverse of your mask, clear the boundary objects, and you'll have something closer to the ideal centroid you posted. The following code is what I used with the raw image you posted:
I=imread('p1s1ev11bw73.png'); I = ~im2bw(rgb2gray(I)); I = imclearborder(I); L=bwlabel(I); s = regionprops(L, 'Centroid'); imshow(L) hold on for k = 1:numel(s) plot(s(k).Centroid(1), s(k).Centroid(2), 'r*') end hold off


Date

Subject

Author

1/10/13


Jeff

1/11/13


Jeff


