ITK
ITK copied to clipboard
Image Writing from Python and C++ give different results
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".
@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.
I can reproduce this on Windows, too, with my existing build of ITK.
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.
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?
Some related forum discussion can be found here.
This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.