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?
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.
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.
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?
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.
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.
Here is a picture explanation of what @zivy is saying. In there they call spacing under different name: increment. In case the link rots, here is the image:
Please see this discussion on image spacing. What you highlighted, slice thickness, is a different quantity and is obtained from the DICOM tag (0018|0050).