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 11, 2013 4:23 PM
|
|
"Duarte " <du.art.silv@gmail.com> wrote in message <kcnmka$k2m$1@newscl01ah.mathworks.com>... > "Jeff EA" <jea@gene.dot.com> wrote in message <kcngdc$t86$1@newscl01ah.mathworks.com>... > > "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 x-ray 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/my-images/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 > > Your solution does work for the dark circle and gives the same result when I use Photoshop to manually find it. Nevertheless, if I use photoshop to find the centroid of just the white ring, which I now understand was being computed with the first code, I still get horizontal error with the Photoshop centroid appearing more to the right. I should point out that vertically its perfect so it is indeed some kind of problem with the boundingbox. Perhaps that poltrusion to the right isn't inside the bounding box? Is there a way to see this box? > > However what I need is the centroid of the white ring plus the dark inner circle or in other words the centroid of the white ring outer edge. Then I have to figure out how to draw and compute the area of the smallest circle that encloses the white ring.
After checking the documentation for regionprops, I must offer my apologies. The centroid from regionprops is, in fact, a weighted centroid, and will depend upon the distribution of pixels. I incorrectly made an assumption between the "cetroid" and "weightedcentroid" outputs. The following code exemplifies the differences between centroid based on mass, and centroid based on bounding box:
I=imread('p1s1ev11bw73.png'); I = im2bw(rgb2gray(I)); I = bwareaopen(I, 500); L=bwlabel(I); s = regionprops(L, 'Centroid', 'BoundingBox'); imshow(L) hold on for k = 1:numel(s) plot(s(k).Centroid(1), s(k).Centroid(2), 'r*') plot(( s(k).BoundingBox(1,1) + s(k).BoundingBox(1,3) /2 ), ( s(k).BoundingBox(1,2) + s(k).BoundingBox(1,4)/2 ), 'b*') end hold off
|
|
|
Date
|
Subject
|
Author
|
|
1/10/13
|
|
Jeff
|
|
1/11/13
|
|
Jeff
|
|
|