<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Nick,<br>
      <br>
      I have noticed that the error is not thrown if I do not set the
      initial transform for the moving image via
      registrationMethod-&gt;SetMovingInitialTransform (although the
      optimizer then produces a constant error value and the
      registration simply iterates without altering the deformation
      field - I don't know if this is an unrelated problem).<br>
      <br>
      My setup is simple, i.e. no multi-resolution involved. I'm doing
      essentially this:<br>
      <br>
      typedef itk::BSplineTransform&lt; PixelType, ImageDimension &gt;
      TransformType;<br>
      typedef itk::MeanSquaresImageToImageMetricv4&lt; ImageType,
      ImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp; MetricType;<br>
      typedef itk::GradientDescentOptimizerv4 OptimizerType;<br>
      typedef itk::ImageRegistrationMethodv4&lt; ImageType, ImageType,
      TransformType &gt; RegistrationMethodType;<br>
      typedef itk::RegistrationParameterScalesFromPhysicalShift&lt;
      MetricType &gt; ScalesEstimatorType;<br>
      <br>
      MetricType::Pointer metric = MetricType::New();<br>
      <br>
      OptimizerType::Pointer optimizer = OptimizerType::New();<br>
      optimizer-&gt;SetNumberOfIterations( 200 );<br>
      optimizer-&gt;SetDoEstimateLearningRateOnce( true );<br>
      optimizer-&gt;SetMinimumConvergenceValue( 1e-16 );<br>
      optimizer-&gt;SetConvergenceWindowSize( 20 );<br>
      optimizer-&gt;SetMaximumStepSizeInPhysicalUnits( 2 );<br>
      <br>
      ScalesEstimatorType::Pointer scalesEstimator =
      ScalesEstimatorType::New();<br>
      scalesEstimator-&gt;SetMetric( metric );<br>
      scalesEstimator-&gt;SetTransformForward( true );<br>
      optimizer-&gt;SetScalesEstimator( scalesEstimator );<br>
      optimizer-&gt;SetDoEstimateScales( true );<br>
      <br>
      RegistrationMethodType::Pointer registrationMethod =
      RegistrationMethodType::New();<br>
      registrationMethod-&gt;SetOptimizer( optimizer );<br>
      registrationMethod-&gt;SetFixedImage( fixedImage );<br>
      registrationMethod-&gt;SetMovingImage( movingImage );<br>
      registrationMethod-&gt;SetFixedInitialTransform(
      initialFixedTransform );<br>
      registrationMethod-&gt;SetMovingInitialTransform(
      initialMovingTransform );<br>
      registrationMethod-&gt;SetNumberOfLevels( 1 );<br>
      registrationMethod-&gt;SetMetric( metric );<br>
      registrationMethod-&gt;SetMetricSamplingStrategy(
      RegistrationMethodType::NONE );<br>
      <br>
      <br>
      <br>
      <br>
      The initial transforms are initialized like this:<br>
      <br>
      TransformType::PhysicalDimensionsType fixedPhysicalDimensions;<br>
      TransformType::MeshSizeType meshSize;<br>
      for( unsigned int i=0; i &lt; ImageDimension; i++ )<br>
      {<br>
      &nbsp; fixedPhysicalDimensions[i] = fixedImage-&gt;GetSpacing()[i] *<br>
      &nbsp; static_cast&lt;double&gt;(<br>
      &nbsp;&nbsp;&nbsp; movingImage-&gt;GetLargestPossibleRegion().GetSize()[i] - 1 );<br>
      }<br>
      unsigned int SplineOrder = 3;<br>
      unsigned int numberOfGridNodesInOneDimension = 5;<br>
      meshSize.Fill( numberOfGridNodesInOneDimension - SplineOrder );<br>
      initialMovingTransform-&gt;SetTransformDomainOrigin(
      movingImage-&gt;GetOrigin() );<br>
      initialMovingTransform-&gt;SetTransformDomainPhysicalDimensions(
      fixedPhysicalDimensions );<br>
      initialMovingTransform-&gt;SetTransformDomainMeshSize( meshSize );<br>
      initialMovingTransform-&gt;SetTransformDomainDirection(
      movingImage-&gt;GetDirection() );<br>
      TransformType::ParametersType initialMovingParameters(
      initialMovingTransform-&gt;GetNumberOfParameters() );<br>
      initialMovingParameters.Fill(0.0);<br>
      initialMovingTransform-&gt;SetParameters(initialMovingParameters);<br>
      <br>
      <br>
      Thanks for the link to the relevant ANTs class. I took a look at
      the relevant lines but it didn't help me either.<br>
      <br>
      Many thanks,<br>
      Frank<br>
      <br>
      <br>
      <br>
      <br>
      <br>
      On 07/31/2013 01:21 PM, Nick Tustison wrote:<br>
    </div>
    <blockquote
      cite="mid:A17F6726-D128-435D-B37A-1F6A4D831A7D@gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      Hi Frank,
      <div><br>
      </div>
      <div>I'm cc'ing the insight users list as others might be
        interested. &nbsp;</div>
      <div><br>
      </div>
      <div>How are you setting&nbsp;up the registration? In case you were
        interested, we have&nbsp;</div>
      <div>a pretty comprehensive application&nbsp;which ties in all the new
        registration stuff&nbsp;</div>
      <div>in a single application. In it, we set up&nbsp;the B-spline
        transform which you can&nbsp;</div>
      <div>view at</div>
      <div><br>
      </div>
      <div><a moz-do-not-send="true"
href="https://github.com/stnava/ANTs/blob/master/Examples/itkantsRegistrationHelper.hxx">https://github.com/stnava/ANTs/blob/master/Examples/itkantsRegistrationHelper.hxx</a></div>
      <div><br>
      </div>
      <div>starting at line 1896.</div>
      <div><br>
      </div>
      <div>Nick</div>
      <div><br>
        <div>
          <div>
            <div>On Jul 31, 2013, at 4:45 AM, Frank Preiswerk &lt;<a
                moz-do-not-send="true"
                href="mailto:frank.preiswerk@unibas.ch">frank.preiswerk@unibas.ch</a>&gt;
              wrote:</div>
            <br class="Apple-interchange-newline">
            <blockquote type="cite">
              <div bgcolor="#FFFFFF" text="#000000">
                <div class="moz-cite-prefix">Hi Nick,<br>
                  <br>
                  I have adapted my code to work with the new ITKv4
                  classes. For the affine registration this worked well.
                  But for the BSplineTransform, I get the following
                  error during optimization:<br>
                  <br>
                  <meta name="qrichtext" content="1">
                  <div style="margin: 0px; text-indent: 0px; "><!--StartFragment--><span
                      style=" font-family:'Monospace'; font-size:9pt;
                      color:#b20808;">/usr/local/include/ITK-4.4/itkImageToImageMetricv4GetValueAndDerivativeThreaderBase.hxx:258:</span></div>
                  <div style="margin: 0px; text-indent: 0px; "><span
                      style=" font-family:'Monospace'; font-size:9pt;
                      color:#b20808;">Exception in
                      GetValueAndDerivativeProcessPoint:</span></div>
                  <div style="margin: 0px; text-indent: 0px; "><span
                      style=" font-family:'Monospace'; font-size:9pt;
                      color:#b20808;">/usr/local/include/ITK-4.4/itkBSplineBaseTransform.h:282:</span></div>
                  <div style="margin: 0px; text-indent: 0px; "><span
                      style=" font-family:'Monospace'; font-size:9pt;
                      color:#b20808;">itk::ERROR:
                      BSplineTransform(0x384cb00):
                      ComputeJacobianWithRespectToPosition not yet
                      implemented for BSplineTransform<br>
                    </span></div>
                  <div style="margin: 0px; text-indent: 0px; "><span
                      style=" font-family:'Monospace'; font-size:9pt;
                      color:#b20808;"><br>
                    </span><!--EndFragment--></div>
                  <style type="text/css">
p, li { white-space: pre-wrap; }
</style>I use GradientDescentOptimizerv4 and
                  MeanSquaresImageToImageMetricv4 and also tried
                  substituting them with QuasiNewtonOptimizerv4 and
                  MattesMutualInformationImageToImageMetricv4 but to no
                  avail.<br>
                  <br>
                  Sorry to bother you but I could not find any examples
                  on the web that shows how the BSplineTransform can be
                  used in the new framework.<br>
                  <br>
                  Many thanks!<br>
                  Frank<br>
                  <br>
                  <br>
                  <br>
                  <br>
                  On 07/30/2013 04:09 PM, Nick Tustison wrote:<br>
                </div>
                <blockquote
                  cite="mid:926583E4-B993-45F2-B82D-4C7D27D5DBD3@gmail.com"
                  type="cite">
                  <pre wrap="">Hi Frank,

I don't think that anybody on the registration team has tried to use the composite
transform with the old registration framework.  I'm not even sure that it would work 
as both the optimization and metrics are completely separate between ITKv3 and
ITKv4.  In suggesting the use of the CompositeTransform class, I didn't catch that
you were sticking with ITKv3.  Sorry about that.  

There was some earlier work by Torsten and Marius &amp; Stefan who gave us some
ideas for the current composite transform.  Perhaps one of those contributions would
fit your needs.

<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.insight-journal.org/browse/publication/143">http://www.insight-journal.org/browse/publication/143</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.insight-journal.org/browse/publication/91">http://www.insight-journal.org/browse/publication/91</a>

Also, I would be remiss if I didn't at least proselyte concerning the utility of the new 
registration framework.  There's quite a few advantages in addition to the composite
transform:

<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.itk.org/Wiki/ITK/Release_4/Why_Switch_to_ITKv4#New_Registration_Framework">http://www.itk.org/Wiki/ITK/Release_4/Why_Switch_to_ITKv4#New_Registration_Framework</a>

Nick


On Jul 30, 2013, at 7:35 AM, Frank Preiswerk <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:frank.preiswerk@unibas.ch">&lt;frank.preiswerk@unibas.ch&gt;</a> wrote:

</pre>
                  <blockquote type="cite">
                    <pre wrap="">Hi Nick,

I have a few additional questions and I would be very glad if you could help me getting on the right track.

Your suggestion to use the CompositeTransform guided me to the new registration framework. I have played around a bit and now I'm unsure which version to use.

First of all, in ImageRegistrationMethodv4 there is a method SetMovingInitialTransform that probably does exactly what I need. As far as I understand it, one can achieve the same with the old framework by using CompositeTransform like this:

compositeTransform-&gt;AddTransform(affineTransform); // the output from the prior affine step
compositeTransform-&gt;AddTransform(bsplineTransform);
compositeTransform-&gt;SetOnlyMostRecentTransformToOptimizeOn(); // activate the bspline transform for the next optimization
registration-&gt;SetTransform( compositeTransform );

Is this the way how to properly use CompositeTransform in the old registration framework? And is my assumption correct that SetMovingInitialTransform would be sufficient when using the new framework?

Thanks a lot for your efforts,
Frank



On 07/29/2013 12:16 PM, Nick Tustison wrote:
</pre>
                    <blockquote type="cite">
                      <pre wrap="">You should try using the composite transform

<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.itk.org/Doxygen/html/classitk_1_1CompositeTransform.html">http://www.itk.org/Doxygen/html/classitk_1_1CompositeTransform.html</a>

Nick

On Jul 29, 2013, at 4:49 AM, Frank Preiswerk <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:frank.preiswerk@unibas.ch">&lt;frank.preiswerk@unibas.ch&gt;</a> wrote:

</pre>
                      <blockquote type="cite">
                        <pre wrap="">Hi all,

I'm writing a program that performs image registration by first computing an
affine transformation followed by a bspline deformation. The bspline
registration should be initialized with the output of the affine
registration.

I'm using ITK 4.4. The example DeformableRegistration15.cxx intends to do
the above but it seems that the BSplineTransform is actually not initialized
with the output of the affine step, as already reported earlier:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.itk.org/pipermail/insight-users/2012-May/044623.html">http://www.itk.org/pipermail/insight-users/2012-May/044623.html</a>

ITK 3's BSplineDeformableTransform had a method SetBulkTransform to concat
the bspline transform with another transform, but in ITK 4's
BSplineTransform this method was removed. So the question remains how to
properly initialize a BSplineTransform with an affine (or any other)
registration output.

Computing the parameters of the bspline transform by applying the affine
transform to the grid nodes is an option. But something like
SetBulkTransform would be much more convenient.

I'm thankful for any hints.

Regards,
Frank







--
View this message in context: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://itk-insight-users.2283740.n2.nabble.com/Initializing-a-BSplineTransform-in-ITK-4-4-tp7583607.html">http://itk-insight-users.2283740.n2.nabble.com/Initializing-a-BSplineTransform-in-ITK-4-4-tp7583607.html</a>
Sent from the ITK Insight Users mailing list archive at <a moz-do-not-send="true" href="http://Nabble.com">Nabble.com</a>.
_____________________________________
Powered by <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.kitware.com/">www.kitware.com</a>

Visit other Kitware open-source projects at
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>

Kitware offers ITK Training Courses, for more information visit:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.kitware.com/products/protraining.php">http://www.kitware.com/products/protraining.php</a>

Please keep messages on-topic and check the ITK FAQ at:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/ITK_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a>
</pre>
                      </blockquote>
                    </blockquote>
                    <pre wrap="">-- 
Frank Preiswerk, Senior Researcher
Medical Image Analysis Center (MIAC)
University of Basel c/o University Hospital Basel
Spitalstrasse 21
CH-4031 Basel
Switzerland

Tel: +41 61 265 96 58
Fax: +41 61 265 96 68
Office:Schanzenstrasse 46, Room 321

</pre>
                  </blockquote>
                </blockquote>
                <br>
                <br>
                <pre class="moz-signature" cols="72">-- 
Frank Preiswerk, Senior Researcher
Medical Image Analysis Center (MIAC)
University of Basel c/o University Hospital Basel
Spitalstrasse 21
CH-4031 Basel
Switzerland

Tel: +41 61 265 96 58
Fax: +41 61 265 96 68
Office:Schanzenstrasse 46, Room 321</pre>
              </div>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Frank Preiswerk, Senior Researcher
Medical Image Analysis Center (MIAC)
University of Basel c/o University Hospital Basel
Spitalstrasse 21
CH-4031 Basel
Switzerland

Tel: +41 61 265 96 58
Fax: +41 61 265 96 68
Office:Schanzenstrasse 46, Room 321</pre>
  </body>
</html>