[Insight-users] itk::ERROR: BSplineDeformableTransform

Darren Weber darren.weber.lists at gmail.com
Wed Oct 7 15:50:34 EDT 2009


Hi Luis,

Thank you for taking the time to look over this code so closely (your quick
response has allowed me to move on with the work today).

This is a question about replacing a section of BSplineTransform init code
with the helper class to do that, as discussed in
http://hdl.handle.net/1926/1338

Below is a section of code that uses the helper class and comments out
previous init code to define the BSpline grid parameters.  Does it do this
correctly?

    typedef itk::BSplineDeformableTransform< CoordinateRepType,
SpaceDimension, SplineOrder > bsTransformType;
    bsTransformType::Pointer bsTransform = bsTransformType::New();

    // Use the itk::BSplineDeformableTransformInitializer to simplify
    // initialization of the grid parameters for the
itk::BSplineDeformableTranform.
    // It will ensure that no small detail is missed in the process.
    typedef itk::BSplineDeformableTransformInitializer< bsTransformType,
bwInputImageType > bsInitializerType;
    bsInitializerType::Pointer bsTransformInitilizer =
bsInitializerType::New();
    bsTransformInitilizer->SetTransform( bsTransform );
    bsTransformInitilizer->SetImage( fixBWimg );
    bsTransformInitilizer->SetNumberOfGridNodesInsideTheImage( 5 );
    bsTransformInitilizer->InitializeTransform();

    // BEGIN COMMENTED CODE SECTION
    // Here we define the parameters of the BSplineDeformableTransform
grid.  We
    // arbitrarily decide to use a grid with $5 \times 5$ nodes within the
image.
    // The reader should note that the BSpline computation requires a
    // finite support region (1 grid node at the lower borders and 2
    // grid nodes at upper borders). Therefore in this example, we set
    // the grid size to be $8 \times 8$ and place the grid origin such that
    // grid node (1,1) coincides with the first pixel in the fixed image.
    //typedef bsTransformType::RegionType RegionType;
    //RegionType::SizeType gridSizeOnImage;
    //RegionType::SizeType gridBorderSize;
    //RegionType::SizeType gridTotalSize;
    //gridSizeOnImage.Fill( 5 );
    //gridBorderSize.Fill( 3 );    // Border for spline order = 3 ( 1 lower,
2 upper )
    //gridTotalSize = gridSizeOnImage + gridBorderSize;
    //RegionType gridRegion;
    //gridRegion.SetSize( gridTotalSize );
    //// grid spacing is based on fixed image spacing
    //bsTransformType::SpacingType gridSpacing = fixBWimg->GetSpacing();
    //for(unsigned int r=0; r<ImageDimension; r++)
    //    {
    //    gridSpacing[r] *= static_cast<double>(fixBWimgSize[r] - 1)  /
    //                      static_cast<double>(gridSizeOnImage[r] - 1);
    //    }
    //// grid origin is based on fixed image origin
    //bwInputImageType::DirectionType gridDirection =
fixBWimg->GetDirection();
    //bsTransformType::SpacingType gridOriginOffset = gridDirection *
gridSpacing;
    //bsTransformType::OriginType origin = fixBWimg->GetOrigin();
    //bsTransformType::OriginType gridOrigin = origin - gridOriginOffset;
    //bsTransform->SetGridRegion( gridRegion );
    //bsTransform->SetGridOrigin( gridOrigin );
    //bsTransform->SetGridSpacing( gridSpacing );
    //bsTransform->SetGridDirection( gridDirection );
    // END COMMENTED CODE SECTION

    // Initialize the BSpline transform parameters.
    typedef bsTransformType::ParametersType bsParametersType;
    const unsigned int bsNumberOfParameters =
bsTransform->GetNumberOfParameters();
    bsParametersType bsParameters( bsNumberOfParameters );
    bsParameters.Fill( 0.0 );
    bsTransform->SetParameters( bsParameters );

    // Use the affine transform in the BSpline transform.
    bsTransform->SetBulkTransform( affineTransform );



