[Insight-users] Image-Registration Output-Direction
Luis Ibanez
luis.ibanez at kitware.com
Sun Dec 12 21:22:34 EST 2010
Hi Yusuf,
Please see an example on how to do this in
the View2D class of the IGSTK toolkit,
http://public.kitware.com/cgi-bin/viewcvs.cgi/Source/igstkView2D.cxx?root=IGSTK&view=markup
Essentially you have to position your
vtkCamera according to:
http://www.itk.org/Wiki/Proposals:Orientation#DICOM_LPS_Orientation_-_Full_Body_Graphical_Example
Regards,
Luis
-----------------------------------------------------
On Sat, Dec 11, 2010 at 3:51 PM, Yusuf OEZBEK <nasil122002 at yahoo.de> wrote:
> Hallo,
>
> I wanted to have my MI-Registration in sagittal and coronal view. I made the
> registration in ITK and I presented it with VTK. But the output-direction is
> only in the axial-slice. How can I get the registration in sagittal and
> coronal view represent?
>
> Thanks
>
> Here is my Code:
>
> const unsigned int Dimension = 2;
> typedef unsigned short PixelType;
>
> typedef itk::Image< PixelType, Dimension > FixedImageType;
> typedef itk::Image< PixelType, Dimension > MovingImageType;
>
> typedef itk::TranslationTransform< double, Dimension > TransformType;
> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
> typedef itk::LinearInterpolateImageFunction< MovingImageType,double >
> InterpolatorType;
> typedef itk::ImageRegistrationMethod<FixedImageType,MovingImageType>
> RegistrationType;
>
> typedef
> itk::MattesMutualInformationImageToImageMetric<FixedImageType,MovingImageType
>> 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 );
>
> unsigned int numberOfBins = 24;
> unsigned int numberOfSamples = 10000;
>
> numberOfBins =24;
> numberOfSamples =10000;
>
> metric->SetNumberOfHistogramBins( numberOfBins );
> metric->SetNumberOfSpatialSamples( numberOfSamples );
> metric->SetUseExplicitPDFDerivatives(4);
>
> typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
> typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
>
> FixedImageReaderType::Pointer fixedImageReader =
> FixedImageReaderType::New();
> MovingImageReaderType::Pointer movingImageReader =
> MovingImageReaderType::New();
>
>
> //std::cout<<"pfad"<<filesSecondFusion.at((int)this->sliderFusion2->value()).c_str()<<endl;
>
>
> fixedImageReader->SetFileName(filesFirstFusion.at((int)this->sliderFusion1->value()).c_str());
>
> movingImageReader->SetFileName(filesSecondFusion.at((int)this->sliderFusion2->value()).c_str());
>
> registration->SetFixedImage(fixedImageReader->GetOutput());
> registration->SetMovingImage(movingImageReader->GetOutput());
>
> fixedImageReader->Update();
>
>
> registration->SetFixedImageRegion(fixedImageReader->GetOutput()->GetBufferedRegion());
>
> typedef RegistrationType::ParametersType ParametersType;
> ParametersType initialParameters( transform->GetNumberOfParameters() );
>
> initialParameters[0] = 0.0; // Initial offset in mm along X
> initialParameters[1] = 0.0; // Initial offset in mm along Y
>
> registration->SetInitialTransformParameters( initialParameters );
>
> optimizer->MinimizeOn();
> optimizer->SetMaximumStepLength(2.00);
> optimizer->SetMinimumStepLength(0.001);
> optimizer->SetNumberOfIterations(2000);
> optimizer->SetRelaxationFactor(0.8);
>
> ParametersType finalParameters =
> registration->GetLastTransformParameters();
>
> double TranslationAlongX= finalParameters[0];
> double TranslationAlongY= finalParameters[1];
>
> unsigned int numberOfIterations = optimizer->GetCurrentIteration();
>
> double bestValue = optimizer->GetValue();
>
> std::cout << "Result = " << std::endl;
> std::cout << " Translation X = " << TranslationAlongX << std::endl;
> std::cout << " Translation Y = " << TranslationAlongY << std::endl;
> std::cout << " Iterations = " << numberOfIterations << std::endl;
> std::cout << " Metric value = " << bestValue << std::endl;
> std::cout << " Stop Condition = " << optimizer->GetStopCondition() <<
> std::endl;
>
>
> typedef itk::ResampleImageFilter<MovingImageType,FixedImageType>
> ResampleFilterType;
>
> TransformType::Pointer finalTransform = TransformType::New();
>
> finalTransform->SetParameters(finalParameters);
> finalTransform->SetFixedParameters( transform->GetFixedParameters() );
>
> ResampleFilterType::Pointer resample = ResampleFilterType::New();
>
> resample->SetTransform( finalTransform );
> resample->SetInput( movingImageReader->GetOutput() );
>
> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
>
> PixelType defaultPixelValue= 100;
> defaultPixelValue= 100;
>
> resample->SetSize(fixedImage->GetLargestPossibleRegion().GetSize());
> resample->SetOutputOrigin(fixedImage->GetOrigin());
> resample->SetOutputSpacing(fixedImage->GetSpacing());
> resample->SetOutputDirection(fixedImage->GetDirection());
> resample->SetDefaultPixelValue(defaultPixelValue);
>
>
> typedef unsigned char OutputPixelType;
> typedef itk::Image<OutputPixelType, Dimension> OutputImageType;
> typedef itk::CastImageFilter<FixedImageType,OutputImageType>
> CastFilterType;
> typedef itk::ImageFileWriter<OutputImageType> WriterType;
>
> WriterType::Pointer writer= WriterType::New();
> CastFilterType::Pointer caster= CastFilterType::New();
>
> writer->SetFileName("registration1.jpg");
>
> caster->SetInput(resample->GetOutput());
> writer->SetInput(caster->GetOutput());
> writer->Update();
>
> typedef itk::CheckerBoardImageFilter< FixedImageType >
> CheckerBoardFilterType;
> CheckerBoardFilterType::Pointer checker = CheckerBoardFilterType::New();
>
> checker->SetInput1(fixedImage);
> checker->SetInput2(resample->GetOutput());
>
> if(imageRegistrationCheckerboardChoice->value()== 0){
> unsigned int checkerArray[3]= {2,2,2};
> checker->SetCheckerPattern(checkerArray);
> }
> if(imageRegistrationCheckerboardChoice->value()== 1){
> unsigned int checkerArray[3]= {4,4,4};
> checker->SetCheckerPattern(checkerArray);
> }
> if(imageRegistrationCheckerboardChoice->value()== 2){
> unsigned int checkerArray[3]= {8,8,8};
> checker->SetCheckerPattern(checkerArray);
> }
> if(imageRegistrationCheckerboardChoice->value()== 3){
> unsigned int checkerArray[3]= {16,16,16};
> checker->SetCheckerPattern(checkerArray);
> }
>
> caster->SetInput(checker->GetOutput());
> writer->SetInput(caster->GetOutput() );
>
> resample->SetDefaultPixelValue(100);
>
> // Before registration
> TransformType::Pointer identityTransform = TransformType::New();
> identityTransform->SetIdentity();
> resample->SetTransform( identityTransform );
>
> writer->SetFileName("registration2.jpg");
> writer->Update();
>
>
> // After registration
> resample->SetTransform( finalTransform );
> writer->SetFileName("registration3.jpg");
> writer->Update();
>
> typedef itk::VTKImageExport< OutputImageType > ExportFilterType;
> ExportFilterType::Pointer itkExporter = ExportFilterType::New();
> itkExporter->SetInput(caster->GetOutput() );
>
> vtkImageImport* vtkImporter = vtkImageImport::New();
> ConnectPipelines(itkExporter, vtkImporter);
> vtkImporter->Update();
>
> modeFusion = vtkInteractorStyleTrackballCamera::New();
>
> rendererFusion = vtkRenderer::New();
>
> renderWindowFusion = vtkRenderWindow::New();
> renderWindowFusion->AddRenderer(rendererFusion);
>
> imageFusionBox->SetRenderWindow(renderWindowFusion);
> imageFusionBox->SetInteractorStyle(modeFusion);
> imageFusionBox->Initialize();
>
>
> imgFirstColorMap = vtkLookupTable::New();
> imgFirstColorMap->SetTableRange(-250, 1200);
> imgFirstColorMap->SetSaturationRange(0,0);
> imgFirstColorMap->SetHueRange(0, 0);
> imgFirstColorMap->SetValueRange(0, 2);
> imgFirstColorMap->Build();
>
> firstColorMapper = vtkImageMapToColors::New();
> firstColorMapper->SetInput(vtkImporter->GetOutput());
> firstColorMapper->SetLookupTable(imgFirstColorMap);
>
> imgFusionMIActor = vtkImageActor::New();
> imgFusionMIActor->SetInput(firstColorMapper->GetOutput());
> imgFusionMIActor->SetOpacity(1.0);
>
> cameraFusion = vtkCamera::New();
> cameraFusion->SetViewUp(0, 0, -1);
> cameraFusion->SetPosition(0, 1, 0);
> cameraFusion->SetFocalPoint(0, 0, 0);
> cameraFusion->ComputeViewPlaneNormal();
> cameraFusion->Roll(-90);
> cameraFusion->Azimuth(90);
> cameraFusion->Roll(90);
>
> rendererFusion->AddActor(imgFusionMIActor);
> rendererFusion->SetActiveCamera(cameraFusion);
> rendererFusion->ResetCamera();
> cameraFusion->Dolly(1.7);
> rendererFusion->ResetCameraClippingRange();
>
>
>
>
>
> Mit freundlichen Grüßen
> Yusuf ÖZBEK
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list