Hello,<br><br>I`m trying to align two images in analyze format. However, the output is always a blank image with a black line (always in the same place - around the top of the image). <br>I use the class itkImageFileReader to read the two images and I don`t think the problem is related with it. I think there`s something missing, but don`t know what.<br>
<br>Here is my sourcecode: (C++)<br><br>void Alinhador::alinhar() {<br> const unsigned int Dimension = 3;<br> typedef short PixelType;<br><br> // TIPOS<br> typedef itk::VersorRigid3DTransform< double > TransformType;<br>
typedef itk::RegularStepGradientDescentOptimizer OptimizerType;<br> typedef itk::MattesMutualInformationImageToImageMetric<ImageType, ImageType> MetricType;<br> typedef itk::LinearInterpolateImageFunction<ImageType, double> InterpolatorType;<br>
typedef itk::ImageRegistrationMethod< ImageType, ImageType > RegistrationType;<br><br> //INSTANCIAS<br> MetricType::Pointer metric = MetricType::New();<br> OptimizerType::Pointer optimizer = OptimizerType::New();<br>
InterpolatorType::Pointer interpolator = InterpolatorType::New();<br> TransformType::Pointer transform = TransformType::New();<br> RegistrationType::Pointer registration = RegistrationType::New();<br><br> metric->UseAllPixelsOn(); <br>
<br> registration->SetMetric(metric);<br> registration->SetOptimizer(optimizer);<br> registration->SetInterpolator(interpolator);<br> registration->SetTransform(transform );<br><br> registration->SetFixedImage(this->fixedImage);<br>
registration->SetMovingImage(this->movingImage);<br> this->fixedImage->Update();<br><br> registration->SetFixedImageRegion( this->fixedImage->GetBufferedRegion() );<br><br><br> //INITIALIZER<br>
typedef itk::CenteredTransformInitializer< TransformType, ImageType, ImageType > TransformInitializerType;<br> TransformInitializerType::Pointer initializer = TransformInitializerType::New();<br><br> initializer->SetTransform( transform );<br>
initializer->SetFixedImage(this->fixedImage );<br> initializer->SetMovingImage(this->movingImage );<br> //initializer->GeometryOn();<br> initializer->MomentsOn();<br><br> initializer->InitializeTransform();<br>
<br> registration->SetInitialTransformParameters( transform->GetParameters() );<br><br> typedef OptimizerType::ScalesType OptimizerScalesType;<br> OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );<br>
const double translationScale = 1.0 / 1000.0;<br><br> std::cout<< transform->GetNumberOfParameters() << std::endl;<br> optimizerScales[0] = 1.0;<br> optimizerScales[1] = 1.0;<br> optimizerScales[2] = 1.0;<br>
optimizerScales[3] = translationScale;<br> optimizerScales[4] = translationScale;<br> optimizerScales[5] = translationScale;<br><br> optimizer->SetScales( optimizerScales );<br><br> optimizer->SetMaximumStepLength( 1.0 ); <br>
optimizer->SetMinimumStepLength( 0.06 );<br><br> optimizer->SetNumberOfIterations( 100 );<br><br><br> CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<br> optimizer->AddObserver( itk::IterationEvent(), observer );<br>
<br><br> try <br> { <br> registration->StartRegistration(); <br> } <br> catch( itk::ExceptionObject & err ) <br> { <br> std::cerr << "ExceptionObject caught !" << std::endl; <br>
std::cerr << err << std::endl; <br> return;<br> } <br><br> OptimizerType::ParametersType finalParameters = <br> registration->GetLastTransformParameters();<br><br><br> const double versorX = finalParameters[0];<br>
const double versorY = finalParameters[1];<br> const double versorZ = finalParameters[2];<br> const double finalTranslationX = finalParameters[3];<br> const double finalTranslationY = finalParameters[4];<br>
const double finalTranslationZ = finalParameters[5];<br><br> const unsigned int numberOfIterations = optimizer->GetCurrentIteration();<br><br> const double bestValue = optimizer->GetValue();<br><br> transform->SetParameters( finalParameters );<br>
<br> TransformType::MatrixType matrix = transform->GetRotationMatrix();<br> TransformType::OffsetType offset = transform->GetOffset();<br><br> std::cout << "Matrix = " << std::endl << matrix << std::endl;<br>
std::cout << "Offset = " << std::endl << offset << std::endl;<br><br><br> TransformType::Pointer finalTransform = TransformType::New();<br><br> finalTransform->SetCenter( transform->GetCenter() );<br>
<br> finalTransform->SetParameters( finalParameters );<br><br> resampler = ResampleFilterType::New();<br><br> resampler->SetTransform( finalTransform );<br> resampler->SetInput( this->movingImage );<br>
<br> ImageType::Pointer fixedImage = this->fixedImage;<br><br> resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );<br> resampler->SetOutputOrigin( fixedImage->GetOrigin() );<br>
resampler->SetOutputSpacing( fixedImage->GetSpacing() );<br> resampler->SetDefaultPixelValue( 100 );<br>}<br><br>