[Insight-users] call metric in Observer code
Bill Lorensen
bill.lorensen at gmail.com
Wed Nov 25 23:53:27 EST 2009
You are dynamically casting object to 4 different itk objects:
OptimizerPointer optimizer = dynamic_cast< OptimizerPointer >( object );
MetricPointer metric = dynamic_cast< MetricPointer >( object );
TransformPointer transform = dynamic_cast< TransformPointer >( object );
FixedImagePointer fixedImage = dynamic_cast< FixedImagePointer>( object );
This is not valid code. I think only the first cast is probably valid.
Anytime you do a dynamic cast, you should check the results for NULL
to see if the cast was legal.
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