Conversation
When calling `it.GetIndex()` on each iteration, ITK's `ImageRegionIteratorWithIndex` is much faster than `ImageRegionIterator`. This commit will improve the performance of the "TransformRigidityPenalty" metric. Removed the unnecessary public `RigidityImageIteratorType = ImageRegionIterator` type alias.
When calling `it.GetIndex()` on each iteration, `ImageRegionIteratorWithIndex` is much faster than `ImageRegionIterator`. This yields a performance improvement when using a mask. ComputeImageExtremaFilter is being used during the initialization of metrics.
When calling `it.GetIndex()` on each iteration, ITK's `ImageRegionIteratorWithIndex` is much faster than `ImageRegionIterator`. This commit will improve the performance of the "MultiBSplineTransformWithNormal" transform.
|
Regarding the use of an iterator "With Index" (versus using an iterator without index), proposed for TransformRigidityPenaltyTerm, ComputeImageExtremaFilter, and MultiBSplineDeformableTransformWithNormal, I observed that for (IteratorType it{ image, region }; !it.IsAtEnd(); ++it)
{
const auto& index = it.GetIndex();
result += it.Get() + (index[0] + index[1]) % 8;
}Using VS2026, Release build and ITK v6.0b02, I observed that |
|
To my surprise, when only the index is retrieved, both ImageRegionConstIteratorWithIndex and ImageRegionConstIterator appear faster than ImageRegionIndexRange, on a large 2D image. (ImageRegionConstIteratorWithIndex is then almost 3x as fast as ImageRegionConstIterator, and almost 4x as fast as ImageRegionIndexRange.) 🤔
|
7e6a612 to
fa75a2b
Compare
Iterative retrieval of n-dimensional index values is much faster when using `ImageRegionIteratorWithOnlyIndex` than when using a regular `ImageRegionIterator` (which "computes" the index with each iteration). This commit will improve the performance of the "DistancePreservingRigidityPenalty" metric.
Iterative retrieval of n-dimensional index values is much faster when using `ImageRegionConstIteratorWithOnlyIndex` than when using a regular `ImageRegionConstIterator` (which "computes" the index with each iteration). This commit will improve the performance of the "BSplineTransformWithDiffusion" transform. Removed the nested `DummyIteratorType` typedef, that is no longer used by now.
fa75a2b to
fec8631
Compare
ImageConstIterator::GetIndex()is relatively expensive, as it computes the index with each call, by doingm_Image->ComputeIndex(m_Offset)internally.This pull request avoids calling
ImageConstIterator::GetIndex(), either by using an iterator "with index" (for exampleImageRegionIteratorWithIndex), or by using an iterator "with only index" (ImageRegionConstIteratorWithOnlyIndex), instead.Doing so should improve the performance of initialization of metrics. Moreover, it specifically improves the performance of the "DistancePreservingRigidityPenalty" and the "TransformRigidityPenalty" metric. It also improves the performance of the "BSplineTransformWithDiffusion" and the "MultiBSplineTransformWithNormal" transform.
See also:
ComputeIndex()member function to ImageConstIterator InsightSoftwareConsortium/ITK#5787ImageConstIterator::ComputeIndex(), a clearer alternative to GetIndex()