Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Regionprops
Replies: 3   Last Post: Jan 11, 2013 4:23 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jeff

Posts: 107
Registered: 2/27/10
Regionprops
Posted: Jan 10, 2013 5:47 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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


Date Subject Author
1/10/13
Read Regionprops
Jeff
1/11/13
Read Regionprops
Jeff

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.