[Insight-developers] OptBSplineInterpolateImageFunction
Stefan Klein
s.klein at erasmusmc.nl
Thu Aug 27 11:06:17 EDT 2009
Hi,
I wrote an alternative to the itkOptBSplineInterpolateImageFunction,
which is nearly as fast, but requires less code and is easier to use (in
my opinion).
The OptBSplineInterpolateImageFunction adds methods that take the
threadId as argument. For example ::EvaluateAtIndex( index, threadId).
This allows some dynamic memory allocations to be avoided and gives a
great speedup.
An alternative way of avoiding the memory allocations is to declare a
C-array (of fixed size, so allocated on the stack) within the
EvaluateAtIndex method, and use the vnl_matrix_ref class to instantiate
a matrix that uses the statically allocated memory (instead of
allocating memory on the heap).
1 million calls to EvaluateAtIndex give the following result:
The elapsed time for old way: 2953ms
The elapsed time for fast way: 2219ms
The elapsed time for opt way: 2110ms
old = non-optimized itkBSplineInterpolateImageFunction
fast = my proposed implementation
opt = the itkOptBSplineInterpolateImageFunction.
(tested on Windows XP, using Visual C++ 2008 release mode, 3rd order
Bspline, 3d 100x100x100 image, ITK 3.14)
In the attachment you can find the test program and the classes. My
proposed implementation is the itkBSplineInterpolateImageFunctionFast.h.
I renamed the Opt-classes in the testing code, to make it easier to
compare them, but I didn't change the functional code.
The opt version is a bit faster, but requires more lines of code (and
requires changes to all code that uses it, in order to benefit from the
fast implementation). For the EvaluateDerivativeAtIndex method the
timing results are similar. All interpolated values are identical in the
three implementations (old,fast,opt).
What do you think about it?
Kind regards,
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interpoltest.zip
Type: application/x-zip-compressed
Size: 26871 bytes
Desc: not available
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20090827/1c356ff7/attachment.bin>
More information about the Insight-developers
mailing list