MATLAB Answers


How to count the number of voxels of another color

Asked by Matthew Lee on 11 Sep 2019
Latest activity Commented on by Rik
on 12 Sep 2019
I was wondering how to count the number of voxels of one color in a three dimensional space
Thank you!


By "color" do you actually mean gray level? Because a color information in a 3-D space is actually 4-D. What is the source of your image, and what does it represent? Like color movie frames or something? Or a confocal microscope image?
I was segmenting a section out of a three dimensional shape, but I wanted to find volume of the segmented portion, so I thought that I could approach it by highlighting the segmentation using a different color and counting the number of voxels of that certain color and then arrange a conversion into cm^3 to find a measure of volume. Is there a way to do this, or is there a better way of going about this volume calculation?
You can use my answer to achieve this. When you have a logical array you can use sum to count the number of voxels.

Sign in to comment.

1 Answer

Answer by Rik
on 11 Sep 2019
 Accepted Answer

Similar to how you would do that for 2D:
IM=randi(255,[512 512 400]);
%if your release doesn't have the 'all' option:


Sign in to comment.