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

Wrong/Misleading error message from ImageRegistrationMethod.MetricEvaluate function #1728

Closed
zivy opened this issue Oct 1, 2022 · 2 comments

Comments

@zivy
Copy link
Member

zivy commented Oct 1, 2022

When the fixed image has a single value (any value will work) and using MattesMutualInformation, calling the MetricEvaluate results in an exception which is misleading, message refers to image spacing which isn't the problem:

RuntimeError: Exception thrown in SimpleITK ImageRegistrationMethod_MetricEvaluate: /usr/local/miniconda/envs/bld/conda-bld/simpleitk_1649359436444/work/build/ITK-prefix/include/ITK-5.2/itkImageBase.hxx:165:
ITK ERROR: Image(0x7fe989578e00): A spacing of 0 is not allowed: Spacing is [0, 0.00396808]

This issue was raised in this ITK discourse question.

Minimal working example:

import SimpleITK as sitk
import numpy as np

fixed_image = sitk.Image([32]*3, sitk.sitkFloat32)
# Uncommenting the following line, fills the image with random content, and all is ok.
#fixed_image = sitk.Cast(sitk.GetImageFromArray(np.random.random([32]*3)), sitk.sitkFloat32)
moving_image = sitk.Cast(sitk.GetImageFromArray(np.random.random([32]*3)), sitk.sitkFloat32)

irm = sitk.ImageRegistrationMethod()
irm.SetMetricAsMattesMutualInformation(numberOfHistogramBins=256)
initial_metric_value = irm.MetricEvaluate(fixed_image, moving_image)

@blowekamp
Copy link
Member

This is most likely a corner case not handled in ITK itself.

@zivy
Copy link
Member Author

zivy commented Oct 7, 2022

Indeed an ITK issue. Logged a bug report on the ITK issue tracker and provided a test illustrating the problem. Closing the issue here in favor of the ITK issue.

@zivy zivy closed this as completed Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants