-
-
Notifications
You must be signed in to change notification settings - Fork 691
PERF: Use region iterator image ComposeBigVectorImageFilter #5306
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PERF: Use region iterator image ComposeBigVectorImageFilter #5306
Conversation
This test is timing out on nightly valgrind and coverage builds. These changes may reduce the number of temporaries heap allocations used, and improve performance. Local test in debug mode, improve performance by more than 10%.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @blowekamp 💯
itk::ImageRegionConstIterator<VectorImageType> it(img, sliceRegion); | ||
for (it.GoToBegin(); !it.IsAtEnd(); ++it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blowekamp Cool. 👍 Some small suggestions...
it.GoToBegin()
is not necessary. An ImageRegionConstIterator
always starts at the begin. So these two lines could be replaced with one:
for (itk::ImageRegionConstIterator<VectorImageType> it(img, sliceRegion); !it.IsAtEnd(); ++it)
if (it.Get()[i] != i % 250) | ||
{ | ||
itk::Index<3> idx = { { x, y, z } }; | ||
|
||
auto pixel = img->GetPixel(idx); | ||
if (pixel[i] != i % 250) | ||
{ | ||
++values[pixel[i]]; | ||
} | ||
++values[it.Get()[i]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, I would avoid calling it.Get()[i]
twice. Instead, would it also work as follows?
if (const auto channelValue = it.Get()[i]; channelValue != i % 250)
{
++values[channelValue];
}
for (unsigned int i = 0; i < nchannels; ++i) | ||
{ | ||
itk::IndexValueType z = i; | ||
std::map<unsigned int, unsigned int> values; | ||
|
||
for (itk::IndexValueType y = 0; y < size; ++y) | ||
sliceRegion.SetIndex(2, z); // Set the index of the z-dimension to the current slice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If z
should always just have the same value as i
(the current channel number), I would suggest removing the variable z
, and using i
directly:
sliceRegion.SetIndex(2, i);
This test is timing out on nightly valgrind and coverage builds.
These changes may reduce the number of temporaries heap allocations used, and improve performance. Local test in debug mode, improve performance by more than 10%.
PR Checklist
Refer to the ITK Software Guide for
further development details if necessary.