Problem in image and its mask superposition

Dear SITK team,

We are trying to generate image and its mask from RTStruct file.

The dimension of the image is: 256 256 216
The dimension of the mask is: 256 256 216

While visualizing we observed that mask is not superposed on the image as shown in the attached image and code block.


When we transposed the image, it perfectly superposed on the mask as shown in the attached figure and code block.


When both image and mask dimensions are same why we need to take transpose?

Your help will be highly appreciated.

Thanks.

Sincerely,
Sunita

They probably have different metadata. What is the output of t1c_img.affine and t1c_msk.affine?

Hello @Sunita_Patel,

Are you mixing and matching SimpleITK and nibabel? Possibly that is the difference:

import SimpleITK as sitk
import nibabel as nb

# create image with sizes x=10, y=20, z=30 and write to disk
file_name = "1.nii"
image = sitk.Image([10,20,30], sitk.sitkUInt16)
sitk.WriteImage(image, file_name)

# get numpy arrays using nibabel's load and SimpleITK read+get_array
nb_arr = nb.load(file_name)
sitk_arr = sitk.GetArrayFromImage(sitk.ReadImage(file_name))

print(nb_arr.shape)
print(sitk_arr.shape)

Dear Zivy,

We are not mixing SimpleITK and Nibabel. We are only using SimpleITK. The image detail and mask detail are shown here. When we visualize the image and the mask without transpose, there is a mismatch. After doing transposition it shows correct superposition. It means in each slice x and y dimension should be swapped to get the right image with the right mask.




That’s what we did after so many trials and errors and now it is working fine. Basically, we included a for loop to iterate over each slice and within which we swapped the x and y dimension. Now without transpose it is showing correct superposition. Overall dimension has not changed that is 256, 256, 216.

Thank you.

Sincerely,
Sunita