<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hello Anton,<br>
<br>
Yes, likely you are correct. Right now your code initializes using the identity transform and as far as I remember your B-spline grid doesn't physically overlap with your images (maybe it does, but this would be by chance).<br>
What is a bit surprising is that you did not get an error with regard to too many samples outside the domain (indicating no overlap between images - so I am a bit puzzled as it means your images do overlap sufficiently).
<br>
<br>
This scenario is rare in practice and usually only happens when you are registering temporal data such as 3D volumes from a 4D CT dataset. Please see the following Jupyter Python notebook for an example on setting things up
<a href="https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/65_Registration_FFD.ipynb" target="_blank">
https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/65_Registration_FFD.ipynb</a> . It will be easy for you to
<font size="2">translate it to C#. <br>
<br>
</font><br>
<font size="2"><span dir="ltr"><font face="Arial,sans-serif" size="3"><span style="font-size:12pt;"><font face="Tahoma" size="2">You will also likely need to initialize your registration by performing a registration using a global transformation (rigid/affine)
and only then a local registration (FFD).<br>
<br>
</font></span></font></span>One last thing, there is a bug in the code in the line:</font><span dir="ltr"><font face="Arial,sans-serif" size="3"><span style="font-size:12pt;"><font size="2"> R.SetMetricSamplingPercentage(30.0);<br>
<font face="Tahoma"><br>
This is a 300% sampling. The expected values are in (0.0,1.0].</font></font><br>
<font face="Tahoma" size="2"><br>
<br>
hope this helps<br>
Ziv</font><br>
</span></font></span><br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF293354"><font color="#000000" face="Tahoma" size="2"><b>From:</b> Anton Delehony [anton.delehony@gmail.com]<br>
<b>Sent:</b> Monday, July 18, 2016 5:06 PM<br>
<b>To:</b> insight-users@itk.org<br>
<b>Subject:</b> [ITK-users] simpleITK C# bspline registation<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif">Hi all,</span><span style="font-size:12pt; font-family:"Times New Roman",serif"></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif">I noticed that the output of my registration is exactly as the moving image, which means that the code below is not correct, but not sure where is
the mistake. I think it has to do with the transform initializer....</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif">Thanks,</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif">AD</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> // Read input static</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.ImageFileReader reader1 = new itk.simple.ImageFileReader();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> reader1.SetFileName(args[0]);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> Image static = reader1.Execute();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> // Read input moving</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.ImageFileReader reader2 = new itk.simple.ImageFileReader();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> reader2.SetFileName(args[0]);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> Image moving = reader2.Execute();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> //registation </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.ImageRegistrationMethod R = new itk.simple.ImageRegistrationMethod();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> R.SetMetricAsMattesMutualInformation(50); </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> R.SetMetricSamplingPercentage(30.0);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> R.SetInterpolator(itk.simple.InterpolatorEnum.sitkLinear);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> R.SetOptimizerAsLBFGSB();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.BSplineTransform transform = new itk.simple.BSplineTransform(3);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> R.SetInitialTransform( transform);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.Transform trans_f = R.Execute(static, moving);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> //resample image</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.ResampleImageFilter resample = new itk.simple.ResampleImageFilter();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> resample.SetReferenceImage(static);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> resample.SetTransform(trans_f);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> resample.SetInterpolator(itk.simple.InterpolatorEnum.sitkBSpline);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt"><span style="font-size:12pt; font-family:Arial,sans-serif"> itk.simple.Image registered = resample.Execute(moving);</span></p>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
</div>
</body>
</html>