# How to correct for mask volume in ITK?

**URL:** https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252
**Category:** Beginner Questions
**Created:** [July 2, 2020, 11:26am UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252 "2020-07-02T11:26:52Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![3omarkamal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/3/c77e96/32.png) [@3omarkamal](https://discourse.itk.org/u/3omarkamal)
#### Post date: [July 2, 2020, 11:26am UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/1 "2020-07-02T11:26:52Z")

</div>

I use:

shape\_stats = sitk.LabelShapeStatisticsImageFilter()  
shape\_stats.Execute(ROI)  
vol\_roi = shape\_stats.GetPhysicalSize(1)

to get a Region of interest volume. However, I am not sure of the unit. I looked at the same mask in ITK Snap and it is in mm3. But I am not sure if it is accurate as it seems the physical size is the number of voxels within the mask.

Should I multiply it with the voxel size to get accurate volume measurement?

Thanks

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 2, 2020, 1:30pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/3 "2020-07-02T13:30:40Z")

</div>

Hello @3omarkamal,

The `GetPhysicalSize` does return the physical object size, no need to multiply by voxel size, that is done by the filter. If your ROI spacing is [1,1] in 2D or [1,1,1] in 3D then the number of voxels coincides with the size, otherwise it will be the physical size.

Short example:

```auto
import SimpleITK as sitk

ROI = sitk.Image([2,2], sitk.sitkUInt8)
ROI.SetSpacing([0.5,0.5])

ROI[0,0] = 1
ROI[0,1] = 1

shape_stats = sitk.LabelShapeStatisticsImageFilter()
shape_stats.Execute(ROI)
vol_roi = shape_stats.GetPhysicalSize(1)
print(vol_roi)

```

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [July 2, 2020, 1:38pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/4 "2020-07-02T13:38:14Z")

</div>

Oh sorry. I was wrong.

---

<div class="post-metadata">

### Author: ![3omarkamal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/3/c77e96/32.png) [@3omarkamal](https://discourse.itk.org/u/3omarkamal)
#### Post date: [July 3, 2020, 11:39am UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/6 "2020-07-03T11:39:56Z")

</div>

Sorry, I was wrong too. Apparently the problem is in my Nifti files. I passed the NumPy array into a Nifti file but I think I need to pass the voxel size too.

---

<div class="post-metadata">

### Author: ![3omarkamal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/3/c77e96/32.png) [@3omarkamal](https://discourse.itk.org/u/3omarkamal)
#### Post date: [July 3, 2020, 12:18pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/7 "2020-07-03T12:18:48Z")

</div>

@zivy

Final thing, I loaded my original dicom files, now the spacing is 1.25 X 1.25 X 1 mm (while the slice spacing in the DICOM header is 3). So while the area should be accurate, the volume calculation assumes that the mask is just multiple 2D layers rather than a true 3D volume. Any thoughts?

Thanks

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 3, 2020, 3:06pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/8 "2020-07-03T15:06:22Z")

</div>

Hello @3omarkamal,

At what DICOM tag are you looking to obtain spacing? If slice thickness (0018|0050) then that is not the spacing between slices it is the thickness of a single slice and that slice sits in the middle of the region. The spacing in ITK/SimpleITK is based on the Image Position (Patient) and Image Orientation (Patient) tags from multiple images and we assume uniform spacing.

---

<div class="post-metadata">

### Author: ![3omarkamal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/3/c77e96/32.png) [@3omarkamal](https://discourse.itk.org/u/3omarkamal)
#### Post date: [July 6, 2020, 11:28am UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/9 "2020-07-06T11:28:26Z")

</div>

Sorry, I meant the slice thickness, It is 3 mm in the DICOM header, but 1 mm in the ITK snap layer info

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 6, 2020, 12:44pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/10 "2020-07-06T12:44:37Z")

</div>

Hello @3omarkamal,

In ITK-SNAP are you looking under “image information” info tab, “Image Metadata”? If yes, then what you are seeing is the spacing, which as I said is different from slice thickness. If you move to the “Image Metadata” tab in the same dialog you can see the “Slice Thickness” value which should match what you expect.

Again, slice spacing is used to compute the volume, not slice thickness. Hopefully this clarifies things.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [July 6, 2020, 5:04pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/11 "2020-07-06T17:04:03Z")

</div>

Here is a [picture explanation](https://www.materialise.com/en/faq/what-difference-between-slice-thickness-and-slice-increment) of what @zivy is saying. In there they call spacing under different name: increment. In case the link rots, here is the image:

 ![slice_spacing_thickness](https://discourse.itk.org/uploads/default/original/2X/7/7fc15d0603a889a886d99c28cb9bed48dd3b13a0.jpeg)

---

<div class="post-metadata">

### Author: ![3omarkamal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/3/c77e96/32.png) [@3omarkamal](https://discourse.itk.org/u/3omarkamal)
#### Post date: [July 9, 2020, 10:56am UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/12 "2020-07-09T10:56:52Z")

</div>

Thanks a lot

---

<div class="post-metadata">

### Author: ![jizhang02](https://discourse.itk.org/user_avatar/discourse.itk.org/jizhang02/32/3152_2.png) [@jizhang02](https://discourse.itk.org/u/jizhang02)
#### Post date: [March 31, 2023, 2:00pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/13 "2023-03-31T14:00:13Z")

</div>

Hello,  
Is there a formula for computing the spacing in ITK-SNAP?  
Here is info of one patient:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/f/fe36cf5195f1cc4321cbbf8d4a753ed90a3872ab.png)  
 ![image](https://discourse.itk.org/uploads/default/original/2X/9/9c284ca75ed42b0dacf66cf854a2712eb664d49e.png)

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [March 31, 2023, 2:46pm UTC](https://discourse.itk.org/t/how-to-correct-for-mask-volume-in-itk/3252/14 "2023-03-31T14:46:46Z")

</div>

Hello @jizhang02,

Please see [this discussion on image spacing](https://discourse.itk.org/t/z-spacing-in-image-series-reader/2167/4). What you highlighted, slice thickness, is a different quantity and is obtained from the DICOM tag (0018|0050).
