<html>
<body>
<font size=3>Hi,<br><br>
In addition to my previous mail: in the BSplineInterpolateImageFunction
the startIndex is computed differently than in the
BSplineInterpolationWeightFunction.<br><br>
Method: DetermineRegionOfSupport<br><br>
The following code does the work:<br><br>
<br>
&nbsp; long indx;<br><br>
// compute the interpolation indexes <br>
&nbsp; for (unsigned int n = 0; n&lt; ImageDimension; n++)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; if (splineOrder &amp; 1)&nbsp;&nbsp;&nbsp;&nbsp; //
Use this index calculation for odd splineOrder<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; indx = (long)vcl_floor((float)x[n]) -
splineOrder / 2;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (unsigned int k = 0; k &lt;=
splineOrder; k++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evaluateIndex[n][k] =
indx++;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;
else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// Use this index calculation for even splineOrder<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; indx = (long)vcl_floor((float)(x[n] +
0.5)) - splineOrder / 2;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (unsigned int k = 0; k &lt;=
splineOrder; k++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evaluateIndex[n][k] =
indx++;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br><br>
<br>
I think this behaves exactly like the solution I proposed in my previous
mail, but distinguishes between the cases of odd and even spline order
(so might be slightly less efficient?; especially since the function is
often invoked many times).<br><br>
Let me know what you think about it.<br><br>
Regards!<br>
Stefan.<br><br>
<br><br>
At 15:01 12/10/06, Stefan Klein wrote:<br>
<blockquote type=cite class=cite cite>Hi,<br><br>
I think i found a bug in the implementation of the
BSplineInterpolationWeightFunction.<br><br>
In the Evaluate function, at lines 146-151, the startIndex of the support
region is computed, given a continuous input index (denoted by
'index'):<br><br>
&nbsp; // Find the starting index of the support region<br>
&nbsp; for ( j = 0; j &lt; SpaceDimension; j++ )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; startIndex[j] = static_cast&lt;typename
IndexType::IndexValueType&gt;(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BSplineFloor( index[j] -
static_cast&lt;double&gt;( SplineOrder / 2 ) ) );<br>
&nbsp;&nbsp;&nbsp; }<br><br>
<br>
If I understand well, for a zero order bspline, this formula should
result in a 'round' operation. This is not the case with the formula
above:<br><br>
suppose the continuous input index = 0.9 and the SplineOrder = 0.<br>
then:<br><br>
startindex = floor( 0.9 - 0/2 ) = floor (0.9) = 0.<br><br>
Consequently, in line 161, where the bsplinekernel weight is evaluated,
the result is zero.<br>
BsplineZeroOrder( inputindex - startindex ) = BSplineZeroOrder( 0.9 ) =
0.0.<br>
Which must be wrong, since for a zeroth order bspline the weight value
should be nonzero everywhere in its support region.<br><br>
For splineorder=1 the formula works. For splineorder=2 it goes wrong
again and for splineorder=3 it works. So, it's wrong for even spline
orders.<br><br>
I suggest changing it to:<br><br>
&nbsp;&nbsp;&nbsp;&nbsp; startIndex = floor( inputIndex + bsplineoffset
)<br><br>
&nbsp;where<br><br>
&nbsp;&nbsp;&nbsp; bsplineOffset =&nbsp; 0.5 -
static_cast&lt;double&gt;(SplineOrder) / 2.0 ;<br><br>
which results in bsplineOffset = 1/2, 0, -1/2, or -1 respectively for
order 0, 1, 2, and 3.<br><br>
In the case of zero order bspline this obviously gives the desired round
operation (floor(input+0.5)).<br>
In general: for odd spline orders it works the same as the current
formula, but for even orders the result is different.<br><br>
Please let me know if I made a mistake, or if it's really a 
bug.<br><br>
Kind regards,<br>
Stefan.<br><br>
_______________________________________________<br>
Insight-users mailing list<br>
Insight-users@itk.org<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" eudora="autourl">http://www.itk.org/mailman/listinfo/insight-users</a></font></blockquote></body>
<br>
</html>