Centroid calculation for connected component in 3D volume
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Amala Thampi
am 11 Sep. 2015
Kommentiert: Amala Thampi
am 14 Sep. 2015
I am trying to implement brain tumor segmentation on 3D brain MRI(.mha data type). After preliminary segmentation, I am applying 26-neighbor connected component algorithm(using bwconncomp) to obtain the largest connected component with maximum volume, following which I need to calculate the centroid of this connected component.
I am not sure if my method of calculating the largest connected component and the centroid is correct, because the centroid value obtained and its nearby voxels all have value 0. Also I dont know how 3D index is represented. For eg. if centroid=(x,y,z), does it correspond to x=row,y=column and z=2D slice?
Any help would be appreciated. Below is my code with the relevant part.
CC=bwconncomp(Ibin,26); %Input Black & White 3D data of size 240x240x155
Pixelid=regionprops(CC,'PixelIdxList');
[prow pcol]=size(Pixelid);
maxval=Pixelid(1).PixelIdxList;
index=1;
for i=1:prow
number=numel([Pixelid(i).PixelIdxList]); %calculating the component with max number of voxels
if(number>maxval)
maxval=number;
index=i;
end
end
for i=1:prow
if i~=index
Ibin(Pixelid(i).PixelIdxList)=0;
end
end
CC1=bwconncomp(Ibin,26);
Cent=regionprops(CC1,'Centroid');
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Sep. 2015
The Centroid returned can be fractional as it involves a mean.
The documentation of regionprops says for Centroid
"Returns a 1-by-Q vector that specifies the center of mass of the region. The first element of Centroid is the horizontal coordinate (or x-coordinate) of the center of mass, and the second element is the vertical coordinate (or y-coordinate). All other elements of Centroid are in order of dimension."
Note though that x coordinate corresponds to column in MATLAB, so if you want to use the centroid to index you should reverse the first two coordinates
Centstats = regionprops(CC1,'Centroid');
Cent = Centstats(1).Centroid;
crow = round(Cent(2));
ccol = round(Cent(1));
cplane = round(Cent(3));
pixel_nearest_centroid = Ibin(crow, ccol, cplane);
Even so keep in mind that for an area that is not strictly convex, that the centroid can be outside of the region. For example, for a region shaped like
* *
* *
****
the centroid is going to have to be between columns 2 and 3 (because it is symmetric around the horizontal axis) and it is going to have to be above the baseline (because there is mass above the baseline but no mass below the baseline), so the centroid would have to be at a location where there is no set pixel in the blob.
3 Kommentare
Walter Roberson
am 12 Sep. 2015
Use the two-output form and index the second output at the rounded centroid to find the index of the closest pixel in the region that is set.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!