[MINC-users] Issue with itk_convert_xfm

Robert D. Vincent robert.d.vincent at mcgill.ca
Mon Jan 18 12:13:35 EST 2016


Hi all,

My apologies for the lengthy message. There may well be issues with the
mnc2nii/nii2mnc pair, but part of the problem may be that itk_convert
doesn't obey one of MINC's conventions, which is that direction_cosines are
not supposed to encode axis flipping information. In some cases,
itk_convert can create a MINC file with direction cosines of [-1, 0, 0].
These might not be handled correctly in some MINC tools. Here's what I
mean, illustrated using one of the standard NIfTI example files:

% wget http://nifti.nimh.nih.gov/nifti-1/data/avg152T1_RL_nifti.nii.gz
% itk_convert avg152T1_RL_nifti.nii.gz RL.mnc
% mincinfo RL.mnc
file: RL.mnc
image: unsigned byte 0 to 255
image dimensions: xspace yspace zspace
    dimension name         length         step        start
    --------------         ------         ----        -----
    xspace                     91            2          -90
    yspace                    109            2         -126
    zspace                     91            2          -72

% mincinfo -attvalue xspace:direction_cosines RL.mnc
-1 0 0

That -1 apparently means that the X axis is flipped, but MINC assumes that
any flipping is encoded in the step size. I'm sure itk_convert is
internally consistent, so of course it works just fine in many cases.

There are also inconsistencies between the "NIfTI-world" coordinate system
in Andrew's example and the MINC coordinate system. Again using the NIfTI
example file, I tried the following:

% make_transform 10 10 10 trans.xfm
% itk_convert_xfm trans.xfm trans.mat
% antsApplyTransforms --input avg152T1_RL_nifti.nii --transform trans.mat
--output out.nii --reference-image avg152T1_RL_nifti.nii
% fslview avg152T1_RL_nifti.nii out.nii

The transformation moves the image in the +X and +Y direction, but in the
-Z direction (see the enclosed screen capture - the original image is blue,
the transformed image is red). Given the original transform, I would have
expected that the signs of all three components of the transform would be
negative. This example uses no MINC tools other than make_transform, so I
suspect that there is some inconsistency between MINC's coordinate system
and the coordinate system assumed in itk_convert_xfm or antsApplyTransforms.

By way of comparison, performing the same transform using mincresample
(using -invert_transformation) moves the image -10 in X, -10 in Y, and -10
in Z  (at least according to the MINC conventions for these directions:
MINC's convention is for X to increase from patient left to patient right,
Y from patient posterior to patient anterior, and Z from patient inferior
to patient superior).

    -bert

On Mon, Jan 18, 2016 at 4:05 AM, Simon Eskildsen <eskild at gmail.com> wrote:

