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

Luis Ibanez luis.ibanez at kitware.com
Fri Feb 12 09:03:51 EST 2010


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
>
>


More information about the Insight-users mailing list