InsightSoftwareConsortium / InsightSoftwareConsortium/ITKElastix
`itk.elastix_registration_method` sometimes crashes silently
- Dominant language
- Python
- Stars
- 281
- Forks
- 29
- Avg merge
- 16h 28m
- Merged PRs (30d)
- 8
Description
## Overview
Registration with `itk.ElastixRegistrationMethod` or `itk.elastix_registration_method` sometimes crashes on Windows.
I am having difficulty pinning down the exact cause of the issue. It appears most frequently, but not exclusively, when the image is initialized from a NumPy array. I've been able to sometimes reproduce the issue across two Windows machines, across `itk==v5.3.0` and `itk==v5.4rc1`, and `itk-elastix` versions `0.16.0`, `0.18.0`, and `0.19.0`. It is unclear whether a resolution lies in ITK, Elastix, or ITKElastix.
## Steps to Reproduce
Replace the image source in the first ITKElastix example with a NumPy-converted image.
```py
fixed_image = itk.image_from_array(np.random.rand(10,10,10).astype(np.float32))
moving_image = itk.image_from_array(np.random.rand(10,10,10).astype(np.float32))
registered, parameters = itk.elastix_registration_method(fixed_image, moving_image )
```
Or, download test images and read in with `itk.imread`: https://data.kitware.com/#user/602bd4e62fa25629b97ba6ec/folder/6525e04e43427b2e1b65cba8
## Expected Behavior
Registration completes without error.
## Observed Behavior
The running Python process crashes. Logging to console or file shows output similar to below:
```
```py
>>> registered, parameters = itk.elastix_registration_method(s,t, log_to_console=True)
WARNING: The parameter "MovingInternalImagePixelType", requested at entry number 0, does not exist at all.
The default value "float" is used instead.
ELASTIX version: 5.1.0
Command line options from ElastixBase:
-priority unspecified, so NORMAL process priority
-threads unspecified, so all available threads are used
WARNING: The parameter "UseDirectionCosines", requested at entry number 0, does not exist at all.
The default value "true" is used instead.
WARNING: The option "UseDirectionCosines" was not found in your parameter file.
From elastix 4.8 it defaults to true!
This may change the behavior of your registrations considerably.
Command line options from TransformBase:
-t0 unspecified, so no initial transform used
Reading images...
Reading images took 0 ms.
WARNING: the fixed pyramid schedule is not fully specified!
A default pyramid schedule is used.
WARNING: the moving pyramid schedule is not fully specified!
A default pyramid schedule is used.
WARNING: The parameter "AutomaticTransformInitializationMethod", requested at entry number 0, does not exist at all.
The default value "GeometricalCenter" is used instead.
Transform parameters are initialized as: [0, 0, 0]
Initialization of all components (before registration) took: 0 ms.
Preparation of the image pyramids took: 33 ms.
Resolution: 0
WARNING: The parameter "ShowExactMetricValue", requested at entry number 0, does not exist at all.
The default value "false" is used instead.
... # other standard warnings ...
WARNING: The parameter "SigmoidScaleFactor", requested at entry number 0, does not exist at all.
The default value "0.1" is used instead.
Elastix initialization of all components (for this resolution) took: 1 ms.
Initialization of AdvancedMattesMutualInformation metric took: 8 ms.
Starting automatic parameter estimation for AdaptiveStochasticGradientDescent ...
WARNING: The parameter "ASGDParameterEstimationMethod", requested at entry number 0, does not exist at all.
The default value "Original" is used instead.
Computing JacobianTerms ...
Computing the Jacobian terms took 0.000548s
NumberOfGradientMeasurements to estimate sigma_i: 11
Sampling gradients ...
# silent crash
```
Sometimes when running within a `dask.delayed` function a Windows access violation error is printed to the console before exit:
```
Windows fatal exception: access violation
```
The behavior is reproducible in a standard Python console.
## Platforms
Windows 10 and Windows 11
## Versions
Python 3.8 and Python 3.10
`itk` v5.3.0, v5.4rc1
`itk-elastix` 0.16.0, 0.18.0, 0.19.0
## Additional Notes
Perhaps there is an issue with the ITK NumPy bridge rather than in ITKElastix? I could not find any obvious differences between an image read from disk and an image obtained from a NumPy array. I am able to directly access pixels in the fixed and moving images without error.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.