Potential acceleration for registration with BSplineTransform in metric derivative calculation

Hi All,
I believe I’ve identified a potential computational bottleneck when computing registrations involving BSplineTransforms, specifically during derivative calculation in the v3 registration metrics (might also be applicable to the v4 metrics too). For the v3 metrics I’ve looked at, the metric object calls the generic transform method ComputeJacobianWithRespectToParameters to obtain a Jacobian at the corresponding physical point. Every element of this Jacobian is used to calculate derivatives at the physical point, however, most of the Jacobian elements are 0 for the BSplineTransform.
When weights caching is used, the cached indexes “point to” all the non-zero Jacobian elements, and the value of these elements equals the cached weight at the corresponding index. In this case, the cached indexes and weights at the corresponding point’s can be directly substituted into the derivative calculation instead of the Jacobian assigned through the ComputeJacobian method. This avoids recalculation of the weights by the BSplineTransform in it’s ComputeJacobian methods and omits unnecessary calculation of derivatives with zero-element Jacobians. Anecdotally, implementing weights caching for derivative calculation has drastically reduced 2D-3D registration time for me (by a factor of 5-150 times - dependent on the number of parameters). I’m not sure whether derivative calculation with weights-caching has been implemented in the v4 metrics (or if I’ve missed it in the v3 metrics), but I thought it worthwhile to share.
Cheers, Levi.

2 Likes

@hjmjohnson @blowekamp @Niels_Dekker BSplines are indeed frequently used in registration. Does anyone have time to look into this suggestion?

@dzenanz I do not have time to investigate this directly.

@ljm898 Levi, it sounds like you have an implementation of the performance improvement. Could you make a pull request with your changes?

1 Like

Happy to do so, I’ll see which metrics the proposed changes are applicable to and try implementing them there.

Pull request made: PERF: Adding weights caching derivative calculation to iktMeanSquaresImageToImageMetric by ljm898 · Pull Request #4982 · InsightSoftwareConsortium/ITK · GitHub. Starting with MeanSquaresImageToImageMetric (v3) as it’s simple - verified that it works for example: Global Registration of Two Images (BSpline) — v5.4.0. When all checks/tests pass review, will progress through the other metrics.

1 Like