[Insight-users] fail to change the Direction Cosine Matrix to identity

Luis Ibanez luis.ibanez at kitware.com
Mon Feb 15 18:08:32 EST 2010


Hi Xi,


         That explains everything    :-)


Analyze can only manage some orientations
(only three actually), and the Identity matrix is
not one of them, so it seems to be defaulting
to one of the directions that it actually supports.


Please don't use the Analyze fileformat.


You may want to use

              * MetaImage  (extension ".mha") or
              * Nifti (extension   ".nii" )


    Regards


             Luis



---------------------------------------------------------------------
2010/2/15 Xi LIANG <liangxi1986317 at hotmail.com>:
> Hi Luis,
>
>> What file format are you using for storing the images ?
>>
>> That is, what is the extension of the filename that you
>> are passing as the second command line argument to
>> your program ?
> I am using .hdr
> Regards,
> --------------------------------
> Xi Liang
>
> 梁茜
> --------------------------------
>
>
>
>
>> Date: Mon, 15 Feb 2010 18:04:09 -0500
>> Subject: Re: [Insight-users] fail to change the Direction Cosine Matrix to
>> identity
>> From: luis.ibanez at kitware.com
>> To: liangxi1986317 at hotmail.com
>> CC: insight-users at itk.org; m.staring at lumc.nl; njuptlw at 163.com
>>
>> Hi Xi,
>>
>>
>> The problem seems to be in the writer / reader that
>> is used for the writing and reading the changed image.
>>
>>
>> What file format are you using for storing the images ?
>>
>> That is, what is the extension of the filename that you
>> are passing as the second command line argument to
>> your program ?
>>
>>
>> Please let us know,
>>
>>
>> Thanks
>>
>>
>> Luis
>>
>>
>>
>> ------------------------------------------------------------------------------------------
>> 2010/2/15 Xi LIANG <liangxi1986317 at hotmail.com>:
>> > Hi all,
>> > I wrote 2 pieces of code to change the direction to identity. The idea
>> > of
>> > the program is to read in the input image and only change its direction,
>> > and
>> > then write the resulting image into output. Those code is attached with
>> > the
>> > email.
>> >
>> > However, both of them cannot change the direction to identity and
>> > generate
>> > the same unrelated directions. One method is
>> > though itkChangeInformationImageFilter suggested by Luis, and the other
>> > is
>> > using ResampleImageFilter suggested by another ITK user.
>> >
>> > By using those two methods, I got the same wired result. The direction
>> > of
>> > the output image is different from input image direction and is not
>> > identity
>> > direction neither. I am not sure why the direction in the filter is
>> > identity, but it generates a totally unrelated direction in writer. The
>> > followings are direction shows the directions in Input/filter/output
>> > images.
>> >
>> > Input image DCM:
>> > 1 0 0
>> > 0 -1 0
>> > 0 0 1
>> > DCM got from the filter
>> > 1 0 0
>> > 0 1 0
>> > 0 0 1
>> > Output image DCM:
>> > 1 0 0
>> > 0 0 -1
>> > 0 1 0
>> > --------------------------------
>> > Xi Liang
>> >
>> > 梁茜
>> > --------------------------------
>> >
>> >
>> >
>> >
>> >> Date: Fri, 12 Feb 2010 09:03:51 -0500
>> >> Subject: Re: [Insight-users] fail to change the Direction Cosine Matrix
>> >> to
>> >> identity
>> >> From: luis.ibanez at kitware.com
>> >> To: liangxi1986317 at hotmail.com
>> >> CC: insight-users at itk.org
>> >>
>> >> Hi Xi,
>> >>
>> >> You should not attempt to modify directly the information of an
>> >> image that is generated as the output of a filter (or a reader).
>> >>
>> >>
>> >> What you should do, is to use the
>> >>
>> >> itkChangeInformationImageFilter
>> >>
>> >>
>> >> Connect this filter to the output of the reader and make sure
>> >> that you call ChangeDirectionOn() in the filter before you
>> >> call Update()
>> >>
>> >>
>> >> BTW: changing the direction of a medical image can
>> >> be a dangerous thing to do. You should make sure
>> >> that you have a good justification for replacing the
>> >> direction of the original image.
>> >>
>> >>
>> >>
>> >> Regards,
>> >>
>> >>
>> >>
>> >> Luis
>> >>
>> >>
>> >> -------------------------------------------------------------------
>> >> 2010/2/12 Xi LIANG <liangxi1986317 at hotmail.com>:
>> >> > Dear all,
>> >> > I am trying to change an image direction cosine matrix to identity by
>> >> > using
>> >> > the following code, but it fails. I read in an input image and set
>> >> > its
>> >> > DCM
>> >> > to identity, then I write it to a new image and then print out its
>> >> > DCM
>> >> > again. However, the DCM in the new image is not identity matrix. I am
>> >> > not
>> >> > sure what was wrong in my code, and the following are the major part
>> >> > related
>> >> > to this.
>> >> >
>> >> > // I first get the DCM from the fixedImage
>> >> > FixedImageType::DirectionType directionCosines =
>> >> > fixedImage->GetDirection();
>> >> >
>> >> > std::cout << "Input DCM is " << std::endl;
>> >> > std::cout << directionCosines << std::endl;
>> >> > //Terminal shows:
>> >> > //1 0 0
>> >> > //0 -1 0
>> >> > //0 0 1
>> >> > directionCosines[0][0] = 1;
>> >> > directionCosines[0][1] = 0;
>> >> > directionCosines[0][2] = 0;
>> >> > directionCosines[1][0] = 0;
>> >> > directionCosines[1][1] = 1;
>> >> > directionCosines[1][2] = 0;
>> >> > directionCosines[2][0] = 0;
>> >> > directionCosines[2][1] = 0;
>> >> > directionCosines[2][2] = 1;
>> >> > std::cout << directionCosines << std::endl;
>> >> > //Terminal shows:
>> >> > //1 0 0
>> >> > //0 1 0
>> >> > //0 0 1
>> >> >
>> >> > //Then I reset the direction to identity
>> >> > fixedImage Reader->GetOutput()->SetDirection(directionCosines);
>> >> >
>> >> > std::cout << "New DCM is " << std::endl;
>> >> > std::cout << fixedImageReader->GetOutput()->GetDirection() <<
>> >> > std::endl;
>> >> > //Terminal shows:
>> >> > //1 0 0
>> >> > //0 1 0
>> >> > //0 0 1
>> >> >
>> >> >
>> >> > //Then I write the new image with the identity DCM
>> >> > caster->SetInput( fixedImageReader->GetOutput() );
>> >> > &nbsp ; writer->SetInput( caster->GetOutput() );
>> >> >
>> >> > //Then I read in the new image again to print its DCM
>> >> > outputImageReader->SetFileName( argv[2] );
>> >> > OutputImageType::ConstPointer outputImage =
>> >> > outputImageReader->GetOutput();
>> >> > outputImageReader->Update();
>> >> > OutputImageType::DirectionType directionCosinesOutput =
>> >> > outputImage->GetDirection();
>> >> > std::cout << "Output DCM is " << std::endl;
>> >> > std::cout << directionCosinesOutput << std::endl;
>> >> > //Terminal shows:
>> >> > //1 0 0
>> >> > // 0 -1 0
>> >> > //0 0 1
>> >> > --------------------------------
>> >> > Xi Liang
>> >> >
>> >> > 梁茜
>> >> > --------------------------------
>> >> >
>> >> >
>> >> >
>> >> > ________________________________
>> >> > Hotmail: Trusted email with Microsoft's powerful SPAM protection.
>> >> > Sign
>> >> > up
>> >> > now.
>> >> > _____________________________________
>> >> > Powered by www.kitware.com
>> >> >
>> >> > Visit other Kitware open-source projects at
>> >> > http://www.kitware.com/opensource/opensource.html
>> >> >
>> >> > Kitware offers ITK Training Courses, for more information visit:
>> >> > http://www.kitware.com/products/protraining.html
>> >> >
>> >> > Please keep messages on-topic and check the ITK FAQ at:
>> >> > http://www.itk.org/Wiki/ITK_FAQ
>> >> >
>> >> > Follow this link to subscribe/unsubscribe:
>> >> > http://www.itk.org/mailman/listinfo/insight-users
>> >> >
>> >> >
>> >
>> > ________________________________
>> > Hotmail: Powerful Free email with security by Microsoft. Get it now.
>
> ________________________________
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up
> now.


More information about the Insight-users mailing list