[Insight-users] Problem with ElasticBodySplineKernelTransform

Albert Chitemyan abbs_c at yahoo.com
Tue Jan 31 01:48:54 EST 2006


Skipped content of type multipart/alternative-------------- next part --------------
#include "itkImageFileReader.h" 
#include "itkImageFileWriter.h" 
#include "itkImage.h"
#include "itkResampleImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"

#include <itkElasticBodySplineKernelTransform.h>


#include "itkPoint.h"
#include <itkPointSet.h>
#include <fstream>


int main( int argc, char * argv[] )
{
	if( argc < 3 )
		{
		std::cerr << "Missing Parameters " << std::endl;
		std::cerr << "Usage: " << argv[0];
		std::cerr << " landmarksFile inputImage ";
		std::cerr << "DeformedImage " << std::endl;
		return 1;
		}

	const     unsigned int   ImageDimension = 2;
	typedef   unsigned char  PixelType;
	typedef   itk::Image< PixelType, ImageDimension >  InputImageType;
	typedef   itk::ImageFileReader< InputImageType  >  ReaderType;
	typedef   itk::ImageFileWriter< InputImageType >  DeformedImageWriterType;

	typedef   itk::ElasticBodySplineKernelTransform< double,   ImageDimension>     TransformType;
	typedef   itk::Point< double, ImageDimension >  PointType;
	typedef   TransformType::PointSetType      PointSetType;
	typedef   PointSetType::Pointer            PointSetPointer;
	typedef   PointSetType::PointIdentifier  PointIdType;
	typedef   itk::ResampleImageFilter< InputImageType, InputImageType  >  ResamplerType;
	typedef   itk::LinearInterpolateImageFunction< InputImageType, double >  InterpolatorType;

	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName( argv[2] );

	try
		{
		reader->Update();
		}
	catch( itk::ExceptionObject & excp )
		{
		std::cerr << "Exception thrown " << std::endl;
		std::cerr << excp << std::endl;
		return EXIT_FAILURE;
		}

	PointSetType::Pointer sourceLandMarks = PointSetType::New();
	PointSetType::Pointer targetLandMarks = PointSetType::New();
	PointType p1;     PointType p2;
	PointSetType::PointsContainer::Pointer sourceLandMarkContainer = 
									sourceLandMarks->GetPoints();
	PointSetType::PointsContainer::Pointer targetLandMarkContainer = 
									targetLandMarks->GetPoints();

	PointIdType id = itk::NumericTraits< PointIdType >::Zero;

	std::ifstream infile;
	infile.open( argv[1] );
	while (!infile.eof())
		{
		infile >>  p1[0] >> p1[1] >> p2[0] >> p2[1]; 

		sourceLandMarkContainer->InsertElement( id, p1 );
		targetLandMarkContainer->InsertElement( id++, p2 );

		} 
	infile.close();

	TransformType::Pointer transform = TransformType::New();
	transform->SetSourceLandmarks(sourceLandMarks);
	transform->SetTargetLandmarks(targetLandMarks);
	transform->ComputeWMatrix();	  

	InputImageType::ConstPointer inputImage = reader->GetOutput();
	ResamplerType::Pointer resampler = ResamplerType::New();
	InterpolatorType::Pointer interpolator = InterpolatorType::New();
	resampler->SetInterpolator( interpolator );
	InputImageType::SpacingType spacing = inputImage->GetSpacing();
	InputImageType::PointType   origin  = inputImage->GetOrigin();
	InputImageType::RegionType region = inputImage->GetBufferedRegion();
	InputImageType::SizeType   size =  region.GetSize();

	resampler->SetOutputSpacing( spacing );
	resampler->SetOutputOrigin(  origin  );
	resampler->SetSize( size );
	resampler->SetTransform( transform );
	  
	resampler->SetOutputStartIndex(  region.GetIndex() );
	resampler->SetInput( reader->GetOutput() );


	DeformedImageWriterType::Pointer deformedImageWriter = 
		DeformedImageWriterType::New();
	deformedImageWriter->SetInput( resampler->GetOutput() );
	deformedImageWriter->SetFileName( argv[3] );

	try
		{
		deformedImageWriter->Update();
		}
	catch( itk::ExceptionObject & excp )
		{
		std::cerr << "Exception thrown " << std::endl;
		std::cerr << excp << std::endl;
		return EXIT_FAILURE;
		}
}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.jpg
Type: image/pjpeg
Size: 20404 bytes
Desc: 2228698964-out.jpg
Url : http://public.kitware.com/pipermail/insight-users/attachments/20060130/fef3decc/out-0001.bin


More information about the Insight-users mailing list