<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Dear Luis,<div><br></div><div>Thank you very much for this. Finally I realize the format is a big issue for image processing, and this has been confusing me a lot. Could you please suggest a good reference for understanding and analysis on format and head file information, which could show the important parameters that would effect the result significant and how. &nbsp;</div><div><br></div><div>I will post some later if I manage to find any good reference.</div><div><br></div><div>Thank you and regards,<br><br>--------------------------------<br>Xi Liang<br><br>ÁºÜç<br>--------------------------------<br><br><br><br><br>&gt; Date: Mon, 15 Feb 2010 18:08:32 -0500<br>&gt; Subject: Re: [Insight-users] fail to change the Direction Cosine Matrix to         identity<br>&gt; From: luis.ibanez@kitware.com<br>&gt; To: liangxi1986317@hotmail.com<br>&gt; CC: insight-users@itk.org; m.staring@lumc.nl; njuptlw@163.com<br>&gt; <br>&gt; Hi Xi,<br>&gt; <br>&gt; <br>&gt;          That explains everything    :-)<br>&gt; <br>&gt; <br>&gt; Analyze can only manage some orientations<br>&gt; (only three actually), and the Identity matrix is<br>&gt; not one of them, so it seems to be defaulting<br>&gt; to one of the directions that it actually supports.<br>&gt; <br>&gt; <br>&gt; Please don't use the Analyze fileformat.<br>&gt; <br>&gt; <br>&gt; You may want to use<br>&gt; <br>&gt;               * MetaImage  (extension ".mha") or<br>&gt;               * Nifti (extension   ".nii" )<br>&gt; <br>&gt; <br>&gt;     Regards<br>&gt; <br>&gt; <br>&gt;              Luis<br>&gt; <br>&gt; <br>&gt; <br>&gt; ---------------------------------------------------------------------<br>&gt; 2010/2/15 Xi LIANG &lt;liangxi1986317@hotmail.com&gt;:<br>&gt; &gt; Hi Luis,<br>&gt; &gt;<br>&gt; &gt;&gt; What file format are you using for storing the images ?<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; That is, what is the extension of the filename that you<br>&gt; &gt;&gt; are passing as the second command line argument to<br>&gt; &gt;&gt; your program ?<br>&gt; &gt; I am using .hdr<br>&gt; &gt; Regards,<br>&gt; &gt; --------------------------------<br>&gt; &gt; Xi Liang<br>&gt; &gt;<br>&gt; &gt; ÁºÜç<br>&gt; &gt; --------------------------------<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;&gt; Date: Mon, 15 Feb 2010 18:04:09 -0500<br>&gt; &gt;&gt; Subject: Re: [Insight-users] fail to change the Direction Cosine Matrix to<br>&gt; &gt;&gt; identity<br>&gt; &gt;&gt; From: luis.ibanez@kitware.com<br>&gt; &gt;&gt; To: liangxi1986317@hotmail.com<br>&gt; &gt;&gt; CC: insight-users@itk.org; m.staring@lumc.nl; njuptlw@163.com<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Hi Xi,<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; The problem seems to be in the writer / reader that<br>&gt; &gt;&gt; is used for the writing and reading the changed image.<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; What file format are you using for storing the images ?<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; That is, what is the extension of the filename that you<br>&gt; &gt;&gt; are passing as the second command line argument to<br>&gt; &gt;&gt; your program ?<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Please let us know,<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Thanks<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Luis<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; ------------------------------------------------------------------------------------------<br>&gt; &gt;&gt; 2010/2/15 Xi LIANG &lt;liangxi1986317@hotmail.com&gt;:<br>&gt; &gt;&gt; &gt; Hi all,<br>&gt; &gt;&gt; &gt; I wrote 2 pieces of code to change the direction to identity. The idea<br>&gt; &gt;&gt; &gt; of<br>&gt; &gt;&gt; &gt; the program is to read in the input image and only change its direction,<br>&gt; &gt;&gt; &gt; and<br>&gt; &gt;&gt; &gt; then write the resulting image into output. Those code is attached with<br>&gt; &gt;&gt; &gt; the<br>&gt; &gt;&gt; &gt; email.<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt; However, both of them cannot change the direction to identity and<br>&gt; &gt;&gt; &gt; generate<br>&gt; &gt;&gt; &gt; the same unrelated directions. One method is<br>&gt; &gt;&gt; &gt; though itkChangeInformationImageFilter suggested by Luis, and the other<br>&gt; &gt;&gt; &gt; is<br>&gt; &gt;&gt; &gt; using ResampleImageFilter suggested by another ITK user.<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt; By using those two methods, I got the same wired result. The direction<br>&gt; &gt;&gt; &gt; of<br>&gt; &gt;&gt; &gt; the output image is different from input image direction and is not<br>&gt; &gt;&gt; &gt; identity<br>&gt; &gt;&gt; &gt; direction neither. I am not sure why the direction in the filter is<br>&gt; &gt;&gt; &gt; identity, but it generates a totally unrelated direction in writer. The<br>&gt; &gt;&gt; &gt; followings are direction shows the directions in Input/filter/output<br>&gt; &gt;&gt; &gt; images.<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt; Input image DCM:<br>&gt; &gt;&gt; &gt; 1 0 0<br>&gt; &gt;&gt; &gt; 0 -1 0<br>&gt; &gt;&gt; &gt; 0 0 1<br>&gt; &gt;&gt; &gt; DCM got from the filter<br>&gt; &gt;&gt; &gt; 1 0 0<br>&gt; &gt;&gt; &gt; 0 1 0<br>&gt; &gt;&gt; &gt; 0 0 1<br>&gt; &gt;&gt; &gt; Output image DCM:<br>&gt; &gt;&gt; &gt; 1 0 0<br>&gt; &gt;&gt; &gt; 0 0 -1<br>&gt; &gt;&gt; &gt; 0 1 0<br>&gt; &gt;&gt; &gt; --------------------------------<br>&gt; &gt;&gt; &gt; Xi Liang<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt; ÁºÜç<br>&gt; &gt;&gt; &gt; --------------------------------<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; Date: Fri, 12 Feb 2010 09:03:51 -0500<br>&gt; &gt;&gt; &gt;&gt; Subject: Re: [Insight-users] fail to change the Direction Cosine Matrix<br>&gt; &gt;&gt; &gt;&gt; to<br>&gt; &gt;&gt; &gt;&gt; identity<br>&gt; &gt;&gt; &gt;&gt; From: luis.ibanez@kitware.com<br>&gt; &gt;&gt; &gt;&gt; To: liangxi1986317@hotmail.com<br>&gt; &gt;&gt; &gt;&gt; CC: insight-users@itk.org<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; Hi Xi,<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; You should not attempt to modify directly the information of an<br>&gt; &gt;&gt; &gt;&gt; image that is generated as the output of a filter (or a reader).<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; What you should do, is to use the<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; itkChangeInformationImageFilter<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; Connect this filter to the output of the reader and make sure<br>&gt; &gt;&gt; &gt;&gt; that you call ChangeDirectionOn() in the filter before you<br>&gt; &gt;&gt; &gt;&gt; call Update()<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; BTW: changing the direction of a medical image can<br>&gt; &gt;&gt; &gt;&gt; be a dangerous thing to do. You should make sure<br>&gt; &gt;&gt; &gt;&gt; that you have a good justification for replacing the<br>&gt; &gt;&gt; &gt;&gt; direction of the original image.<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; Regards,<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; Luis<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt;<br>&gt; &gt;&gt; &gt;&gt; -------------------------------------------------------------------<br>&gt; &gt;&gt; &gt;&gt; 2010/2/12 Xi LIANG &lt;liangxi1986317@hotmail.com&gt;:<br>&gt; &gt;&gt; &gt;&gt; &gt; Dear all,<br>&gt; &gt;&gt; &gt;&gt; &gt; I am trying to change an image direction cosine matrix to identity by<br>&gt; &gt;&gt; &gt;&gt; &gt; using<br>&gt; &gt;&gt; &gt;&gt; &gt; the following code, but it fails. I read in an input image and set<br>&gt; &gt;&gt; &gt;&gt; &gt; its<br>&gt; &gt;&gt; &gt;&gt; &gt; DCM<br>&gt; &gt;&gt; &gt;&gt; &gt; to identity, then I write it to a new image and then print out its<br>&gt; &gt;&gt; &gt;&gt; &gt; DCM<br>&gt; &gt;&gt; &gt;&gt; &gt; again. However, the DCM in the new image is not identity matrix. I am<br>&gt; &gt;&gt; &gt;&gt; &gt; not<br>&gt; &gt;&gt; &gt;&gt; &gt; sure what was wrong in my code, and the following are the major part<br>&gt; &gt;&gt; &gt;&gt; &gt; related<br>&gt; &gt;&gt; &gt;&gt; &gt; to this.<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; // I first get the DCM from the fixedImage<br>&gt; &gt;&gt; &gt;&gt; &gt; FixedImageType::DirectionType directionCosines =<br>&gt; &gt;&gt; &gt;&gt; &gt; fixedImage-&gt;GetDirection();<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; "Input DCM is " &lt;&lt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; directionCosines &lt;&lt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Terminal shows:<br>&gt; &gt;&gt; &gt;&gt; &gt; //1 0 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 -1 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 0 1<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[0][0] = 1;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[0][1] = 0;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[0][2] = 0;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[1][0] = 0;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[1][1] = 1;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[1][2] = 0;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[2][0] = 0;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[2][1] = 0;<br>&gt; &gt;&gt; &gt;&gt; &gt; directionCosines[2][2] = 1;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; directionCosines &lt;&lt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Terminal shows:<br>&gt; &gt;&gt; &gt;&gt; &gt; //1 0 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 1 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 0 1<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Then I reset the direction to identity<br>&gt; &gt;&gt; &gt;&gt; &gt; fixedImage Reader-&gt;GetOutput()-&gt;SetDirection(directionCosines);<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; "New DCM is " &lt;&lt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; fixedImageReader-&gt;GetOutput()-&gt;GetDirection() &lt;&lt;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Terminal shows:<br>&gt; &gt;&gt; &gt;&gt; &gt; //1 0 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 1 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 0 1<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Then I write the new image with the identity DCM<br>&gt; &gt;&gt; &gt;&gt; &gt; caster-&gt;SetInput( fixedImageReader-&gt;GetOutput() );<br>&gt; &gt;&gt; &gt;&gt; &gt; &amp;nbsp ; writer-&gt;SetInput( caster-&gt;GetOutput() );<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Then I read in the new image again to print its DCM<br>&gt; &gt;&gt; &gt;&gt; &gt; outputImageReader-&gt;SetFileName( argv[2] );<br>&gt; &gt;&gt; &gt;&gt; &gt; OutputImageType::ConstPointer outputImage =<br>&gt; &gt;&gt; &gt;&gt; &gt; outputImageReader-&gt;GetOutput();<br>&gt; &gt;&gt; &gt;&gt; &gt; outputImageReader-&gt;Update();<br>&gt; &gt;&gt; &gt;&gt; &gt; OutputImageType::DirectionType directionCosinesOutput =<br>&gt; &gt;&gt; &gt;&gt; &gt; outputImage-&gt;GetDirection();<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; "Output DCM is " &lt;&lt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; std::cout &lt;&lt; directionCosinesOutput &lt;&lt; std::endl;<br>&gt; &gt;&gt; &gt;&gt; &gt; //Terminal shows:<br>&gt; &gt;&gt; &gt;&gt; &gt; //1 0 0<br>&gt; &gt;&gt; &gt;&gt; &gt; // 0 -1 0<br>&gt; &gt;&gt; &gt;&gt; &gt; //0 0 1<br>&gt; &gt;&gt; &gt;&gt; &gt; --------------------------------<br>&gt; &gt;&gt; &gt;&gt; &gt; Xi Liang<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; ÁºÜç<br>&gt; &gt;&gt; &gt;&gt; &gt; --------------------------------<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; ________________________________<br>&gt; &gt;&gt; &gt;&gt; &gt; Hotmail: Trusted email with Microsoft's powerful SPAM protection.<br>&gt; &gt;&gt; &gt;&gt; &gt; Sign<br>&gt; &gt;&gt; &gt;&gt; &gt; up<br>&gt; &gt;&gt; &gt;&gt; &gt; now.<br>&gt; &gt;&gt; &gt;&gt; &gt; _____________________________________<br>&gt; &gt;&gt; &gt;&gt; &gt; Powered by www.kitware.com<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; Visit other Kitware open-source projects at<br>&gt; &gt;&gt; &gt;&gt; &gt; http://www.kitware.com/opensource/opensource.html<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; Kitware offers ITK Training Courses, for more information visit:<br>&gt; &gt;&gt; &gt;&gt; &gt; http://www.kitware.com/products/protraining.html<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; Please keep messages on-topic and check the ITK FAQ at:<br>&gt; &gt;&gt; &gt;&gt; &gt; http://www.itk.org/Wiki/ITK_FAQ<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt; Follow this link to subscribe/unsubscribe:<br>&gt; &gt;&gt; &gt;&gt; &gt; http://www.itk.org/mailman/listinfo/insight-users<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt;<br>&gt; &gt;&gt; &gt; ________________________________<br>&gt; &gt;&gt; &gt; Hotmail: Powerful Free email with security by Microsoft. Get it now.<br>&gt; &gt;<br>&gt; &gt; ________________________________<br>&gt; &gt; Hotmail: Trusted email with Microsoft¡¯s powerful SPAM protection. Sign up<br>&gt; &gt; now.<br></div>                                               <br /><hr />Hotmail: Trusted email with Microsoft¡¯s powerful SPAM protection. <a href='https://signup.live.com/signup.aspx?id=60969' target='_new'>Sign up now.</a></body>
</html>