<html>
<body>
<br>
Im trying to write the Jacobian determinant of the deformation field
after register two images.<br>
When I write to a file the deformation field seems to be OK. The next
step is to write to a file the deformation field but it returns to be all
zeros. <br>
What can be wrong?<br><br>
--------------------------------------------------------------------------------------------<br>
<br>
<font face="Arial, Helvetica" color="#008000">// Generate the explicit
deformation field resulting from <br>
</font><font face="Arial, Helvetica">
</font><font face="Arial, Helvetica" color="#008000">// the
registration.<br><br>
</font><font face="Arial, Helvetica">
</font><font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica"> itk::Vector<
</font><font face="Arial, Helvetica" color="#0000FF">float</font>
<font face="Arial, Helvetica">, ImageDimension >
VectorType;<br>
</font><font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica"> itk::Image< VectorType, ImageDimension
> DeformationFieldType;<br><br>
DeformationFieldType::Pointer field =
DeformationFieldType::New();<br>
field->SetRegions( fixedRegion );<br>
field->SetOrigin( fixedImage->GetOrigin() );<br>
field->SetSpacing( fixedImage->GetSpacing() );<br>
field->Allocate();<br><br>
</font><font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica"> itk::ImageRegionIterator<
DeformationFieldType > FieldIterator;<br>
FieldIterator fi( field, fixedRegion );<br><br>
fi.GoToBegin();<br><br>
TransformType::InputPointType fixedPoint;<br>
TransformType::OutputPointType movingPoint;<br>
DeformationFieldType::IndexType index;<br><br>
VectorType displacement;<br><br>
</font><font face="Arial, Helvetica" color="#0000FF">while</font>
<font face="Arial, Helvetica">( ! fi.IsAtEnd() )<br>
{<br>
index = fi.GetIndex();<br>
field->TransformIndexToPhysicalPoint( index,
fixedPoint );<br>
movingPoint = finaltransform ->TransformPoint(
fixedPoint );<br>
displacement[0] = movingPoint[0] - fixedPoint[0];<br>
displacement[1] = movingPoint[1] - fixedPoint[1];<br>
fi.Set( displacement );<br>
++fi;<br>
}<br><br>
<br>
<x-tab> </x-tab></font>
<font face="Arial, Helvetica" color="#0000FF">if</font>
<font face="Arial, Helvetica">( argc >= 12)<br>
{<br>
<x-tab> </x-tab><x-tab>
</x-tab>std::cout
<<
</font><font face="Arial, Helvetica" color="#800000">"Writing
Deformation Field to file"</font><font face="Arial, Helvetica">
<< std::endl; <br>
<x-tab> </x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica"> itk::ImageFileWriter<
DeformationFieldType > FieldWriterType;<br>
<x-tab> </x-tab>
FieldWriterType::Pointer fieldWriter = FieldWriterType::New();<br><br>
<x-tab> </x-tab>
fieldWriter->SetInput( field );<br><br>
<x-tab> </x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">if</font>
<font face="Arial, Helvetica">( argc >= 12)<br>
<x-tab> </x-tab><x-tab>
</x-tab>{<br>
<x-tab> </x-tab><x-tab>
</x-tab>
fieldWriter->SetFileName( DeformationFieldFile );<br>
<x-tab> </x-tab><x-tab>
</x-tab></font>
<font face="Arial, Helvetica" color="#0000FF">try<br>
</font><font face="Arial, Helvetica"><x-tab>
</x-tab><x-tab>
</x-tab> {<br>
<x-tab> </x-tab><x-tab>
</x-tab>
fieldWriter->Update();<br>
<x-tab> </x-tab><x-tab>
</x-tab> }<br>
<x-tab> </x-tab><x-tab>
</x-tab></font>
<font face="Arial, Helvetica" color="#0000FF">catch</font>
<font face="Arial, Helvetica">( itk::ExceptionObject & excp )<br>
<x-tab> </x-tab><x-tab>
</x-tab> {<br>
<x-tab> </x-tab><x-tab>
</x-tab> std::cerr
<<
</font><font face="Arial, Helvetica" color="#800000">"Exception
thrown "</font><font face="Arial, Helvetica"> <<
std::endl;<br>
<x-tab> </x-tab><x-tab>
</x-tab> std::cerr
<< excp << std::endl;<br>
<x-tab> </x-tab><x-tab>
</x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">return</font>
<font face="Arial, Helvetica"> EXIT_FAILURE;<br>
<x-tab> </x-tab><x-tab>
</x-tab> }<br>
<x-tab> </x-tab><x-tab>
</x-tab>}<br>
<x-tab> </x-tab>}<br><br>
</font><font face="Arial, Helvetica" color="#008000">
//-----------------------------------------------------------------------------------------------------------<br>
</font><font face="Arial, Helvetica"> </font>
<font face="Arial, Helvetica" color="#008000">// Calculate the Jacobian
Determinant of the deformation field <br>
</font><font face="Arial, Helvetica">
</font><font face="Arial, Helvetica" color="#008000">// <br>
</font><font face="Arial, Helvetica"><x-tab>
</x-tab>std::cout
<<
</font><font face="Arial, Helvetica" color="#800000">"Calculating
Jacobian Determinant"</font><font face="Arial, Helvetica"> <<
std::endl; <br>
<x-tab> </x-tab></font>
<font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica">
itk::DeformationFieldJacobianDeterminantFilter< DeformationFieldType
> JacobianDeterminantFilterType;<br>
<x-tab> </x-tab>
JacobianDeterminantFilterType::Pointer JacobianDeterminantFilter =
JacobianDeterminantFilterType::New();<br>
<x-tab> </x-tab></font>
<font face="Arial, Helvetica" color="#008000">//derivatives in the image
scaled with pixel size (derivative in world coordinates)<br>
</font><font face="Arial, Helvetica"><x-tab>
</x-tab>
JacobianDeterminantFilter->SetUseImageSpacingOn();<br>
<x-tab> </x-tab>
JacobianDeterminantFilter->SetInput( field );<br><br>
<x-tab> </x-tab>std::cout
<<
</font><font face="Arial, Helvetica" color="#800000">"Writing
Jacobian Determinant to file"</font><font face="Arial, Helvetica">
<< std::endl; <br>
<x-tab> </x-tab><br>
<x-tab> </x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica">
JacobianDeterminantFilterType::OutputImageType JacobianImageType;<br>
<x-tab> </x-tab><br>
<x-tab> </x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">typedef</font>
<font face="Arial, Helvetica"> itk::ImageFileWriter< JacobianImageType
> JacobianWriterType;<br>
<x-tab> </x-tab>
JacobianWriterType::Pointer JacobianWriter =
JacobianWriterType::New();<br><br>
<x-tab> </x-tab>
JacobianWriter->SetInput(
JacobianDeterminantFilter->GetOutput());<br><br>
<x-tab> </x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">if</font>
<font face="Arial, Helvetica">( argc >= 13)<br>
<x-tab> </x-tab><x-tab>
</x-tab>{<br>
<x-tab> </x-tab><x-tab>
</x-tab>
JacobianWriter->SetFileName( JacobianFile );<br>
<x-tab> </x-tab><x-tab>
</x-tab></font>
<font face="Arial, Helvetica" color="#0000FF">try<br>
</font><font face="Arial, Helvetica"><x-tab>
</x-tab><x-tab>
</x-tab> {<br>
<x-tab> </x-tab><x-tab>
</x-tab>
JacobianWriter->Update();<br>
<x-tab> </x-tab><x-tab>
</x-tab> }<br>
<x-tab> </x-tab><x-tab>
</x-tab></font>
<font face="Arial, Helvetica" color="#0000FF">catch</font>
<font face="Arial, Helvetica">( itk::ExceptionObject & excp )<br>
<x-tab> </x-tab><x-tab>
</x-tab> {<br>
<x-tab> </x-tab><x-tab>
</x-tab> std::cerr
<<
</font><font face="Arial, Helvetica" color="#800000">"Exception
thrown "</font><font face="Arial, Helvetica"> <<
std::endl;<br>
<x-tab> </x-tab><x-tab>
</x-tab> std::cerr
<< excp << std::endl;<br>
<x-tab> </x-tab><x-tab>
</x-tab>
</font><font face="Arial, Helvetica" color="#0000FF">return</font>
<font face="Arial, Helvetica"> EXIT_FAILURE;<br>
<x-tab> </x-tab><x-tab>
</x-tab> }<br>
<x-tab> </x-tab><x-tab>
</x-tab>}</font></body>
</html>