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

Xi LIANG liangxi1986317 at hotmail.com
Mon Feb 15 03:57:35 EST 2010


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 00 0 1
DCM got from the filter1 0 00 1 00 0 1
Output image DCM:1 0 00 0 -10 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.
https://signup.live.com/signup.aspx?id=60969
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100215/1a7184f5/attachment-0001.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: setIdentityDirection3D.1.1.cxx
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100215/1a7184f5/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: setIdentityDirection3D.1.2.cxx
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100215/1a7184f5/attachment-0001.asc>


More information about the Insight-users mailing list