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

SymmetricEigenAnalysisImageFilter incorrect python wrapping #4520

Closed
chatti opened this issue Mar 15, 2024 · 6 comments · Fixed by #4675
Closed

SymmetricEigenAnalysisImageFilter incorrect python wrapping #4520

chatti opened this issue Mar 15, 2024 · 6 comments · Fixed by #4675
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Milestone

Comments

@chatti
Copy link

chatti commented Mar 15, 2024

The python implementation of SymmetricEigenAnalysisImageFilter is returning 6 values per pixel instead of 3, and more than 3 of the 6 values is non-zero. Since there are only 3 eigenvalues for a 3D Hessian (3x3) eigenvalue decomposition, this functionality must be incorrect.

I asked about this on the forum and the comment was that it was probably wrapped incorrectly.
"Maybe the problem is in wrapping specification? The test instantiates the filter with <SSRT<3>, FixedArray<3> >, whereas the wrapping instantiates with <SSRT<3>, SSRT<3> >."

https://discourse.itk.org/t/computing-hessian-eigenvalues-in-python-how-to-interpret-output-of-symmetriceigenanalysisimagefilter/6517

Description

Steps to Reproduce

  1. Use a test image (ideally a CT scan) with size >= 100^3
  2. Run this code:
import itk
#Load the sample image, ideally a CT scan
hessian_image = itk.hessian_recursive_gaussian_image_filter(
            itk_image, sigma=2.0
        )
#hessian_image size = (6, 188, 217, 259)
eigen_values_image = itk.SymmetricEigenAnalysisImageFilter(hessian_image)
#eigen_values_image size = (6, 188, 217, 259)

eigen_values_array = itk.GetArrayFromImage(eigen_values_image, keep_axes=True)
print( eigen_values_array[:,100,100,100] )

Expected behavior

You should see an array printed out that has 6 values. Similar to this, but the numbers obviously will not be the same
array([ -3.0928779 , 1.86561006, 0. , -11.97670084,
6.26783045, 0. ])

Actual behavior

Reproducibility

Unknown

Versions

5.3.0

Environment

python:
4.9.18 (main, Feb 13 2024, 10:56:47)
[GCC 12.2.0]

@chatti chatti added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Mar 15, 2024
Copy link

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

@dzenanz
Copy link
Member

dzenanz commented Mar 15, 2024

Taking a second look, itk.SymmetricEigenAnalysisImageFilter is the object-oriented syntax. You should have a .Update(), or use snake case like for hessian_recursive_gaussian_image_filter.

@chatti
Copy link
Author

chatti commented Mar 15, 2024

SymmetricEigenAnalysisImageFilter

I'm still getting the same problems when I use this code:
hessian_image = itk.hessian_recursive_gaussian_image_filter( itk_image, sigma=sigma ) eigs = itk.symmetric_eigen_analysis_image_filter(hessian_image)

results in
[ -0.56114415 0.56627178 0. -28.24620925 5.85857641 │··························································· 0. ]

When I query a single pixel

@chatti
Copy link
Author

chatti commented Mar 15, 2024

Taking a second look, itk.SymmetricEigenAnalysisImageFilter is the object-oriented syntax. You should have a .Update(), or use snake case like for hessian_recursive_gaussian_image_filter.

Object oriented approach doesn't work either

   ```eig_filter = itk.SymmetricEigenAnalysisImageFilter.New(hessian_image)
    eig_filter.Update()
    eig_image = eig_filter.GetOutput()```

[ -0.56114415 0.56627178 0. -28.24620925 5.85857641 0. ]

@dzenanz
Copy link
Member

dzenanz commented Mar 15, 2024

It is a bit strange that your original code worked (due to syntax).

But I guess that problem is in the wrapping.

@chatti
Copy link
Author

chatti commented Mar 15, 2024

It is a bit strange that your original code worked (due to syntax).

But I guess that problem is in the wrapping.

Yeah, it ran without error but the values at that pixel were different.

@thewtex thewtex added this to the ITK 5.4.0 milestone Mar 26, 2024
thewtex added a commit to thewtex/ITK that referenced this issue May 16, 2024
…e output

The default template parameter output, an Image of
SymmetricSecondRankTensor, is not correct or valid. The output of this
filter is an image of eigenvectors. Wrap with an Image of
CovariantVector along with base classes. Also remove the invalid default
template parameter output.

Closes InsightSoftwareConsortium#4520
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

Successfully merging a pull request may close this issue.

3 participants