Permuting Axes using c3d

64 views
Skip to first unread message

mfk16

unread,
Jun 16, 2022, 4:10:16 PM6/16/22
to itksnap-users
Hi,

I'm looking to permute axes of a segmentation nii file from [512 512 74] to [74 512 512] as my source images are [512 512 74].

However, I don't see this option in c3d....is there a combination of other commands I can use to achieve the same result?

Thanks!

-Matt

Rolf Heckemann

unread,
Jun 21, 2022, 6:08:07 PM6/21/22
to itksnap-users
There be dragons. Orientation in NIfTI files is a complex matter. Not sure how you extracted these triplets, but it is quite possible that they refer to the data ordering in the file, and that other header elements ensure that your file pair is spatially matched despite the discrepancy. When you open the pair in ITK Snap, do they appear aligned? If so, manipulating the orientation will probably do more harm than good. If for some reason you have to force identical spatial interpretations onto the two files, the safest way might be to correct both with fslreorient2std from the FSL suite.


Hope this helps

Rolf

mfk16

unread,
Jun 22, 2022, 10:54:20 AM6/22/22
to itksnap-users
​Hi Rolf,

Thanks for the reply. ​I extracted the triplets via niftiread in MATLAB. I manually reordered the matrix [512 512 74] --> [74 512 512] and I was able to successfully display the reordered segmentation in itk-snap, but alas, my reordered segmentation did not pair up with the main image as I did not alter the orientation. 

I also found dcm2nii (https://github.com/rordenlab/dcm2niix/releases) that creates nii files with the [74 512 512] ordering, but the orientation is still off.

I agree that it's not a trivial issue to resolve, and I don't have a linux server available or IT permission to install a virtual machine for the FSL software at this time, so I'm looking for something that works at the windows command line or a stand alone executable.

Any alternative suggestions would be helpful.

Thank you,

Matt




Rolf Heckemann

unread,
Jun 22, 2022, 12:49:39 PM6/22/22
to itksnap-users
It's too bad that you have to do this work with one hand tied behind your back.

Like you, I don't think c3d has any commands to manipulate the orientation at the depth that you need.

The general advice is to go back as far as possible in the processing chain and to use software that complies with the NIfTI and DICOM standards (or at least misinterprets them consistently). dcm2niix is highly trustworthy in my experience, whereas using MATLAB or R routines that let you access the raw matrix data while bypassing the header information can easily lead to the mess you describe.

I can't grasp the story of your data from your two posts, but it seems that you have DICOM data from some scanner and a set of segmentation labels in NIfTI format. If the latter does not match the former, it means that whoever generated the label set interpreted the orientation in the DICOM data differently from you. To reverse-engineer that interpretation, you need to examine the headers carefully. I'm sure there are MATLAB tools for this, but I don't know what they are.

No guarantees, but it might help if you describe the processing path that your data went through from the beginning.

Rolf

Paul Yushkevich

unread,
Jun 25, 2022, 5:04:26 AM6/25/22
to itksna...@googlegroups.com
There is a command -swapdim in c3d that achieves this task, swapping dimensions but keeping the world coordinates of voxels intact.

Paul

--
You received this message because you are subscribed to the Google Groups "itksnap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to itksnap-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/itksnap-users/53de9139-a295-4bda-b389-ee201f063782n%40googlegroups.com.

mfk16

unread,
Jun 28, 2022, 10:48:50 AM6/28/22
to itksnap-users
Thanks Paul, the -swapdim flag was able to solve the problem. Fortunately ITK-snap displays the orientation in the Image Layer Inspector to confirm all of the swapping that I need to do.

-Matt

Rolf Heckemann

unread,
Jun 29, 2022, 7:48:55 AM6/29/22
to itksnap-users
Well done Matt! Sorry, Paul, for underestimating c3d.

Rolf

Fumin Guo

unread,
Nov 14, 2024, 8:46:51 PM11/14/24
to itksnap-users
Hi Paul,

Thanks for the reply.

I wonder if the -swapdim works for 4D images. I have an image size HxWxCxZ, and I would like to display it with itksnap with orientations  HxWxZxC (permute the last two dimensions).

Thanks,
Fumin 

Reply all
Reply to author
Forward
0 new messages