Resample to same Spacing and Size and Align to same Origin

Hello @zivy,

Thank you for helping me with that clarification. I understand there are subtle differences in the way NIFTI and DICOM data are stored. I was under the impression I would require resampling the segmentation mask to the image grid in order to match (as they are spatially not aligned).

I tried what you suggested and unfortunately the labels still remain misaligned. I wrote the result into a NIFTI file using SITK and visualized it on the ITK tool. I am attaching screenshots of the ITK Image Summary for :

  1. Original DICOM Series
    dicom_IS

  2. Original DICOM Segmentation Mask (Works correctly)
    dicomseg_IS

3)NIFTI Converted Image
image_IS

  1. NIFTI Mask (after modifying with PermuteAxes and setting direction and origin)
    seg_IS_mod

Here is my code that I tried : (seg : Original Segmentation on DICOM, img : NIFTI converted image from DICOM)

seg_modified = sitk.PermuteAxes(seg,[2,1,0])
seg_modified.SetDirection(img.GetDirection())
seg_modified.SetOrigin(img.GetOrigin())

result = seg_modified

Grateful for any further advice on this matter - the mask remains not aligned, and I am unable to figure out why - even though my origin,direction and spacing are appropriate.
Thanks a lot.

Hello @Samarth,

Can you possibly share the mask and image? Otherwise we are guessing, based on experience, and it is much harder to arrive at the solution.

1 Like

Hello @zivy ,
I understand.
I can share a zoomed in snippet highlighting the region of interest, please find the same attached here (permuted axis/matched origin/matched direction). Please note the segments were created using the ITK platform, and the lesion is highlighted.

Snippet 1 - Aligned Segmentation on DICOM

Snippet 2 - Misaligned Segmentation on NIFTI

Thanks for your continued help on this matter - I also wanted to point out , I tried CopyInformation() to ensure metadata matches, but unfortunately that is not of use.

Hello @Samarth,

See if flipping the y axis does it, I believe that is the difference between the DICOM and nii coordinate systems:

seg_modified = seg[:,::-1,:]
1 Like

Thanks @zivy for your response.
I wanted to ensure I understand this correctly : permute axes changes the image size from 512512240 to 240512512. After permuting axes, then I go ahead and flip the same? I believe I would have to flip both x and y, as only Z axis direction is maintained. I shall try and ensure I report the results here.

I found this figure from dcm2niix (NITRC: dcm2nii: MainPage) , the tool I utilized for converting DICOM to NIFTI :

Screenshot 2023-08-25 at 3.16.28 PM

Hello @zivy,

I wanted to update on my problem status - at this point, unfortunately, a simple permute and flipping the axes have not been useful for me. The annotations still remain misaligned, albeit slightly. If there is anything else that may be suggested, I would be grateful - for this seemingly straightforward but currently intractable problem.

Hello @Samarth,

Unfortunately, at this point the only way we can help is if you provide a dataset exhibiting the issue. This can be an artificial dataset, or you can use publicly available DICOM data to recreate the problem (see TCIA for publicly available data).

1 Like

Thank you @zivy for guiding me in that direction. I will be able to use publicly available data to recreate the problem and hope to share it here as soon as I am done. I will be trying to map a single point in space in the DICOM to NIFTY transform.