I have a mask with regions labeled with 1, 2 and 3. I have a 3D volume that I would like to calculate the mean of the pixels correspond to those regions. I want to calculate the mean of the regions with number 1, number 2 and number 3 separately. Is the following correct? m = mean(volume(mask==1)); m = mean(volume(mask==2)); m = mean(volume(mask==3));
Kshitij Singh answered .
2025-11-20
Yes, your approach is correct for calculating the mean of the regions labeled with 1, 2, and 3 separately in your 3D volume. Each line of code correctly identifies the voxels corresponding to the specified label in your mask and calculates the mean of those voxels in the volume.
Here's a summary and the code:
For region labeled with 1:
m1 = mean(volume(mask == 1));
For region labeled with 2:
m2 = mean(volume(mask == 2));
For region labeled with 3:
m3 = mean(volume(mask == 3));
This will give you the mean values of the pixels in the 3D volume corresponding to regions labeled 1, 2, and 3, respectively. Ensure that volume and mask are appropriately defined and that they are the same size.