[Insight-users] call metric in Observer code

Serena Fabbri fabbri at u.washington.edu
Wed Nov 25 20:51:06 EST 2009


Hi All,

I am registering CT image and MRI image with Mattes MI and Bspline Transformation.
I'd like to know the value of MI of a little area of the fixed image during the registration process.
I call the metric in the observer code but i get a bus error.

could anybody suggest me where the error is?

Thank you very much.

Serena





class CommandIterationUpdate : public itk::Command 
{
public:
   typedef  CommandIterationUpdate   Self;
   typedef  itk::Command             Superclass;
   typedef itk::SmartPointer<Self>  Pointer;
   itkNewMacro( Self );

protected:
   CommandIterationUpdate() {};

public:
    typedef itk::RegularStepGradientDescentOptimizer     OptimizerType;
    typedef   const OptimizerType   *    OptimizerPointer;

 	typedef itk::OrientedImage< float, 3 >  FixedImageType;
 	typedef   const  FixedImageType*  FixedImagePointer;

 	typedef itk::OrientedImage< float, 3 >  MovingImageType;

 	typedef itk::MattesMutualInformationImageToImageMetric< FixedImageType, MovingImageType 
>MetricType;
 	typedef   const MetricType*  MetricPointer;

 	typedef itk::BSplineDeformableTransform< double,3,3 > DeformableTransformType;
 	typedef   const DeformableTransformType*  TransformPointer;




   void Execute(itk::Object *caller, const itk::EventObject & event)
     {
       Execute( (const itk::Object *)caller, event);
     }

   void Execute(const itk::Object * object, const itk::EventObject & event)
     {

 		OptimizerPointer optimizer = dynamic_cast< OptimizerPointer >( object );
 		MetricPointer metric = dynamic_cast< MetricPointer >( object );
 		TransformPointer transform = dynamic_cast< TransformPointer >( object );
 	    FixedImagePointer fixedImage = dynamic_cast< FixedImagePointer>( object );
 		FixedImageType::IndexType start;
 		FixedImageType::SizeType size;

 		 start[0]=43;
 		 start[1]=30;
 		 start[2]=0;

 		 size[0]=10;
 		 size[1]=17;
 		 size[2]=20;


 		 FixedImageType::RegionType fixedRegionMetric ;
 		 fixedRegionMetric.SetIndex(start);
 		 fixedRegionMetric.SetSize(size);

 		OptimizerType::ParametersType parameters;


       if( !(itk::IterationEvent().CheckEvent( &event )) )
         {
         return;
         }
 	    metric->SetFixedImageRegion(fixedRegionMetric);
 		metric->SetUseAllPixels( true );
 	    parameters = transform->GetParameters();


 	  std::cout << optimizer->GetCurrentIteration() << "MIglobal   "<< optimizer->GetValue() << " 
MIlocal  "<<metric->GetValue(parameters);
       std::cout << std::endl;



     }
};




More information about the Insight-users mailing list