[Insight-users] Opacity for 3D image

Massinissa Bandou Massinissa.Bandou at USherbrooke.ca
Wed Dec 11 01:32:48 EST 2013


Hello ITK!
I tried to perform a  3D mutual information registration of two vtkImageData
(float) but the code seems not working. It just freeze and do nothing
without error???????

Can someone give me a hand with this

thank you in advance!!

Massi

	
typedef itk::Image<float, 3> ImageType;
typedef itk::VTKImageToImageFilter<ImageType> VTKToITKConnector;
    VTKToITKConnector::Pointer fixed = VTKToITKConnector::New();
	VTKToITKConnector::Pointer moving = VTKToITKConnector::New();
	fixed->SetInput(source); // source vtkImageData
	moving->SetInput(target); // target vtkImageData

	ImageType::Pointer  fixedImage = fixed->GetOutput();
	ImageType::Pointer  movingImage = moving->GetOutput();

	typedef float InternalPixelType;

	typedef itk::Image<float,3> InternalImageType;
	
	typedefitk::NormalizeImageFilter<ImageType, InternalImageType>
NormalizeFilterType;
	
	NormalizeFilterType::Pointer fixedNormalizer = NormalizeFilterType::New();
	NormalizeFilterType::Pointer movingNormalizer = NormalizeFilterType::New();
	
	fixedNormalizer->SetInput(fixedImage);
	movingNormalizer->SetInput(movingImage);

	  // Smooth the normalized images
	typedef
itk::DiscreteGaussianImageFilter<InternalImageType,InternalImageType>
GaussianFilterType;
	GaussianFilterType::Pointer fixedSmoother  = GaussianFilterType::New();
	GaussianFilterType::Pointer movingSmoother = GaussianFilterType::New();
	
	fixedSmoother->SetVariance(2.0);
	movingSmoother->SetVariance(2.0);
	
	fixedSmoother->SetInput(fixedNormalizer->GetOutput());
	movingSmoother->SetInput(movingNormalizer->GetOutput());

	typedef itk::TranslationTransform<double,3> TransformType;
	typedef itk::GradientDescentOptimizer OptimizerType;
	typedef itk::LinearInterpolateImageFunction<InternalImageType,double>
InterpolatorType;
	typedef itk::ImageRegistrationMethod<InternalImageType,InternalImageType>
RegistrationType;
	typedef
itk::MutualInformationImageToImageMetric<InternalImageType,InternalImageType>
MetricType;
 
	TransformType::Pointer transform = TransformType::New();
	OptimizerType::Pointer optimizer = OptimizerType::New();
	InterpolatorType::Pointer interpolator = InterpolatorType::New();
	RegistrationType::Pointer registration = RegistrationType::New();
 
	registration->SetOptimizer(optimizer);
	registration->SetTransform(transform);
	registration->SetInterpolator(interpolator);
 
	MetricType::Pointer metric = MetricType::New();
	registration->SetMetric(metric);

	metric->SetFixedImageStandardDeviation(0.4);
	metric->SetMovingImageStandardDeviation(0.4);

	registration->SetFixedImage(fixedSmoother->GetOutput());
	registration->SetMovingImage(movingSmoother->GetOutput());
	fixedNormalizer->Update();
	 
	ImageType::RegionType fixedImageRegion =
fixedNormalizer->GetOutput()->GetBufferedRegion();
	registration->SetFixedImageRegion(fixedImageRegion);
 
	typedef RegistrationType::ParametersType ParametersType;
	ParametersType initialParameters(transform->GetNumberOfParameters());

	initialParameters[0] = 0.0;  // Initial offset along X
	initialParameters[1] = 0.0;  // Initial offset along Y
	initialParameters[2] = 0.0;  // Initial offset along Z

	registration->SetInitialTransformParameters(initialParameters);

	const unsigned int numberOfPixels = fixedImageRegion.GetNumberOfPixels();
	const unsigned int numberOfSamples = static_cast<unsigned
int>(numberOfPixels * 0.01);
	metric->SetNumberOfSpatialSamples(numberOfSamples);

	optimizer->SetLearningRate(15.0);
	optimizer->SetNumberOfIterations(200);
	optimizer->MaximizeOn();

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

	ParametersType finalParameters =
registration->GetLastTransformParameters();
	double TranslationAlongX = finalParameters[0];
	double TranslationAlongY = finalParameters[1];
	double TranslationAlongZ = finalParameters[2];

	unsigned int numberOfIterations = optimizer->GetCurrentIteration();
	double bestValue = optimizer->GetValue();
	// Print out results
	std::cout<<std::endl;
	std::cout&lt;&lt;&quot;Result = &quot;&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot; Translation X =
&quot;&lt;&lt;TranslationAlongX&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot; Translation Y =
&quot;&lt;&lt;TranslationAlongY&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot; Translation Z =
&quot;&lt;&lt;TranslationAlongZ&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot; Iterations    =
&quot;&lt;&lt;numberOfIterations&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot; Metric value  =
&quot;&lt;&lt;bestValue&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot; Numb. Samples =
&quot;&lt;&lt;numberOfSamples&lt;&lt;std::endl;

	typedef itk::ResampleImageFilter&lt;ImageType,ImageType>
ResampleFilterType;
	
	TransformType::Pointer finalTransform = TransformType::New();
	finalTransform->SetParameters(finalParameters);
	finalTransform->SetFixedParameters(transform->GetFixedParameters());
	
	ResampleFilterType::Pointer resample = ResampleFilterType::New();
	resample->SetTransform(finalTransform);
	resample->SetInput(movingImage);

	resample->SetSize(fixedImage->GetLargestPossibleRegion().GetSize());
	resample->SetOutputOrigin(fixedImage->GetOrigin());
	resample->SetOutputSpacing(fixedImage->GetSpacing());
	resample->SetOutputDirection(fixedImage->GetDirection());
	resample->SetDefaultPixelValue(100);




--
View this message in context: http://itk-users.7.n7.nabble.com/Opacity-for-3D-image-tp32950.html
Sent from the ITK - Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list