[Insight-users] Seg fault while using itkMutualInformationImageToImageMetric

Luis Ibanez luis.ibanez@kitware.com
Fri, 31 Jan 2003 10:38:49 -0500


Hi Tuhin,

The Registration method cannot produce a value
with GetValue() without having run the optimizer.

In other words, the output of GetValue() is only
valid after you call "StartRegistration()" and
the optimizer converges.

However, if you are only interested in evaluating
the MutualInformation, you don't need the registration
method at all.  Simply use the metric as you already
instantiated it,  BUT call "Initialize()" on the metric
before calling "GetValue()" on the metric too.

The call to Initialize() should be placed in a try/catch
block since exceptions may be thrown if anything goes
wrong during the initialization.

The code will look like:

     mi->SetMovingImageStandardDeviation(1);
     mi->SetFixedImageStandardDeviation(1);
     mi->SetNumberOfSpatialSamples(50);
     mi->SetTransform( transform );
     mi->SetInterpolator( interpolator );

     try {
       mi->Initialize();
     }
     catch( itk::ExceptionObject &exp )
      {
      std::cerr << exp << std::endl;
      }

   //
   // here... define parameters
   // (following Julien's advice)..
   //

   const double value =  mi->GetValue( parameters );

   std::cout << "VAlue = " << value << std::endl;



   Note that due to the stochastic nature of the
   way in which MI is estimated, the program will
   give you slightly diferent values if you run it
   several times.


  Please let us know if you find further problems.


     Luis




BTW, for some reason you email address did
not appeared on your post.



--------------------------
Tuhin wrote:
> Hello all,
> 
>   I am trying to use the itkMutualInformationImageToImageMetric class to 
> calculate the mutual information between two images.  I don't want to 
> register the images using itk, I just want the mutual information.  I have 
> tried to get the following code to run on a Linux box with last night's itk 
> source and I get a seg-fault (no exception is raised) at the last line in the 
> try block.  Any regarding my issue would be appreciated.
> 
> TIA,
> 
> Tuhin
> 
>   //My typedefs
>   typedef itk::Image<unsigned char,3> ImageType;
>   typedef itk::MutualInformationImageToImageMetric<ImageType,ImageType>
> 	MetricType;
>   typedef itk::QuaternionRigidTransform<double> TransformType;
>   typedef itk::ImageRegistrationMethod<ImageType,ImageType> RegistrationType;
> 
>   //Set up the ITK MutualInformation calculator
>   MetricType::Pointer mi = MetricType::New();
>   MetricType::ParametersType params;
>   TransformType::Pointer transform = TransformType::New();
>   RegistrationType::Pointer reg = RegistrationType::New();
> 
>   try {
>     mi->SetMovingImageStandardDeviation(1);
>     mi->SetFixedImageStandardDeviation(1);
>     mi->SetNumberOfSpatialSamples(50);
>     
>     reg->SetMetric(mi);
>     reg->SetTransform(transform);
>     reg->SetFixedImage(orig_imp->GetOutput());
>     reg->SetMovingImage(defo_imp->GetOutput());
> 
>     params.resize(7);
>     for(int i = 0; i < 7; i++) {
>       params(i) = 0;      
>     }
>     params(3) = 1;
>     cout << mi->GetValue(params) << endl;
>   }
>   catch (itk::ExceptionObject &e) {
>     cout << "Exception detected: " << e;
>     return -1;
>   }
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 
>