-
Notifications
You must be signed in to change notification settings - Fork 169
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
Issue with Origin Values Changing After Saving and Re-Loading an Image #582
Comments
It is likely something particular to your data.
I will look into it if you can share data. It's fine if you want to blank out the voxel values, an image of zeros that can reproduce the problem is OK. Also, please let us know the details of your system and ANTsPy version |
Round trips through ITK with non-standards compliant Nifti files can cause issues. In addition, make sure to test things with an itk compliant viewer such as itk snap to confirm things actually changed, rather than it being due to a viewer which uses different conventions. |
Thank you for your response. I'm using Python 3.10.8 with antspyx version 0.3.8, mainly for VMTK purposes. The MRI data in question comes from the freely available dataset (https://brain-development.org/ixi-dataset/). I also tested with Python 3.11.2 and antspyx version 0.4.2, but encountered the same issue with the origin shifting. @gdevenyi
ValueError: images do not occupy same physical space |
The |
@ncullen93 |
ANTsPy 0.5.0 on Mac OS 12.7:
0.4.2:
@tomo-akiyama I notice this image
is perhaps resampled, when I load the image, I see
Can you please provide a single code snippet with all the commands you ran to produce the issue? |
Finally, a reproducible example
|
@cookpa Thank you, everybody. |
Hello,
I'm new to using ANTsPy and have encountered an issue across multiple image processing functions, including n4_bias_field_correction, ants.resample_image, and ants.denoise_image, that I'm hoping to get some insights on. After applying these functions to MRA images and saving the processed images using ants.image_write, then reloading them with ants.image_read, I've noticed that the Origin values of the images are altered.
Here is a simplified example of my workflow:
import ants
Image processing (example with n4_bias_field_correction)
img_processed = ants.n4_bias_field_correction(img, rescale_intensities=True, shrink_factor=2)
Saving the processed image
output_path = "path/to/save/image.nii"
ants.image_write(img_processed, output_path)
Reloading the processed image
img_reloaded = ants.image_read(output_path)
Observing the change
print(img_processed)
ANTsImage (RPI)
Pixel Type : float (float32)
Components : 1
Dimensions : (480, 480, 480)
Spacing : (0.5, 0.5, 0.5)
Origin : (-120.0739, 112.3748, 0.857)
Direction : [ 0.9999 0. -0.0169 -0.0021 -0.9923 -0.1241 0.0168 -0.1242 0.9921]
print(img_reloaded)
ANTsImage (RPI)
Pixel Type : float (float32)
Components : 1
Dimensions : (480, 480, 480)
Spacing : (0.5, 0.5, 0.5)
Origin : (-118.7191, 122.3064, -78.5125)
Direction : [ 0.9999 0. -0.0169 -0.0021 -0.9923 -0.1241 0.0168 -0.1242 0.9921]
This issue doesn't seem to be isolated to n4_bias_field_correction but also occurs with ants.resample_image and ants.denoise_image. Each time, the Origin values before saving and after reloading do not match, leading to alignment problems in subsequent processing steps.
Any advice, insights, or workarounds to maintain consistent Origin values through the image processing pipeline would be greatly appreciated.
Thank you very much for your time and assistance.
Best regards,
The text was updated successfully, but these errors were encountered: