<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hi all,<div><br></div><div>I wrote 2 pieces of code to change the direction to identity. <span class="Apple-style-span" style="font-family: monospace; color: rgb(68, 68, 68); ">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.</span></div><div><br></div><div><br></div><div>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 <span class="Apple-style-span" style="font-family: monospace; color: rgb(68, 68, 68); ">ResampleImageFilter suggested by another ITK user. </span><br><br></div><div>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. </div><div><br></div><div><br></div><div>Input image DCM:</div><div>1 0 0 </div><div>0 -1 0</div><div>0 0 1</div><div><br></div><div>DCM got from the filter</div><div>1 0 0</div><div>0 1 0</div><div>0 0 1</div><div><br></div><div>Output image DCM:</div><div>1 0 0</div><div>0 0 -1</div><div>0 1 0</div><div><br>--------------------------------<br>Xi Liang<br><br>ÁºÜç<br>--------------------------------<br><br><br><br><br>> Date: Fri, 12 Feb 2010 09:03:51 -0500<br>> Subject: Re: [Insight-users] fail to change the Direction Cosine Matrix to         identity<br>> From: luis.ibanez@kitware.com<br>> To: liangxi1986317@hotmail.com<br>> CC: insight-users@itk.org<br>> <br>> Hi Xi,<br>> <br>> You should not attempt to modify directly the information of an<br>> image that is generated as the output of a filter (or a reader).<br>> <br>> <br>> What you should do, is to use the<br>> <br>> itkChangeInformationImageFilter<br>> <br>> <br>> Connect this filter to the output of the reader and make sure<br>> that you call ChangeDirectionOn() in the filter before you<br>> call Update()<br>> <br>> <br>> BTW: changing the direction of a medical image can<br>> be a dangerous thing to do. You should make sure<br>> that you have a good justification for replacing the<br>> direction of the original image.<br>> <br>> <br>> <br>> Regards,<br>> <br>> <br>> <br>> Luis<br>> <br>> <br>> -------------------------------------------------------------------<br>> 2010/2/12 Xi LIANG <liangxi1986317@hotmail.com>:<br>> > Dear all,<br>> > I am trying to change an image direction cosine matrix to identity by using<br>> > the following code, but it fails. I read in an input image and set its DCM<br>> > to identity, then I write it to a new image and then print out its DCM<br>> > again. However, the DCM in the new image is not identity matrix. I am not<br>> > sure what was wrong in my code, and the following are the major part related<br>> > to this.<br>> ><br>> > // I first get the DCM from the fixedImage<br>> > FixedImageType::DirectionType directionCosines = fixedImage->GetDirection();<br>> ><br>> > std::cout << "Input DCM is " << std::endl;<br>> > std::cout << directionCosines << std::endl;<br>> > //Terminal shows:<br>> > //1 0 0<br>> > //0 -1 0<br>> > //0 0 1<br>> > directionCosines[0][0] = 1;<br>> > directionCosines[0][1] = 0;<br>> > directionCosines[0][2] = 0;<br>> > directionCosines[1][0] = 0;<br>> > directionCosines[1][1] = 1;<br>> > directionCosines[1][2] = 0;<br>> > directionCosines[2][0] = 0;<br>> > directionCosines[2][1] = 0;<br>> > directionCosines[2][2] = 1;<br>> > std::cout << directionCosines << std::endl;<br>> > //Terminal shows:<br>> > //1 0 0<br>> > //0 1 0<br>> > //0 0 1<br>> ><br>> > //Then I reset the direction to identity<br>> > fixedImage Reader->GetOutput()->SetDirection(directionCosines);<br>> ><br>> > std::cout << "New DCM is " << std::endl;<br>> > std::cout << fixedImageReader->GetOutput()->GetDirection() << std::endl;<br>> > //Terminal shows:<br>> > //1 0 0<br>> > //0 1 0<br>> > //0 0 1<br>> ><br>> ><br>> > //Then I write the new image with the identity DCM<br>> > caster->SetInput( fixedImageReader->GetOutput() );<br>> > &nbsp ; writer->SetInput( caster->GetOutput() );<br>> ><br>> > //Then I read in the new image again to print its DCM<br>> > outputImageReader->SetFileName( argv[2] );<br>> > OutputImageType::ConstPointer outputImage =<br>> > outputImageReader->GetOutput();<br>> > outputImageReader->Update();<br>> > OutputImageType::DirectionType directionCosinesOutput =<br>> > outputImage->GetDirection();<br>> > std::cout << "Output DCM is " << std::endl;<br>> > std::cout << directionCosinesOutput << std::endl;<br>> > //Terminal shows:<br>> > //1 0 0<br>> > // 0 -1 0<br>> > //0 0 1<br>> > --------------------------------<br>> > Xi Liang<br>> ><br>> > ÁºÜç<br>> > --------------------------------<br>> ><br>> ><br>> ><br>> > ________________________________<br>> > Hotmail: Trusted email with Microsoft's powerful SPAM protection. Sign up<br>> > now.<br>> > _____________________________________<br>> > Powered by www.kitware.com<br>> ><br>> > Visit other Kitware open-source projects at<br>> > http://www.kitware.com/opensource/opensource.html<br>> ><br>> > Kitware offers ITK Training Courses, for more information visit:<br>> > http://www.kitware.com/products/protraining.html<br>> ><br>> > Please keep messages on-topic and check the ITK FAQ at:<br>> > http://www.itk.org/Wiki/ITK_FAQ<br>> ><br>> > Follow this link to subscribe/unsubscribe:<br>> > http://www.itk.org/mailman/listinfo/insight-users<br>> ><br>> ><br></div>                                            <br /><hr />Hotmail: Powerful Free email with security by Microsoft. <a href='https://signup.live.com/signup.aspx?id=60969' target='_new'>Get it now.</a></body>
</html>