Hi Davoud<br><br>With this Transform, you should use an optimizer that <br>doesn't require the computation of Metric derivatives.<br><br>Typical options are:<br><br>* OnePlusOneEvolutionaryOptimizer<br>* AmoebaOptimizer<br>
<br><br> Regards,<br><br><br> Luis<br><br><br>--------------------------------<br><div class="gmail_quote">On Wed, Sep 22, 2010 at 10:29 AM, Dav <span dir="ltr"><<a href="mailto:davoud_zzz@yahoo.com">davoud_zzz@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">
Greetings dear members,<div>I am trying to register pair of CT images using the Thin-Plate Spline (TPS) transform and the following source code is the section related to TPS registration:</div><div><br></div><div>**********************************************************************************************************</div>
<div><p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New"; color: blue;">const</span><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">unsigned</span> <span style="color: blue;">int</span><span>
</span>Dimension = 2;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span><span> </span><span style="color: blue;">short</span><span> </span>PixelType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::Image< PixelType, Dimension ><span>
</span>FixedImageType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::Image< PixelType, Dimension ><span>
</span>MovingImageType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span> <span style="color: blue;">double</span> CoordinateRepType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::ThinPlateSplineKernelTransform< CoordinateRepType, Dimension>
TransformType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::ImageRegistrationMethod< FixedImageType, MovingImageType > RegistrationType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span><span> </span>itk::Point< CoordinateRepType, Dimension
><span> </span>PointType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span><span> </span>TransformType::PointSetType<span> </span>PointSetType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span><span> </span>PointSetType::Pointer<span> </span>PointSetPointer;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span><span> </span>PointSetType::PointIdentifier<span> </span>PointIdType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::RegularStepGradientDescentOptimizer<span>
</span>OptimizerType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::MutualInformationImageToImageMetric< FixedImageType, MovingImageType
><span> </span>MetricType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span> itk::
LinearInterpolateImageFunction< MovingImageType, <span style="color: blue;">double</span>><span> </span>InterpolatorType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>OptimizerType::Pointer<span> </span>optimizer<span> </span>= OptimizerType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>InterpolatorType::Pointer<span> </span>interpolator<span>
</span>= InterpolatorType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>RegistrationType::Pointer<span> </span>registration<span>
</span>= RegistrationType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>MetricType::Pointer<span> </span><span> </span>metric<span>
</span>= MetricType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: green;">//------------------------------------------------------------------------------------------------------//</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointSetType::Pointer sourceLandMarks =
PointSetType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointSetType::Pointer targetLandMarks = PointSetType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointType p1;<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointType p2;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointSetType::PointsContainer::Pointer
sourceLandMarkContainer = sourceLandMarks->GetPoints();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointSetType::PointsContainer::Pointer
targetLandMarkContainer = targetLandMarks->GetPoints();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>PointIdType id = itk::NumericTraits<
PointIdType >::Zero;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: green;">// Read in the list
of landmarks</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>std::ifstream infile;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>infile.open( argv[1] );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">while</span>
(!infile.eof())</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>infile >><span> </span>p1[0] >> p1[1] >> p2[0] >>
p2[1]; </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>sourceLandMarkContainer->InsertElement(
id, p1 );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>targetLandMarkContainer->InsertElement(
id++, p2 );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>} </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>infile.close();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>TransformType::Pointer tps =
TransformType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>tps->SetSourceLandmarks(sourceLandMarks);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>tps->SetTargetLandmarks(targetLandMarks);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>tps->ComputeWMatrix();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: green;">//-------------------------------------------------------------------------------------------------------//</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetOptimizer(<span> </span>optimizer<span> </span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetTransform(<span> </span>tps<span>
</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetInterpolator(<span> </span>interpolator<span>
</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetMetric(<span> </span>metric<span> </span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::ImageFileReader< FixedImageType<span>
</span>> FixedImageReaderType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
itk::ImageFileReader< MovingImageType > MovingImageReaderType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>FixedImageReaderType::Pointer<span> </span>fixedImageReader<span> </span>= FixedImageReaderType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>MovingImageReaderType::Pointer
movingImageReader = MovingImageReaderType::New();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>fixedImageReader->SetFileName(<span> </span>argv[2] );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>movingImageReader->SetFileName( argv[3] );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetFixedImage( <span> </span>fixedImageReader->GetOutput()<span> </span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetMovingImage(<span> </span>movingImageReader->GetOutput()<span> </span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>fixedImageReader->Update();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->SetFixedImageRegion(
fixedImageReader->GetOutput()->GetBufferedRegion() );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">typedef</span>
RegistrationType::ParametersType ParametersType;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>ParametersType initialParameters(
tps->GetNumberOfParameters() );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>initialParameters = tps->GetParameters();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>std::cout << <span style="color: rgb(163, 21, 21);">"
TPS Parameters = "</span> << tps->GetParameters() <<
std::endl;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>std::cout << <span style="color: rgb(163, 21, 21);">"
TPS Parameters = "</span> << initialParameters << std::endl;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span>
</span>registration->SetInitialTransformParameters( initialParameters );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>optimizer->SetNumberOfIterations( 200 );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>optimizer->SetRelaxationFactor( 0.9 );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">try</span> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>{ </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>registration->StartRegistration(); </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>std::cout << <span style="color: rgb(163, 21, 21);">"Optimizer
stop condition: "</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><<
registration->GetOptimizer()->GetStopConditionDescription()</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><< std::endl;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>} </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">catch</span>(
itk::ExceptionObject & err ) </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>{ </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>std::cout << <span style="color: rgb(163, 21, 21);">"ExceptionObject
caught !"</span> << std::endl; </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span>std::cout << err << std::endl; </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: "Courier New";"><span> </span><span style="color: blue;">return</span>
EXIT_FAILURE;</span></p>
<div><span style="font-family: 'Courier New';"><span> </span>}</span></div><div>*********************************************************************************************************</div><div><br></div><div>
<span style="font-family: 'Courier New';"></span>This code is suppose to register two CT images with predefined landmarks which are the TPS transformation parameters. The code compiles just fine however in time of execution I get the following error: </div>
<div>*********************************************************************************************************</div><div><p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">Location: "const class itk::Array2D<double>
&__thiscall itk::KernelTransform<double,2>::GetJacobian(const class
itk::Point<double,2> &) const" </span></p>
<p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">File: e:\research programs\[][ir] itk\insighttoolkit-3.18.0\code\common\itkKernelTransform.txx</span></p>
<p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">Line: 455</span></p>
<p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">Description: itk::ERROR: ThinPlateSplineKernelTransform(01571248):
GetJacobian must be implemented in subclasses of KernelTransform.</span></p><p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">***************************************************************************</span></p>
<p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">The used landmark file is similar to what have been used for the ThinPlateSplineWarp example in the ITK framework and I don't think that is the cause of error. My guess is that the parameters initialization of the registration method is not configured properly but I don't know how to correct that. I would appreciate any help to solve this issue.</span></p>
<p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">Best regards,</span></p><p class="MsoNormal"><span style="font-family: "Times New Roman","serif";">Davoud.</span></p>
<p class="MsoNormal"><span style="font-family: "Times New Roman","serif";"><br></span></p><p class="MsoNormal"><span style="font-family: "Times New Roman","serif";"><br></span></p></div>
</div></td></tr></tbody></table><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>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.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></blockquote></div><br>