-
Notifications
You must be signed in to change notification settings - Fork 201
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
Incorrect resampling result with SimpleITK.sitkLinear Interpolator option #2098
Comments
Your assumption on expected behavior is incorrect. There are likely large differences between these random pixel values which make the changes in spacing significant enough for the linear interpolation of the faction of a pixel to be off by more than an half integer. Also there is the boundary condition and interpolation occurring. You may want to investigate the behavior of |
@blowekamp just checked with image of size 3x3x3 and values from 0 to 1, sometimes it fails to img_size = np.array([3, 3, 3])
img_spacing = np.array([0.15, 0.15, 0.15])
arr = np.random.randint(0, 2, img_size) |
something weird is happening here: arr = np.array([[[1., 0., 1.],
[1., 0., 0.],
[0., 1., 1.]],
[[0., 1., 0.],
[1., 1., 1.],
[0., 1., 1.]],
[[0., 1., 1.],
[1., 1., 1.],
[0., 1., 0.]]]) from skimage.transform import rescale
print(rescale(arr.astype(float), (2, 2, 2)).round())
print(sitk.GetArrayViewFromImage(result))
what did I do wrong?... |
So I found out a way to make results for integer more stable: resampler.SetOutputPixelType(sitk.sitkFloat32)
result = sitk.Cast(sitk.Round(resample.Execute(image)), image.GetPixelID()) Result:
|
SimpleITK.sitkLinear affects result
Applying ResampleImageFilter on image produces incorrect result with interpolator = sitk.sitkLinear
To Reproduce
Steps to reproduce the behavior:
Architecture: x86_64
CPU(s): 16
Programming language: Python 3.9.14]
Version of SimpleITK:
tested on 2.3.1
How was SimpleITK installed?
Got:
Expected behavior
For example output with sitk.sitkNearestNeighbor:
Additional context
I understand possible reasons why result can vary, though I guess it will be correct if output image will be the same
in case of
output_size - size * (output_spacing / input_spacing) < 0.5
The text was updated successfully, but these errors were encountered: