Skip to content

Conversation

@N-Dekker
Copy link
Collaborator

Following ITK pull request InsightSoftwareConsortium/ITK#5680
"BUG: Avoid copying uninitialized pixels in CastImageFilter"
@N-Dekker N-Dekker requested a review from blowekamp December 10, 2025 17:24
Comment on lines +104 to +119
if constexpr (isVariableLengthVector<OutputPixelType>)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
OutputPixelType value(outputIt.Get());
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
}
else
{
OutputPixelType value;
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
outputIt.Set(value);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the VariableLengthVector case just calls outputIt.Get(), whereas the regular Vector/FixedArray case just calls outputIt.Set(value), with this PR!

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

OutputPixelType value(outputIt.Get());
for (unsigned int k = 0; k < componentsPerPixel; ++k)

if constexpr (isVariableLengthVector<OutputPixelType>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐇

@blowekamp
Copy link
Member

Thank you for applying the bug fix here too. I was hoping to see the performance difference with the change, compare to the the original loop. Please merge if you are done with this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants