[Insight-users] 3D affinetransform

Antoine Leimgruber antoine.leimgruber at sokal.ch
Tue Apr 10 16:00:38 EDT 2007


Hello,

I am using DicomSeriesReadImageWrite2.cxx to read a dicom series.
Everything goes well with DicomSeriesReadImageWrite2.cxx and my dicom files.
I am trying to modify ResampleImageFilter3.cxx from a 2D (which works well) to a 3D affinetransform.
If I insert my 3D version of a translation in DicomSeriesReadImageWrite2.cxx before the writer->Update, then all the pixels of the output image have the value set in SetDefaultPixelValue, even if I set the translation to 0.0 0.0 0.0
I have checked that spacing and size were right and did not know what to put in origin, so I did set it to 0.0 0.0 0.0

Here is the code of the translation that I inserted in DicomSeriesReadImageWrite2.cxx 

Thank you for your help

Antoine

	typedef itk::ResampleImageFilter<ImageType,OutputImageType> FilterType;
	FilterType::Pointer filter = FilterType::New();

	typedef itk::AffineTransform< double, Dimension >  TransformType;
	TransformType::Pointer transform = TransformType::New();

	typedef itk::NearestNeighborInterpolateImageFunction< ImageType, double >  InterpolatorType;
	InterpolatorType::Pointer interpolator = InterpolatorType::New();
	filter->SetInterpolator( interpolator );
	
	filter->SetDefaultPixelValue( 100 );
	
	double spacing[ Dimension ];
	spacing[0] = 0.3125;//0.6;//0.4283; // pixel spacing in millimeters along X
	spacing[1] = 0.3125;//0.6;//0.5350; // pixel spacing in millimeters along Y
	spacing[2] = 1.0;//0.6;//0.5350; // pixel spacing in millimeters along Z
	filter->SetOutputSpacing( spacing );

	double origin[ Dimension ];
	origin[0] = 0.0;  // X space coordinate of origin
	origin[1] = 0.0;  // Y space coordinate of origin
	origin[2] = 0.0;  // Z space coordinate of origin
	filter->SetOutputOrigin( origin );

	ImageType::SizeType   size;
	size[0] = 128;  // number of pixels along X
	size[1] = 128;  // number of pixels along Y
	size[2] = 20;   // number of pixels along Z
	filter->SetSize( size );

	filter->SetInput( reader->GetOutput() );
	writer->SetInput( filter->GetOutput() );
	
	TransformType::OutputVectorType translation0;
	std::cout << "Please enter X translation translation in millimeters: ";
	std::cin >>translation0[0];  // X translation in millimeters
	std::cout << "Please enter Y translation translation in millimeters: ";
	std::cin >> translation0[1];  // Y translation in millimeters
	std::cout << "Please enter Z translation translation in millimeters: ";
	std::cin >> translation0[2];  // Z translation in millimeters
	transform->Translate( translation0, true);
	
	filter->SetTransform( transform );	



More information about the Insight-users mailing list