[Insight-users] Problem using filters

Mathias Seitel mathias.seitel at igd.fhg.de
Tue Jun 1 05:07:36 EDT 2004


Hi Rob,

it seems that in your program the reader whose output is passed on to 
the BinaryThresholdImageFilter isn't assigned a filename. A filename is 
only assigned to the other two readers (fixedImageReader and 
movingImageReader). If what you want is to read a fixed and a moving 
image, and then to apply a BinaryThresholdImageFilter to both images 
before starting the registration, then two filter instances should be 
used, like in the code snippet below.

Hope that helps,
Mathias


// ...

typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;
typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;

typedef itk::BinaryThresholdImageFilter< 
                      FixedImageType, OutputImageType > 
FixedImageFilterType;

typedef itk::BinaryThresholdImageFilter< 
                      MovingImageType, OutputImageType > 
MovingImageFilterType;

FixedImageReaderType::Pointer  fixedImageReader  =
FixedImageReaderType::New();
fixedImageReader->SetFileName(      m_sRef     );

MovingImageReaderType::Pointer movingImageReader =
MovingImageReaderType::New();
movingImageReader->SetFileName(     m_sTar     );

FixedImageFilterType fixedImageFilter = FixedImageFilterType::New();

MovingImageFilterType movingImageFilter = MovingImageFilterType::New();

try
{
////////////////////////////////////////////
fixedImageFilter->SetInput( fixedImageReader->GetOutput() );//
fixedImageFilter->SetOutsideValue(0);              //
fixedImageFilter->SetInsideValue(255);            //
fixedImageFilter->SetLowerThreshold( 10 );       //
fixedImageFilter->SetUpperThreshold(  255);       //
fixedImageFilter->Update();                       //

movingImageFilter->SetInput( movingImageReader->GetOutput() );//
movingImageFilter->SetOutsideValue(0);              //
movingImageFilter->SetInsideValue(255);            //
movingImageFilter->SetLowerThreshold( 10 );       //
movingImageFilter->SetUpperThreshold(  255);       //
movingImageFilter->Update();                       //
////////////////////////////////////////////
}

catch(...)
{
m_sTekst = "Verkeerde parameters";
}



