[Insight-users] call metric in Observer code
Serena Fabbri
fabbri at u.washington.edu
Mon Nov 30 20:10:24 EST 2009
Hi Luis,
thank you very much to explain clearly the mistake.
I fixed the code and now I am able to calculate local MI.
Now I am a bit surprised because the
SetFixedImageRegion is (10,17,20) pixelsize and the FixedImage is (80,80,101) pixelsize and
I am finding that the values of local MI are pretty close to the global values of MI.
I use all pixel for local MI and 10% of statistic for global MI.
Do you think this is reasonable?
Thanks again for any suggestion.
Serena.
These are the results of LOCAL MI:
0 -0.420331
1 -0.437285
2 -0.452543
3 -0.46165
4 -0.468013
5 -0.473045
6 -0.476698
7 -0.479594
8 -0.482887
9 -0.484799
10 -0.48746
11 -0.489388
12 -0.490882
13 -0.492886
14 -0.494813
15 -0.495938
16 -0.497812
17 -0.498596
18 -0.500178
19 -0.501496
20 -0.502828
21 -0.503783
22 -0.504879
23 -0.506142
24 -0.507478
25 -0.508179
26 -0.509647
27 -0.51022
28 -0.511936
29 -0.51237
30 -0.51411
31 -0.514496
32 -0.516189
33 -0.516839
34 -0.518303
35 -0.518713
36 -0.520112
37 -0.520491
38 -0.521601
39 -0.522019
40 -0.523052
41 -0.523425
42 -0.524304
43 -0.524585
44 -0.525526
45 -0.52578
46 -0.526725
47 -0.526987
48 -0.528026
49 -0.528595
50 -0.529578
-GLOBAL MI
0 -0.420331
1 -0.437285
2 -0.452543
3 -0.46165
4 -0.468013
5 -0.473045
6 -0.476698
7 -0.479594
8 -0.482887
9 -0.484799
10 -0.48746
11 -0.489388
12 -0.490882
13 -0.492886
14 -0.494813
15 -0.495938
16 -0.497812
17 -0.498596
18 -0.500178
19 -0.501496
20 -0.502828
21 -0.503783
22 -0.504879
23 -0.506142
24 -0.507478
25 -0.508179
26 -0.509647
27 -0.51022
28 -0.511936
29 -0.51237
30 -0.51411
31 -0.514496
32 -0.516189
33 -0.516839
34 -0.518303
35 -0.518713
36 -0.520112
37 -0.520491
38 -0.521601
39 -0.522019
40 -0.523052
41 -0.523425
42 -0.524304
43 -0.524585
44 -0.525526
45 -0.52578
46 -0.526725
47 -0.526987
48 -0.528026
49 -0.528595
On Thu, 26 Nov 2009, Luis Ibanez wrote:
> Serena,
>
> The "caller" argument of the Execute method is an Observer
> is the pointer to the object that invoked the event.
>
> In your particular case, this is the Optimizer.
>
> As Bill explained,
> you can only cast "caller" to the OptimizerType.
>
>
> For all the other elements of the registration framework, you have
> to pass them through other means to the command.
>
> One way of doing this is to have them as Member variables,
> and to have "Set" methods for them.
>
> Like
>
>> 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;
>>
> MetricPointer m_Metric;
> TransformPointer m_Transform;
> FixedImagePointer m_FixedImage;
> MovingImagePointer m_MovingImage;
>
>
> public:
>
> SetTransform( TransformType * transform ) { m_Transform = transform; }
> SetFixedImage( FixedImageType * fixed ) { m_FixedImage = fixed; }
> SetMovingImage( MovingImageType * moving ) { m_MovingImage = moving; }
>
>
> and then you can use them in your Execute method.
>
> Also,
> when you connect the Command to the optimizer,
> you should also do:
>
>
> observer->SetFixedImage( fixedImage );
> observer->SetMovingImage( movingImage );
> observer->SetTransform( transform );
>
> optimizer->AddObserver( itk::IterationEvent(), observer );
>
> In this way, the components of the registration framework
> will be available to the internals of your observer class.
>
>
> Regards,
>
>
> Luis
>
>
> -------------------------------------------------------------------------------
> On Wed, Nov 25, 2009 at 8:51 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.
>> 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;
>>
>>
>>
>> }
>> };
>>
>>
>> _____________________________________
>> 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