Itk: Filter inputs are released despite : DataObject::SetGlobalReleaseDataFlag() set to false

Created on 28 Sep 2020  路  4Comments  路  Source: InsightSoftwareConsortium/ITK

Since I am not a registered itk developer I give the fix that worked for me here

Description

The filters that rely on DataObject class, eg. itk::MaskImageFilter corrupt the input image (clears it) despite that both global and filter relative setting to release data is set to false. The error was traced and the bug found here:

Code error in the \Modules\Core\Commonsrc\itkDataObject.cxx . The function :

bool
DataObject ::ShouldIReleaseData() const
{
  return (m_GlobalReleaseDataFlag || m_ReleaseDataFlag);
}

contais a bug. The m_GlobalReleaseDataFlag is a pointer and not the actual globalreleasedataflag value.

This corection solves it for me:

bool
DataObject ::ShouldIReleaseData() const
{
  return (GetGlobalReleaseDataFlag() || m_ReleaseDataFlag);
}

Steps to Reproduce

call: itk::DataObject::SetGlobalReleaseDataFlag(false);
Create a 3D image of 16bit values, sized 512x98x512. Fill it with zeros.
Create a 3D binary image to represent a mask. Fill it with zeros.

Apply the itk::MaskImageFilter with all default params, passing in the original image and the mask image.

Expected behavior

Mask filter output is ok, the input image is preserved unchanged.

Actual behavior

The output is produced ok but the original input image is empty!
It should not be cleared, but kept untouched.

Reproducibility

Always and also for other filters that I use

Versions

Official ITK 5.1.0 and ITK 5.1.1 releases

Environment

OS win10 64bit, cmake 3.18.1, Visual studio 2019, no python usage

Bug

Most helpful comment

Pull request process is unclear to me after reading the instructions. Not my intention to go any deeper.
My intention was to pass the info on this bug so that it can hopefully be fixed in future itk releases.
Thank you.

All 4 comments

You don't have to be a maintainer to submit a patch. Do you mind turning this into a pull request?

Good catch! I understand how someone made this error and I think the variable name is not appropriate, maybe you can rename it? m_GlobalReleaseDataFlagPointer? There is at least one other location where it should be changed, maybe you'll catch other errors when renaming.

I reviewed the originating patch a66337ec215c88 for other similar issues and didn't see others.

Thank you for detecting this issue! Nicely done!

Pull request process is unclear to me after reading the instructions. Not my intention to go any deeper.
My intention was to pass the info on this bug so that it can hopefully be fixed in future itk releases.
Thank you.

Was this page helpful?
0 / 5 - 0 ratings