[Insight-users] Local MI value...problem

Serena Fabbri fabbri at u.washington.edu
Tue Nov 24 20:22:56 EST 2009


Hi Karthik ,
thank you for your suggestion.

I have followed  your advice but I get an error message (see below).
Could you help me again?

Thank you.

Serena






#include "itkCommand.h"
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::Image< float, 3 >  FixedImageType;
 	typedef itk::Image< float, 3 >  MovingImageType;
 	typedef itk::MattesMutualInformationImageToImageMetric< FixedImageType, MovingImageType 
>MetricType;
 	typedef   const MetricType*  MetricPointer;


 	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);

   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)
     { MetricPointer MI = dynamic_cast< MetricPointer >( object );
       OptimizerPointer optimizer = dynamic_cast< OptimizerPointer >( object );
       if( !(itk::IterationEvent().CheckEvent( &event )) )
         {
         return;
         }


 	  MI->SetFixedImageRegion(fixedRegionMetric);
 	  MI->SetNumberOfSpatialSamples(numberOfSamples );
 	  MI->SetNumberOfHistogramBins( 20 );
 	  MI->SetUseExplicitPDFDerivatives( 1 );
 	  MI->SetUseCachingOfBSplineWeights( 1 );
 	  MI->SetUseAllPixels(1);
       std::cout << optimizer->GetCurrentIteration() << "MIglobal   "<< optimizer->GetValue() << " 
MIlocal  "<<MI->GetValue();
       std::cout << std::endl;
     }
};



/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:119: warning: ISO C++ forbids
    declaration of `start' with no type
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:119: warning: ISO C++ forbids
    initialization of member `start'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:119: warning: making `start' static
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:119: error: invalid in-class
    initialization of static data member of non-integral type `int[0]'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:120: warning: ISO C++ forbids
    declaration of `start' with no type
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:120: warning: ISO C++ forbids
    initialization of member `start'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:120: warning: making `start' static
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:120: error: invalid in-class
    initialization of static data member of non-integral type `int[1]'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:121: warning: ISO C++ forbids
    declaration of `start' with no type
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:121: warning: ISO C++ forbids
    initialization of member `start'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:121: warning: making `start' static
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:121: error: invalid in-class
    initialization of static data member of non-integral type `int[2]'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:123: warning: ISO C++ forbids
    declaration of `size' with no type
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:123: warning: ISO C++ forbids
    initialization of member `size'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:123: warning: making `size' static
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:123: error: invalid in-class
    initialization of static data member of non-integral type `int[0]'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:124: warning: ISO C++ forbids
    declaration of `size' with no type
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:124: warning: ISO C++ forbids
    initialization of member `size'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:124: warning: making `size' static
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:124: error: invalid in-class
    initialization of static data member of non-integral type `int[1]'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:125: warning: ISO C++ forbids
    declaration of `size' with no type
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:125: warning: ISO C++ forbids
    initialization of member `size'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:125: warning: making `size' static
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:125: error: invalid in-class
    initialization of static data member of non-integral type `int[2]'
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:129: error: syntax error before `.'
    token
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:130: error: syntax error before `.'
    token
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx: In member function `virtual void
    CommandIterationUpdate::Execute(const itk::Object*, const itk::EventObject&)
    ':
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:146: warning: passing `const
    itk::MattesMutualInformationImageToImageMetric<itk::Image<float, 3>,
    itk::Image<float, 3> >' as `this' argument of `void
    itk::ImageToImageMetric<TFixedImage,
    TMovingImage>::SetFixedImageRegion(typename TFixedImage::RegionType) [with
    TFixedImage = itk::Image<float, 3>, TMovingImage = itk::Image<float, 3>]'
    discards qualifiers
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:147: error: `numberOfSamples'
    undeclared (first use this function)
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:147: error: (Each undeclared
    identifier is reported only once for each function it appears in.)
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:148: warning: passing `const
    itk::MattesMutualInformationImageToImageMetric<itk::Image<float, 3>,
    itk::Image<float, 3> >' as `this' argument of `void
    itk::MattesMutualInformationImageToImageMetric<TFixedImage,
    TMovingImage>::SetNumberOfHistogramBins(long unsigned int) [with TFixedImage
    = itk::Image<float, 3>, TMovingImage = itk::Image<float, 3>]' discards
    qualifiers
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:149: warning: passing `const
    itk::MattesMutualInformationImageToImageMetric<itk::Image<float, 3>,
    itk::Image<float, 3> >' as `this' argument of `void
    itk::MattesMutualInformationImageToImageMetric<TFixedImage,
    TMovingImage>::SetUseExplicitPDFDerivatives(bool) [with TFixedImage =
    itk::Image<float, 3>, TMovingImage = itk::Image<float, 3>]' discards
    qualifiers
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:150: warning: passing `const
    itk::MattesMutualInformationImageToImageMetric<itk::Image<float, 3>,
    itk::Image<float, 3> >' as `this' argument of `void
    itk::MattesMutualInformationImageToImageMetric<TFixedImage,
    TMovingImage>::SetUseCachingOfBSplineWeights(bool) [with TFixedImage =
    itk::Image<float, 3>, TMovingImage = itk::Image<float, 3>]' discards
    qualifiers
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:151: warning: passing `const
    itk::MattesMutualInformationImageToImageMetric<itk::Image<float, 3>,
    itk::Image<float, 3> >' as `this' argument of `void
    itk::MattesMutualInformationImageToImageMetric<TFixedImage,
    TMovingImage>::SetUseAllPixels(bool) [with TFixedImage = itk::Image<float,
    3>, TMovingImage = itk::Image<float, 3>]' discards qualifiers
/Users/fabbri/Code/BSpline_MMI_RSG_2.cxx:152: error: no matching function for
    call to `itk::MattesMutualInformationImageToImageMetric<itk::Image<float,
    3>, itk::Image<float, 3> >::GetValue() const'
