How can I count the number of voxels in a region

12 Ansichten (letzte 30 Tage)
Gina Carts
Gina Carts am 2 Mär. 2020
Kommentiert: Gina Carts am 3 Mär. 2020
Hi,
I have a 3D mask with 0 background (NIfTI format). The mask has some regions marked with number 1,other egions with number 2, others with number 3 and others with number 4.
I was wondering how to count the number of voxels involved in each region. If I have 20 regions in my mask: let's say 10 regions have number 1, 5 regions have number 2, 4 regions have number 3 and 1 region have number 4.
I want to know how many voxels correspond to each of my 10 regions with number 1. I want the individual number of voxels in each region not the overall number.
Any help is highly appreciated.
  5 Kommentare
Gina Carts
Gina Carts am 2 Mär. 2020
When I typed the last line of code, I got the following error:
numVoxels = = cellfun(@numel,CC.PixelIdxList);
Error: The expression to the left of the equals sign is not a valid target for an assignment.
I changed it to
numVoxels = cellfun(@numel,CC.PixelIdxList);
I don't really understand the output though. It says that numVoxels is 1x66 double. Does it mean it has 66 regions with label 1?
I know that this mask has 57 regions each of which 49 have label 1.
How can I see the number of voxels for each region? I deleted the ; in the last line of code but I don't really understand what I see
Alex Mcaulley
Alex Mcaulley am 2 Mär. 2020
Hve you read the documentation of bwconncomp? There are some examples to see what this function does.
numVoxels is an array with the number of voxels for each region found

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 2 Mär. 2020
Gina, to find the blob count and volume for all the regions for a particular label number, you can do (untested)
% Get a mask of only this number and label each blobs that has this number.
[thisLabeledImage, numBlobs] = bwlabeln(mask3d == desiredNumber);
% numBlobs is the number of distinct, separate blobs with this label.
% Now find the volume of all those blobs.
props = regionprops3(thisLabeledImage, 'Volume');
allVolumes = [props.Volume]; % List of volumes for all blobs with this particular number only.
Repeat for whatever desiredNumber you want to check. For example
desiredNumber = 4;
Or you can put into a loop over all the numbers you know exist.
mask3d is the "mask" array you mentioned with the labeled regions.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by