<br>Hi Luis,<br><br>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).<br><br>This is a question about replacing a section of BSplineTransform init code with the helper class to do that, as discussed in <a href="http://hdl.handle.net/1926/1338">http://hdl.handle.net/1926/1338</a><br>
<br>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?<br><br><font size="1"><span style="font-family: courier new,monospace;"> typedef itk::BSplineDeformableTransform< CoordinateRepType, SpaceDimension, SplineOrder > bsTransformType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsTransformType::Pointer bsTransform = bsTransformType::New();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Use the itk::BSplineDeformableTransformInitializer to simplify</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // initialization of the grid parameters for the itk::BSplineDeformableTranform.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // It will ensure that no small detail is missed in the process.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::BSplineDeformableTransformInitializer< bsTransformType, bwInputImageType > bsInitializerType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsInitializerType::Pointer bsTransformInitilizer = bsInitializerType::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> bsTransformInitilizer->SetTransform( bsTransform );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsTransformInitilizer->SetImage( fixBWimg );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> bsTransformInitilizer->SetNumberOfGridNodesInsideTheImage( 5 );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsTransformInitilizer->InitializeTransform();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // BEGIN COMMENTED CODE SECTION<br>
// Here we define the parameters of the BSplineDeformableTransform grid. We</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // arbitrarily decide to use a grid with $5 \times 5$ nodes within the image. </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // The reader should note that the BSpline computation requires a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // finite support region (1 grid node at the lower borders and 2</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // grid nodes at upper borders). Therefore in this example, we set</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // the grid size to be $8 \times 8$ and place the grid origin such that</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // grid node (1,1) coincides with the first pixel in the fixed image.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //typedef bsTransformType::RegionType RegionType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //RegionType::SizeType gridSizeOnImage;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //RegionType::SizeType gridBorderSize;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //RegionType::SizeType gridTotalSize;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //gridSizeOnImage.Fill( 5 );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //gridBorderSize.Fill( 3 ); // Border for spline order = 3 ( 1 lower, 2 upper )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //gridTotalSize = gridSizeOnImage + gridBorderSize;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //RegionType gridRegion;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //gridRegion.SetSize( gridTotalSize );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //// grid spacing is based on fixed image spacing</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //bsTransformType::SpacingType gridSpacing = fixBWimg->GetSpacing();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //for(unsigned int r=0; r<ImageDimension; r++)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // gridSpacing[r] *= static_cast<double>(fixBWimgSize[r] - 1) / </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // static_cast<double>(gridSizeOnImage[r] - 1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //// grid origin is based on fixed image origin</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //bwInputImageType::DirectionType gridDirection = fixBWimg->GetDirection();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //bsTransformType::SpacingType gridOriginOffset = gridDirection * gridSpacing;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //bsTransformType::OriginType origin = fixBWimg->GetOrigin();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //bsTransformType::OriginType gridOrigin = origin - gridOriginOffset;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //bsTransform->SetGridRegion( gridRegion );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //bsTransform->SetGridOrigin( gridOrigin );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //bsTransform->SetGridSpacing( gridSpacing );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //bsTransform->SetGridDirection( gridDirection );</span><br style="font-family: courier new,monospace;">
</font><font size="1"><span style="font-family: courier new,monospace;"> // END COMMENTED CODE SECTION<br>
</span></font><br style="font-family: courier new,monospace;"><font size="1"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> // Initialize the BSpline transform parameters.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef bsTransformType::ParametersType bsParametersType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> const unsigned int bsNumberOfParameters = bsTransform->GetNumberOfParameters();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsParametersType bsParameters( bsNumberOfParameters );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> bsParameters.Fill( 0.0 );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsTransform->SetParameters( bsParameters );</span><br><br style="font-family: courier new,monospace;"></font><font size="1"><span style="font-family: courier new,monospace;"> // Use the affine transform in the BSpline transform.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bsTransform->SetBulkTransform( affineTransform );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"></span></font><br><br>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"?<br>
<br>Regards,<br>Darren<br><br><br><br><br><br><br><br><br><br><div class="gmail_quote">On Wed, Oct 7, 2009 at 7:34 AM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Darren,<br>
<br>
After running your program in GDB, things become clearer.<br>
<br>
The problem is that in lines 621-624:<br>
<br>
bsTransformType::Pointer bsFinalTransform = bsTransformType::New();<br>
bsFinalTransform->SetParameters(<br>
bsRegistration->GetLastTransformParameters() );<br>
bsFinalTransform->SetFixedParameters( bsTransform->GetFixedParameters() );<br>
<br>
You are setting the new parameters values BEFORE setting<br>
the Fixed parameters of the transform. The settings of the<br>
BSpline grid are part of the Fixed parameters. Therefore, you<br>
are passing the values of deformation to all the BSpline grid<br>
nodes, without having first specified how many grid nodes<br>
there are.<br>
<br>
The fix is simple:<br>
Invert the order of the SetFixedParameters and SetParameters calls.<br>
<br>
Like<br>
<br>
bsTransformType::Pointer bsFinalTransform = bsTransformType::New();<br>
// FIXED parameters MUST Be set first.<br>
bsFinalTransform->SetFixedParameters( bsTransform->GetFixedParameters() );<br>
bsFinalTransform->SetParameters(<br>
bsRegistration->GetLastTransformParameters() );<br>
<br>
<br>
With this change, the code runs for me until the end<br>
without throwing exceptions.<br>
<br>
<br>
The lbfgs optimizer is still unhappy though...<br>
<br>
<br>
<br>
Regards,<br>
<br>
<br>
Luis<br>
<br>
<br>
<br>
-------------------------------------------<br>
<div><div></div><div class="h5">On Wed, Oct 7, 2009 at 10:18 AM, Luis Ibanez <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>> wrote:<br>
> Hi Darren,<br>
><br>
> Yes, there are multiple ways of debugging this errror.<br>
><br>
> It would seems that the grid of the BSpline transform<br>
> is not defined, despite the fact that you seem to be<br>
> setting that correctly (from looking at your code.)<br>
><br>
> BTW: thanks for attaching the source code.<br>
><br>
> The first thing to try, would be to add:<br>
><br>
> bsTransform->Print( std::cout );<br>
><br>
> to line 594, just after the call to StartRegistration().<br>
><br>
> This will allow us to see the state of the BSpline transform<br>
> at that point. In particular we are interested in seeing<br>
> the values of the BSpline grid.<br>
><br>
><br>
> Please let us know what you find,<br>
><br>
><br>
> Thanks<br>
><br>
><br>
> Luis<br>
><br>
><br>
> -----------------------------------------------------------------------<br>
> On Tue, Oct 6, 2009 at 6:28 PM, Darren Weber<br>
> <<a href="mailto:darren.weber.lists@gmail.com">darren.weber.lists@gmail.com</a>> wrote:<br>
>><br>
>> Is there an easy way to debug this error?<br>
>><br>
>> vnl_lbfgs: Error. Netlib routine lbfgs failed.<br>
>> terminate called after throwing an instance of 'itk::ExceptionObject'<br>
>> what():<br>
>> /opt/local/include/InsightToolkit-3.16/Common/itkBSplineDeformableTransform.txx:347:<br>
>> itk::ERROR: BSplineDeformableTransform(0x126f390): Mismatched between<br>
>> parameters size 128 and region size 0<br>
>><br>
>><br>
>> See code file attached. Example files are available at<br>
>> <a href="ftp://ftp.buckinstitute.org/dweber/itkRegistrationFiles.tar.gz" target="_blank">ftp://ftp.buckinstitute.org/dweber/itkRegistrationFiles.tar.gz</a><br>
>><br>
>> The src code builds OK and it's called using:<br>
>><br>
>> # Bspline deformation registration: $imgMov TO $imgFix<br>
>> $HOME/bin/itkImageBsplineCoregistration \<br>
>> $imgFixBW $imgMovBW ${imgOutBW}.${imgType} \<br>
>> $imgFixRGB $imgMovRGB ${imgOutRGB}.${imgType} \<br>
>> ${imgOutBW}_DiffBefore.$imgType \<br>
>> ${imgOutBW}_DiffAfter.$imgType > ${imgOutBW}.log<br>
>><br>
>> TIA,<br>
>> Darren<br>
>><br>
>><br>
>> _____________________________________<br>
>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>><br>
>> Visit other Kitware open-source projects at<br>
>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>><br>
>> Please keep messages on-topic and check the ITK FAQ at:<br>
>> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
>><br>
>> Follow this link to subscribe/unsubscribe:<br>
>> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
>><br>
>><br>
><br>
</div></div></blockquote></div><br>