SpatialObject.IsInsideInWorldSpace(point) much faster now!

:tada: For your information, we have just achieved a significant performance improvement!

With the latest ITK master branch revision (commit PERF: Make `m_ObjectToWorldTransformInverse->TransformPoint` non-virtual 路 InsightSoftwareConsortium/ITK@4ae04b3 路 GitHub) a SpatialObject.IsInsideInWorldSpace(point) call will be much faster than before! I observed that it has become approximately twice as fast, compared to the last ITK release (v5.3.0), or even the latest release candidate (v5.4rc02)

The performance improvement was achieved by three pull requests that I did, which were reviewed by @Stephen_Aylward @dzenanz and @hjmjohnson, and merged in the last few days:

As SpatialObject.IsInsideInWorldSpace(point) is often called repeatedly over a large range of points (typically inside a for or a while loop), I expect a significant performance improvement for various filters, metric calculations, and registration algorithms. Especially when they involve image masks. Specifically, I would expect a performance improvement for:

  • SpatialObjectToImageStatisticsCalculator
  • DiffusionTensor3DReconstructionImageFilter
  • ImageMomentsCalculator
  • HistogramImageToImageMetric
  • ImageToImageMetric
  • KappaStatisticImageToImageMetric
  • MatchCardinalityImageToImageMetric
  • MattesMutualInformationImageToImageMetric
  • MeanReciprocalSquareDifferenceImageToImageMetric
  • MutualInformationImageToImageMetric
  • NormalizedCorrelationImageToImageMetric
  • JointHistogramMutualInformationImageToImageMetricv4
  • MattesMutualInformationImageToImageMetricv4
  • ImageRegistrationMethodv4

Please have a look and try it out! I鈥檓 interested to hear if you see any performance improvement in your use case!


For your information, both spatialObject.IsInsideInWorldSpace(point) and spatialObject.IsInsideInObjectSpace(point) have become even faster for masks (that is, when the spatial object is an itk::ImageMaskSpatialObject), now that the following pull request is merged:

commit: PERF: ImageMaskSpatialObject use image regions from its base class 路 InsightSoftwareConsortium/ITK@671d758 路 GitHub

For ImageMaskSpatialObject::IsInsideInObjectSpace, I observed a performance improvement of more than 8%, with this commit.

1 Like

Thanks for letting us know - I updated ANTs. It does seem to run a bit faster, maybe 5%, with a brain mask and the Mattes metric.


:tada: FYI, the SpatialObject.IsInsideInWorldSpace(point) performance improvements that I presented here are included with the latest ITK tag: v5.4rc03.

1 Like