[Insight-users] Is it silly to attempt this ?
Emma Ryan
eryanvtk at yahoo.com
Thu Feb 21 03:41:31 EST 2008
Hi,
I am trying to read in a 3D deformationField.vtk file and apply it to a 3D image. To read the deformation field, I use ImageFileReader <deformafieldType> and then connect the output of this to the warper.
The code for this is available below. It seems to take forever to read the deformation field file. Even after 2 hours, the reading is not complete. What is going on ? Any clues ?
Thanks,
Emma
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageRegionIterator.h"
#include "itkCastImageFilter.h"
#include "itkWarpImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkSquaredDifferenceImageFilter.h"
#include "itkCheckerBoardImageFilter.h"
#include "itkTimeProbe.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkPointSet.h"
#include <fstream>
int main( int argc, char *argv[] )
{
if( argc < 4 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " fixedImagefile movingImageFile deformField.vtk ";
std::cerr << " outputImageFile " << std::endl;
return 1;
}
const unsigned int Dimension = 3;
typedef unsigned char PixelType;
typedef itk::Image< PixelType, Dimension > FixedImageType;
typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
fixedImageReader->SetFileName( argv[1] );
typedef itk::Image< PixelType, Dimension > MovingImageType;
typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
movingImageReader->SetFileName( argv[2] );
typedef itk::Vector< float, Dimension > VectorPixelType;
typedef itk::Image< VectorPixelType, Dimension > DeformationFieldType;
typedef itk::ImageFileReader< DeformationFieldType > FieldReaderType;
FieldReaderType::Pointer fieldReader = FieldReaderType::New();
fieldReader->SetFileName( argv[3] );
try {
fieldReader->Update();
}
catch ( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return -1;
}
typedef itk::WarpImageFilter<MovingImageType, MovingImageType,DeformationFieldType > WarperType;
typedef itk::LinearInterpolateImageFunction<MovingImageType, double > InterpolatorType;
WarperType::Pointer warper = WarperType::New();
InterpolatorType::Pointer interpolator = InterpolatorType::New();
FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
warper->SetInput( movingImageReader->GetOutput() );
warper->SetInterpolator( interpolator );
warper->SetOutputSpacing( fixedImage->GetSpacing() );
warper->SetOutputOrigin( fixedImage->GetOrigin() );
warper->SetDeformationField( fieldReader->GetOutput() );
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::CastImageFilter<
MovingImageType,
OutputImageType > CastFilterType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
CastFilterType::Pointer caster = CastFilterType::New();
writer->SetFileName( argv[4] );
caster->SetInput( warper->GetOutput() );
writer->SetInput( caster->GetOutput() );
writer->Update();
return 0;
}
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080221/ae444f83/attachment.html
More information about the Insight-users
mailing list