Rob Bijman wrote:
> Dear ITK users,
> 
> I have a problem using filters inside my program.
> For my program I use two pictures to registrate the movement between the 
> two.
> Now I want to use filters for the pictures to change the pixel 
> intensities (Especially the Binary Tresholdfilter to turn the pixels 
> into black (0) and white (255)), but the filters don't do anything at 
> all. Maybe that's because the filter doesn't work for two images at the 
> same time? Can somebody tell me what I am doing wrong? (There were no 
> errors when running)
> The program parameters from a part of my program are listed below.
> 
> With kind regards,
> 
> Rob Bijman
> 
> 
> 
> if (m_Affine2 == TRUE)
> {
> const unsigned int Dimension = 2;
> typedef float PixelType;
> 
> //////////////
> typedef unsigned char InputPixelType;
> typedef unsigned char OutputPixelType;
> typedef itk::Image< InputPixelType, 2 > InputImageType;
> ///////////
> typedef itk::Image< OutputPixelType, 2 > OutputImageType;
> ////////////
> 
> typedef itk::Image< PixelType, Dimension >                 FixedImageType;
> typedef itk::Image< PixelType, Dimension >                 MovingImageType;
> //typedef itk::Image< PixelType, Dimension >                
> OutputImageType;
> typedef itk::CenteredAffineTransform< double, Dimension >             
> TransformType;
> typedef itk::RegularStepGradientDescentOptimizer                 
> OptimizerType;
> typedef itk::MeanSquaresImageToImageMetric<
>             FixedImageType,
>             MovingImageType >                 MetricType;
> typedef itk:: LinearInterpolateImageFunction<
>             MovingImageType,
>             double >                     InterpolatorType;
> typedef itk::ImageRegistrationMethod<
>             FixedImageType,
>             MovingImageType >                RegistrationType;
> 
> ////////////////////////////////////////////////////////////////////////////////// 
> 
> typedef 
> itk::BinaryThresholdImageFilter<                                        //
>             InputImageType, OutputImageType > 
> FilterType;                       //
> typedef itk::ImageFileReader< InputImageType > ReaderType;
> typedef itk::ImageFileWriter< InputImageType > WriterType;
> ////////////////////////////////////////////////////////////////////////////////// 
> 
> 
> 
> MetricType::Pointer metric = MetricType::New();
> TransformType::Pointer transform = TransformType::New();
> OptimizerType::Pointer optimizer = OptimizerType::New();
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> RegistrationType::Pointer registration = RegistrationType::New();
> 
> ///////////////////////////////////////////////////
> ReaderType::Pointer reader = ReaderType::New();//
> FilterType::Pointer filter = FilterType::New();//
> ///////////////////////////////////////////////////
> 
> registration->SetMetric(         metric         );
> registration->SetOptimizer(         optimizer        );
> registration->SetTransform(         transform        );
> registration->SetInterpolator(         interpolator    );
> 
> typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;
> typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
> 
> FixedImageReaderType::Pointer  fixedImageReader  = 
> FixedImageReaderType::New();
> MovingImageReaderType::Pointer movingImageReader = 
> MovingImageReaderType::New();
> ////
> try
> {
> ////////////////////////////////////////////
> filter->SetInput( reader->GetOutput() );//
> filter->SetOutsideValue(0);              //
> filter->SetInsideValue(255);            //
> filter->SetLowerThreshold( 10 );       //
> filter->SetUpperThreshold(  255);       //
> filter->Update();                       //
> ////////////////////////////////////////////
> }
> 
> catch(...)
> {
> m_sTekst = "Verkeerde parameters";
> }
> ////
> fixedImageReader->SetFileName(      m_sRef     );
> movingImageReader->SetFileName(     m_sTar     );
> 
> registration->SetFixedImage(         fixedImageReader->GetOutput()     );
> registration->SetMovingImage(     movingImageReader->GetOutput()     );
> 
> fixedImageReader->Update();
> movingImageReader->Update();
> 
> m_sTekst = "Work in Progress";
> UpdateData(FALSE);
> 
> 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();
> 
> registration->SetInitialTransformParameters(    
> transform->GetParameters()    );
> 
> double translationScale = 1.0 / 5000.0;
> typedef OptimizerType::ScalesType       OptimizerScalesType;
> OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );
> 
> optimizerScales[0] =  1.0;
> optimizerScales[1] =  1.0;
> optimizerScales[2] =  1.0;
> optimizerScales[3] =  1.0;
> optimizerScales[4] =  translationScale;
> optimizerScales[5] =  translationScale;
> optimizerScales[6] =  translationScale;
> optimizerScales[7] =  translationScale;
> optimizer->SetScales( optimizerScales );
> 
> double steplength = 4;
> unsigned int maxNumberOfIterations = m_dMaxIter;
> 
> optimizer->SetMaximumStepLength( steplength );
> optimizer->SetMinimumStepLength( 0.001 );
> optimizer->SetNumberOfIterations( maxNumberOfIterations );
> optimizer->MinimizeOn();
> 
> 
> try
> {
> registration->StartRegistration();
> }
> catch(...)
> {
> m_sTekst= "Er gaat iets niet goed";
> }
> 
> 
> OptimizerType::ParametersType finalParameters =
>                    registration->GetLastTransformParameters();
> 
> const double finalRot = finalParameters[2];
> const double finalRotationCenterX = finalParameters[4];
> const double finalRotationCenterY = finalParameters[5];
> const double finalTranslationX    = finalParameters[6];
> const double finalTranslationY    = finalParameters[7];
> 
> const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
> 
> const double bestValue = optimizer->GetValue();
> 
> //const double finalMetric = metric->GetValue();     // eventueel kan 
> het ook zoals in ImageRegistration9.cxx met resample
> 
> ///////////////// Einde ITK gedeelte
> 
> m_dTransX = 0; //Translatie doet hier niet mee;
> m_dTransY = 0; //Translatie doet hier niet mee;
> m_dRot = 58.63*finalRot;       //Van radialen naar graden;
> m_dOpt = 0;
> m_dIter = numberOfIterations;  //Aantal Iteraties
> 
> _________________________________________________________________
> Play online games with your friends with MSN Messenger 
> http://messenger.msn.nl/
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 

-- 
Dipl.-Inf. (FH) Mathias Seitel
Fraunhofer Gesellschaft         Phone: +49-6151-155 484
Institute for Computer Graphics Fax: +49-6151-155 559
Fraunhoferstr. 5                mailto: mathias.seitel at igd.fhg.de
D-64283 Darmstadt, Germany      www: http://www.igd.fhg.de/igd-a7


More information about the Insight-users mailing list