Note how the code still has a section at the end to init BSpline parameters
(coefficients?).  As indicated in the IJ article source code, the helper
class (itk::BSplineDeformableTransformInitializer) only sets the grid
parameters on the BSpline transform, not the "coefficients".  The article
was published based on code in ITK 3.12.0, is this still correct for ITK
3.16.0, or does the helper class also set the "coefficients"?

Regards,
Darren









On Wed, Oct 7, 2009 at 7:34 AM, Luis Ibanez <luis.ibanez at kitware.com> wrote:

> Hi Darren,
>
> After running your program in GDB, things become clearer.
>
> The problem is that in lines 621-624:
>
>    bsTransformType::Pointer bsFinalTransform = bsTransformType::New();
>    bsFinalTransform->SetParameters(
> bsRegistration->GetLastTransformParameters() );
>    bsFinalTransform->SetFixedParameters( bsTransform->GetFixedParameters()
> );
>
> You are setting the new parameters values BEFORE setting
> the Fixed parameters of the transform. The settings of the
> BSpline grid are part of the Fixed parameters. Therefore, you
> are passing the values of deformation to all the BSpline grid
> nodes, without having first specified how many grid nodes
> there are.
>
> The fix is simple:
> Invert the order of the SetFixedParameters and SetParameters calls.
>
> Like
>
>    bsTransformType::Pointer bsFinalTransform = bsTransformType::New();
>    // FIXED parameters MUST Be set first.
>    bsFinalTransform->SetFixedParameters( bsTransform->GetFixedParameters()
> );
>    bsFinalTransform->SetParameters(
> bsRegistration->GetLastTransformParameters() );
>
>
> With this change, the code runs for me until the end
> without throwing exceptions.
>
>
> The lbfgs optimizer is still unhappy though...
>
>
>
>   Regards,
>
>
>         Luis
>
>
>
> -------------------------------------------
> On Wed, Oct 7, 2009 at 10:18 AM, Luis Ibanez <luis.ibanez at kitware.com>
> wrote:
> > Hi Darren,
> >
> > Yes, there are multiple ways of debugging this errror.
> >
> > It would seems that the grid of the BSpline transform
> > is not defined, despite the fact that you seem to be
> > setting that correctly (from looking at your code.)
> >
> > BTW: thanks for attaching the source code.
> >
> > The first thing to try, would be to add:
> >
> >    bsTransform->Print( std::cout );
> >
> > to line 594, just after the call to StartRegistration().
> >
> > This will allow us to see the state of the BSpline transform
> > at that point. In particular we are interested in seeing
> > the values of the BSpline grid.
> >
> >
> >    Please let us know what you find,
> >
> >
> >          Thanks
> >
> >
> >                Luis
> >
> >
> > -----------------------------------------------------------------------
> > On Tue, Oct 6, 2009 at 6:28 PM, Darren Weber
> > <darren.weber.lists at gmail.com> wrote:
> >>
> >> Is there an easy way to debug this error?
> >>
> >> vnl_lbfgs: Error. Netlib routine lbfgs failed.
> >> terminate called after throwing an instance of 'itk::ExceptionObject'
> >>   what():
> >>
> /opt/local/include/InsightToolkit-3.16/Common/itkBSplineDeformableTransform.txx:347:
> >> itk::ERROR: BSplineDeformableTransform(0x126f390): Mismatched between
> >> parameters size 128 and region size 0
> >>
> >>
> >> See code file attached.  Example files are available at
> >> ftp://ftp.buckinstitute.org/dweber/itkRegistrationFiles.tar.gz
> >>
> >> The src code builds OK and it's called using:
> >>
> >>         # Bspline deformation registration: $imgMov TO $imgFix
> >>         $HOME/bin/itkImageBsplineCoregistration \
> >>             $imgFixBW  $imgMovBW  ${imgOutBW}.${imgType} \
> >>             $imgFixRGB $imgMovRGB ${imgOutRGB}.${imgType} \
> >>             ${imgOutBW}_DiffBefore.$imgType \
> >>             ${imgOutBW}_DiffAfter.$imgType > ${imgOutBW}.log
> >>
> >> TIA,
> >> Darren
> >>
> >>
> >> _____________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.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
> >>
> >>
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091007/8f730893/attachment-0001.htm>


More information about the Insight-users mailing list