[Insight-users] Visualizing a 2D deformation field - the answer
Boettcher, Dr. Peter
Boettcher at kleintierklinik.uni-leipzig.de
Mon Apr 14 16:00:49 EDT 2008
Thank you Karthikö. This is what I found out ...
Here are the answers I was looking for when I tried to visualize the deformation fields produced by the 2D deformable image registration examples
First one has to change the 2D-vector declaration to a 3D-vector declaration.
const unsigned int Dimension = 2;
typedef float VectorComponentType;
typedef itk::Vector< VectorComponentType, 3 > VectorType;
typedef itk::Image< VectorType, Dimension > DeformationFieldType;
Then we have to fill the third component of the vector with zero (after computation of the deformation field).
try
{
deformer->UpdateLargestPossibleRegion();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
DeformationFieldType::Pointer deformationField = deformer->GetOutput();
Now we have to loop over all vectors within the deformation field and set the 3rd component to the desired value:
DeformationFieldType::PixelType VectorValue;
DeformationFieldType::SizeType size = deformationField->GetLargestPossibleRegion().GetSize();
DeformationFieldType::IndexType vectorIndex;
for(int y = 0; y < size[1]; y++)
for(int x = 0; x < size[0]; x++)
{
vectorIndex[0] = x; // x position
vectorIndex[1] = y; // y position
VectorValue = deformationField->GetPixel( vectorIndex);
VectorValue[2] = 0.0; // z component
deformationField->SetPixel(vectorIndex, VectorValue);
}
Finally we save the deformation field using the meta-image file format (*.mdh). This file can be loaded with Paraview.
typedef itk::ImageFileWriter< DeformationFieldType > FieldWriterType;
FieldWriterType::Pointer Fieldwriter = FieldWriterType::New();
Fieldwriter->SetInput ( deformationField );
Fieldwriter->SetFileName( argv[5] );
deformer->Print( std::cout );
try
{
Fieldwriter->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << "Exception thrown by writer" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
Putting some glyphs onto the image makes the deformation visible.
Regards, Peter.
------------------------------------
Peter Böttcher, Dr med vet, DipECVS
European Veterinary Specialist in Surgery
Fachtierarzt für Kleintierchirurgie
Klinik für Kleintiere
Universität Leipzig
An den Tierkliniken 23
D-04103 Leipzig (Germany)
Tel: +49-341-9738700
Fax: +49-341-9738799
email: boettcher at kleintierklinik.uni-leipzig.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080414/1e920f6e/attachment.htm>
More information about the Insight-users
mailing list