> For what it's worth: I have had similar problems with converting back and
> forth between nifti and minc. I often find myself tailoring the conversion
> (flipping, changing dim order / step sign) whenever I need to go back and
> forth. itk_convert and nii2mnc usually give different results. Quite a
> nuisance.
>
> On Fri, Jan 15, 2016 at 2:00 PM, Robert D. Vincent <
> robert.d.vincent at mcgill.ca> wrote:
>
> > I'll check for issues with the minc to nifti converters...
> >
> >
> > On Thu, Jan 14, 2016 at 5:46 PM, Vladimir S. FONOV <
> > vladimir.fonov at gmail.com
> > > wrote:
> >
> > >
> > > This code works properly:
> > >
> > >
> > >
> > > make_phantom phantom.mnc
> > > param2xfm -translation 10 10 10 trans.xfm
> > >
> > > # Apply the xfm
> > > mincresample -use_input_sampling -invert_transform -transform trans.xfm
> > > phantom.mnc out.mnc -clob
> > >
> > > # Do the same transform in nifti space
> > > itk_convert_xfm trans.xfm trans.mat --clob
> > >
> > > itk_convert phantom.mnc phantom.nii --clob
> > > antsApplyTransforms --input phantom.nii \
> > > --transform trans.mat \
> > > --output out.nii \
> > > --reference-image phantom.nii
> > >
> > > itk_convert out.nii thru_nifti.mnc --clob
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > On 16-01-14 05:04 PM, Andrew Wood wrote:
> > >
> > >> Hi Vlad,
> > >>
> > >> I think I didn't explain my issue correctly. Let me
> > >> add -invert_transformation to my mincresample invocation and try
> again.
> > >>
> > >>
> > >> Here are the commands that I think illustrates a problem:
> > >> $ make_phantom phantom.mnc
> > >> $ param2xfm -translation 10 10 10 trans.xfm
> > >>
> > >> # Apply the xfm
> > >> $ mincresample -use_input_sampling -*invert_transformation* -transform
> > >> trans.xfm phantom.mnc out.mnc
> > >>
> > >> # Do the same transform in nifti space
> > >> $ itk_convert_xfm trans.xfm trans.mat
> > >> $ mnc2nii phantom.mnc phantom.nii
> > >> $ antsApplyTransforms --input phantom.nii \
> > >> --transform trans.mat \
> > >> --output out.nii \
> > >> --reference-image phantom.nii
> > >>
> > >> # Open result in a minc+nifti-friendly viewer, or convert back to minc
> > >> $ nii2mnc out.nii thru_nifti.mnc
> > >> $ register out.mnc thru_nifti.mnc
> > >>
> > >>
> > >>
> > >> As far as I can tell, out.mnc and thru_nifti.mnc should be identical,
> > but
> > >> they clearly are not.
> > >>
> > >> Best,
> > >> Andrew
> > >>
> > >> On Thu, Jan 14, 2016 at 4:39 PM, Vladimir S. FONOV <
> > >> vladimir.fonov at gmail.com
> > >>
> > >>> wrote:
> > >>>
> > >>
> > >> antsApplyTransforms is basically equivalent to mincresample
> > >>> -invert_transformation
> > >>>
> > >>> On Thu, Jan 14, 2016 at 3:18 PM, Andrew Wood <andrew at biospective.com
> >
> > >>> wrote:
> > >>>
> > >>> Hi all,
> > >>>>
> > >>>> I came across a set of transforms generated by ANTs which I've been
> > >>>>
> > >>> trying
> > >>>
> > >>>> to convert and use on minc volumes. There seems to be a bug in one
> or
> > >>>>
> > >>> more
> > >>>
> > >>>> of the tools I'm using, where applying the transforms to nifti
> volumes
> > >>>>
> > >>> does
> > >>>
> > >>>> not give the same result as applying them to minc volumes.
> > >>>>
> > >>>> Likely culprits:
> > >>>> - itk_convet_xfm
> > >>>> - mnc2nii or nii2mnc
> > >>>> - antsApplyTransforms
> > >>>> - mincresample
> > >>>>
> > >>>> Somewhere along the way, several components of the transforms get
> > >>>>
> > >>> inverted.
> > >>>
> > >>>> Here is an example:
> > >>>>
> > >>>> $ make_phantom phantom.mnc
> > >>>> $ param2xfm -translation 10 10 10 trans.xfm
> > >>>>
> > >>>> # Apply the xfm
> > >>>> $ mincresample -use_input_sampling -transform trans.xfm phantom.mnc
> > >>>>
> > >>> out.mnc
> > >>>
> > >>>>
> > >>>> # Do the same transform in nifti space
> > >>>> $ itk_convert_xfm trans.xfm trans.mat
> > >>>> $ mnc2nii phantom.mnc phantom.nii
> > >>>> $ antsApplyTransforms --input phantom.nii \
> > >>>> --transform trans.mat \
> > >>>> --output out.nii \
> > >>>> --reference-image phantom.nii
> > >>>>
> > >>>> # Open result in a minc+nifti-friendly viewer, or convert back to
> minc
> > >>>> $ nii2mnc out.nii thru_nifti.mnc
> > >>>> $ register out.mnc thru_nifti.mnc
> > >>>>
> > >>>> The result of this for me is that the z component of the transform
> was
> > >>>> inverted, but the x and y components are OK.
> > >>>>
> > >>>>  From experimenting with various simple transforms, it seems that
> the
> > >>>> following components are inverted:
> > >>>>     - z translation
> > >>>>     - z rotation
> > >>>>     - x,y,z scale
> > >>>>     - x shear
> > >>>>
> > >>>> Has anybody else noticed or dealt with this before?
> > >>>>
> > >>>> Thanks,
> > >>>> Andrew
> > >>>> _______________________________________________
> > >>>> MINC-users at bic.mni.mcgill.ca
> > >>>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
> > >>>>
> > >>>>
> > >>>
> > >>>
> > >>> --
> > >>> Best regards,
> > >>>
> > >>>   Vladimir S. Fonov ~ vladimir <dot> fonov <at> gmail <dot> com
> > >>> _______________________________________________
> > >>> MINC-users at bic.mni.mcgill.ca
> > >>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
> > >>>
> > >>> _______________________________________________
> > >> MINC-users at bic.mni.mcgill.ca
> > >> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
> > >>
> > >>
> > >
> > > --
> > > Best regards,
> > >
> > >  Vladimir S. FONOV ~ vladimir.fonov <at> gmail.com
> > > _______________________________________________
> > > MINC-users at bic.mni.mcgill.ca
> > > http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
> > >
> > _______________________________________________
> > MINC-users at bic.mni.mcgill.ca
> > http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
> >
> _______________________________________________
> MINC-users at bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>


More information about the MINC-users mailing list