Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Writing from Python and C++ give different results #2703

Open
hjmjohnson opened this issue Aug 21, 2021 · 6 comments
Open

Image Writing from Python and C++ give different results #2703

hjmjohnson opened this issue Aug 21, 2021 · 6 comments
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@hjmjohnson
Copy link
Member

hjmjohnson commented Aug 21, 2021

Description

Identical code (written in python & C++) results in different images being written to disk.

The python code writes an image to disk with Identity direction cosine, even though the image supplied to the write function has non-identity cosines. The change occurs somewhere in itk::ImageBase::UpdateOutputInformation().

Steps to Reproduce

A self-contained environment creates a new virtual environment, builds ITK with python and C++ and runs both the C++ and python test cases from the same source builds is available in the tarball file.

TARBALL: https://github.com/BRAINSia/ITK/raw/debug-python-diffs/failure_case.tar.gz

Download the tarball and run the "do_test.sh" to build (on unix) a clean version of ITK that is instrumented to show the problem.

Expected behavior

Both the C++ and the python variations should produce identical images on disk.

Actual behavior

The python generated image has an identity direction cosine.

Reproducibility

Two different computers (both release and debug mode tested) for two different uses produced the same failures.

Versions

Latest ITK master branch

Environment

Ubuntu 20.04 linux.

Additional Information

Using the "ResampleInPlaceImageFilter".

@hjmjohnson hjmjohnson added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Aug 21, 2021
@hjmjohnson
Copy link
Member Author

@dzenanz I spent all day trying to debug this very weird python problem. I'm hoping you can help shed some light on this failure.

The tarball should be self-contained, and should build and demonstrate the failure by running the do_test.sh script.

@dzenanz
Copy link
Member

dzenanz commented Aug 23, 2021

I can reproduce this on Windows, too, with my existing build of ITK.

@hjmjohnson
Copy link
Member Author

Good news! At least it is reproducible. I was struggling to determine where execution diverges. I could not figure out how to debug the c++ code called from python.

@dzenanz
Copy link
Member

dzenanz commented Aug 23, 2021

The way which worked for me before was to use Visual Studio, enable "Enable native code debugging" in Python project and then step into (F11) interesting code. However, this time VS doesn't step into rip.Update(). The only suspect I have is use of this->GraftOutput(m_OutputImage); in Modules\Core\Transform\include\itkResampleInPlaceImageFilter.hxx. @thewtex do you have ideas about what could be wrong?

@dzenanz dzenanz removed their assignment Aug 23, 2021
@dzenanz
Copy link
Member

dzenanz commented Aug 26, 2021

Some related forum discussion can be found here.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the status:Use_Milestone_Backlog Use "Backlog" milestone instead of label for issues without a fixed deadline label Apr 16, 2022
@hjmjohnson hjmjohnson added this to the ITK 6.0 Beta 1 milestone Jan 23, 2025
@stale stale bot removed the status:Use_Milestone_Backlog Use "Backlog" milestone instead of label for issues without a fixed deadline label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

No branches or pull requests

2 participants