[Insight-users] Set the right pixelType

Massinissa Bandou Massinissa.Bandou at USherbrooke.ca
Fri Jan 10 23:00:27 EST 2014


Dear ITK

I'm trying to use a template function to read 2 unknown images type for a
mutual information registration. The problem is in pixelType1 & pixelType2
(specified in test() function of class TomoRegistration). If I replace them
by float or double or any other format, the program compiles and works fine.
In other hand, I get these errors:

Error	2	error C2146: syntax error : missing ';' before identifier
'ComponentType'	c:\program
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h	45	1
TomoRegistration
Error	4	error C2602:
'itk::DefaultConvertPixelTraits<PixelType>::ComponentType' is not a member
of a base class of 'itk::DefaultConvertPixelTraits<PixelType>'	c:\program
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h	45	1
TomoRegistration
Error	1	error C2838: 'ComponentType' : illegal qualified name in member
declaration	c:\program
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h	45	1
TomoRegistration
Error	5	error C2868:
'itk::DefaultConvertPixelTraits<PixelType>::ComponentType' : illegal syntax
for using-declaration; expected qualified-name	c:\program
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h	45	1
TomoRegistration
Error	3	error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int	c:\program
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h	45	1
TomoRegistration



class ITKRegistration
{
public:
	ITKRegistration();
	~ITKRegistration();

template<typename pixelType1, typename pixelType2>
	vtkSmartPointer<vtkMatrix4x4> VolumeRegistration(const string source, const
string target,int iteration,pixelType1,pixelType2)
	{
		typedef itk::Image< pixelType1, 3 >  FixedImageType; 
		typedef itk::Image< pixelType2, 3 >  MovingImageType;

		typedef itk::VersorRigid3DTransform< double > TransformType;
		typedef itk::VersorRigid3DTransformOptimizer                                 
OptimizerType;
		//typedef itk::MeanSquaresImageToImageMetric< FixedImageType,
MovingImageType > MetricType;
		typedef itk::MutualInformationImageToImageMetric< FixedImageType,
MovingImageType > MetricType;
		typedef itk::LinearInterpolateImageFunction< MovingImageType, double >       
InterpolatorType;
		typedef itk::ImageRegistrationMethod< FixedImageType, MovingImageType >      
RegistrationType;
	
		MetricType::Pointer         metric        = MetricType::New();
		OptimizerType::Pointer      optimizer     = OptimizerType::New();
		InterpolatorType::Pointer   interpolator  = InterpolatorType::New();
		TransformType::Pointer  transform = TransformType::New();

		RegistrationType::Pointer   registration  = RegistrationType::New();
		registration->SetMetric(        metric        );
		registration->SetOptimizer(     optimizer     );
		registration->SetInterpolator(  interpolator  );
		registration->SetTransform( transform );
	
		typedef itk::ImageFileReader<FixedImageType> FixedImageReaderType;
		typedef itk::ImageFileReader<MovingImageType> MovingImageReaderType;

		FixedImageReaderType::Pointer  fixedImageReader  =
FixedImageReaderType::New();
		MovingImageReaderType::Pointer movingImageReader =
MovingImageReaderType::New();
		fixedImageReader->SetFileName(source.c_str()); 
		movingImageReader->SetFileName(target.c_str());


		registration->SetFixedImage(fixedImageReader->GetOutput());
		registration->SetMovingImage(   movingImageReader->GetOutput()   );

		try{
			fixedImageReader->Update();
		}catch(itk::ExceptionObject & excp){
			std::cerr << excp << std::endl;
		}

	
registration->SetFixedImageRegion(fixedImageReader->GetOutput()->GetBufferedRegion()
);

		typedef
itk::CenteredTransformInitializer<TransformType,FixedImageType,MovingImageType> 
TransformInitializerType;
		TransformInitializerType::Pointer initializer =
TransformInitializerType::New();
	  
		initializer->SetTransform(transform);
		initializer->SetFixedImage(fixedImageReader->GetOutput());
		initializer->SetMovingImage(movingImageReader->GetOutput());
		initializer->MomentsOn();
		initializer->InitializeTransform();

		typedef TransformType::VersorType  VersorType;
		typedef VersorType::VectorType     VectorType;
		VersorType     rotation;
		VectorType     axis;
		axis[0] = 0.0;
		axis[1] = 0.0;
		axis[2] = 1.0;
		const double angle = 0;
		rotation.Set(  axis, angle  );
		transform->SetRotation( rotation );

		registration->SetInitialTransformParameters( transform->GetParameters() );

		typedef OptimizerType::ScalesType       OptimizerScalesType;
		OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );
		const double translationScale = 1.0 / 1000.0;
		optimizerScales[0] = 1.0;
		optimizerScales[1] = 1.0;
		optimizerScales[2] = 1.0;
		optimizerScales[3] = translationScale;
		optimizerScales[4] = translationScale;
		optimizerScales[5] = translationScale;
		optimizer->SetScales( optimizerScales );
		optimizer->SetMaximumStepLength( 0.2000  );
		optimizer->SetMinimumStepLength( 0.0001 );
		optimizer->SetNumberOfIterations( iteration );

		CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
		observer->GetTomo(this->in);
		optimizer->AddObserver(itk::IterationEvent(),observer);

		try{
			registration->Update();
			std::cout << "Optimizer stop condition: "<<
registration->GetOptimizer()->GetStopConditionDescription()<< std::endl;
		}
		catch( itk::ExceptionObject & err ){
			std::cerr << "ExceptionObject caught !" << std::endl;
			std::cerr << err << std::endl;
		}

		OptimizerType::ParametersType finalParameters =
registration->GetLastTransformParameters();
		const double versorX              = finalParameters[0];
		const double versorY              = finalParameters[1];
		const double versorZ              = finalParameters[2];
		const double finalTranslationX    = finalParameters[3];
		const double finalTranslationY    = finalParameters[4];
		const double finalTranslationZ    = finalParameters[5];
		const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
		const double bestValue = optimizer->GetValue();

		std::cout << std::endl << std::endl;
		std::cout << " Result = " << std::endl;
		std::cout << " versor X      = " << versorX  << std::endl;
		std::cout << " versor Y      = " << versorY  << std::endl;
		std::cout << " versor Z      = " << versorZ  << std::endl;
		std::cout << " Translation X = " << finalTranslationX  << std::endl;
		std::cout << " Translation Y = " << finalTranslationY  << std::endl;
		std::cout << " Translation Z = " << finalTranslationZ  << std::endl;
		std::cout << " Iterations    = " << numberOfIterations << std::endl;
		std::cout << " Metric value  = " << bestValue          << std::endl;

		transform->SetParameters( finalParameters );
		TransformType::MatrixType matrix = transform->GetMatrix();
		TransformType::OffsetType offset = transform->GetOffset();
		std::cout << "Matrix = " << std::endl << matrix << std::endl;
		std::cout << "Offset = " << std::endl << offset << std::endl;

		vtkSmartPointer<vtkMatrix4x4> matrixOfTransformation =
vtkSmartPointer<vtkMatrix4x4>::New();
		for(unsigned int i=0;i<3;i++){
			for(unsigned int j=0;j<3;j++){
				matrixOfTransformation->SetElement(i,j,matrix(i,j));
			}
		}
		matrixOfTransformation->SetElement(0,3,versorX);
		matrixOfTransformation->SetElement(1,3,versorY);
		matrixOfTransformation->SetElement(2,3,versorZ);
		matrixOfTransformation->SetElement(3,0,0);
		matrixOfTransformation->SetElement(3,1,0);
		matrixOfTransformation->SetElement(3,2,0);
		matrixOfTransformation->SetElement(3,3,1);

		cout<<"matrix from mutual information:
"<<endl&lt;&lt;*matrixOfTransformation&lt;&lt;endl;

		return matrixOfTransformation;
}
};



class TomoRegistration : public QMainWindow, Ui::TomoRegistrationClass
{
public:
void test(){
typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
	itk::ImageIOBase::Pointer imageIOsource =
itk::ImageIOFactory::CreateImageIO(&quot;writesource.mhd&quot;,itk::ImageIOFactory::ReadMode);
	imageIOsource->SetFileName("writesource.mhd");
	imageIOsource->ReadImageInformation();
	const ScalarPixelType pixelTypeSource = imageIOsource->GetComponentType();

	itk::ImageIOBase::Pointer imageIOtarget =
itk::ImageIOFactory::CreateImageIO("writetarget.mhd",itk::ImageIOFactory::ReadMode);
	imageIOtarget->SetFileName("writetarget.mhd");
	imageIOtarget->ReadImageInformation();
	const ScalarPixelType pixelTypeTarget = imageIOtarget->GetComponentType();

vtkSmartPointer<vtkMatrix4x4> MatrixFromMutualInformation =
MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,pixelTypeSource,pixelTypeTarget);
}
};




--
View this message in context: http://itk-users.7.n7.nabble.com/Set-the-right-pixelType-tp33171.html
Sent from the ITK - Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list