/Users/fabbri/InsightToolkit-
3.10.0/Code/Algorithms/itkMattesMutualInformationImageToImageMetric.txx:696: error: candidates
    are: typename itk::ImageToImageMetric<TFixedImage,
    TMovingImage>::MeasureType
    itk::MattesMutualInformationImageToImageMetric<TFixedImage,
    TMovingImage>::GetValue(typename itk::ImageToImageMetric<TFixedImage,
    TMovingImage>::ParametersType&) const [with TFixedImage = itk::Image<float,
    3>, TMovingImage = itk::Image<float, 3>]
make[2]: *** [CMakeFiles/BSpline_MMI_RSG_2.dir/BSpline_MMI_RSG_2.o] Error 1
make[1]: *** [CMakeFiles/BSpline_MMI_RSG_2.dir/all] Error 2
make: *** [all] Error 2




On Mon, 23 Nov 2009, Karthik Krishnan wrote:

> Nothing prevents you from instantiating a separate metric and setting
> the fixed and moving images on it and calling GetValue() yourself. You
> don't need to always drive it from an optimizer (although that is the
> typical use case).
>
> You could place this code in your observer. Your instantiated Mattes
> metric would use all samples (see the option on the metric). Also set
> the transform at the current iteration on the metric.
>
> You may prefer to use itkMutualInformationHistogramImageToImageMetric
> . There is no sampling, smoothing with a kernel function etc, if you
> plan to use every single voxel.
>
>
>
> On Mon, Nov 23, 2009 at 7:34 PM, Serena Fabbri <fabbri at u.washington.edu> wrote:
>>
>>
>>
>> Hi All,
>>
>> I am registering CT image and MRI image with Mattes-MI and BSpline
>> Transformation (Non Rigid Registration).
>> I want use all images for metric calculation but I'd like to know the value
>> of the MI in a particular region of the my fixed image.
>> I think that SetFixedRegion and SetFixedImageMask are not useful for my task
>> because they restrict the MI calculation to the specified region. am I
>> wrong?
>> any suggestion?
>>
>> Thank you.
>> Serena.
>>
>> _____________________________________
>> 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
>>
>
>
>
> --
> _________________________________
> Karthik Krishnan
> R&D Engineer,
> Kitware Inc.
>




More information about the Insight-users mailing list