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

Resample_images() crashes kernel #429

Closed
ninea-anasovi opened this issue Feb 14, 2023 · 5 comments
Closed

Resample_images() crashes kernel #429

ninea-anasovi opened this issue Feb 14, 2023 · 5 comments

Comments

@ninea-anasovi
Copy link

ninea-anasovi commented Feb 14, 2023

function resample_images crashes kernel

I am using python 3.9.4
Jupiter Notebook
Visual studio code

Libraries that I use are:
Matplotlib
Nibabel
Antspyx

First of all I could not install antspy with:
pip install antspyx
As numpy verson was 1.24.2
So I had to donwgrade my python.

After that I needed rigit co-registration of 2 3D images

It didn't worked so I tried to see ants.get_data('r16') and I realised it was 2D and tried to copy the code from documentation to test:

fi = ants.image_read(ants.get_ants_data('r16'))

mi = ants.image_read(ants.get_ants_data('r64'))

print(fi)

print(mi)

fi = ants.resample_image(fi, (60,60), 1, 0)

mi = ants.resample_image(mi, (60,60), 1, 0)

mytx = ants.registration(fixed=fi,moving=mi,type_of_transform ='Rigid' )

This Crashes kernel and I can not do anything unless I reload my VS code.

image

If I remove 2 lines with resample_image() then this is the error I see:

image

Please help me solve this issue.

Os: Windows 10

@dipterix
Copy link

(I'm not ANTs devs, just a user encounter the same issue)

Same here on Windows. Not only resample_image, but also many other functions raise errors, mostly XXXX failed with error code 1 or something like file 000002BE70950FA0 does not exist.

After tracing back to the source (searching keyword "failed with error code"), I found all these failed functions call ANTs c++ with system calls. For example in ResampleImage

libfn = utils.get_lib_fn('ResampleImage')
libfn(processed_args)

or in antsRegistration

processed_args = utils._int_antsProcessArguments(fixed)
libfn = utils.get_lib_fn("antsRegistration")
reg_exit = libfn(processed_args)
if (reg_exit != 0):
raise RuntimeError(f"Registration failed with error code {reg_exit}")

The argument processed_args contains ANTsImage, which seems to be turned into memory pointers (I guess?) when passing to system calls. With verbose=True, ANTsPy prints out the command:

antsRegistration -d 2 -r [000001F898A756B0,000001F898A75920,1] -m mattes[000001F898A756B0,000001F898A75920,1,32,regular,0.2] -t Affine[0.25] -c 2100x1200x1200x0 -s 3x2x1x0 -f 4x2x2x1 -x [NA,NA] -m mattes[000001F898A756B0,000001F898A75920,1,32] -t SyN[0.200000,3.000000,0.000000] -c [40x20x0,1e-7,8] -s 2x1x0 -f 4x2x1 -u 1 -z 1 -o [C:/Users/RUNNER~1/AppData/Local/Temp/Rtmp6VIw8G/working_dir/RtmpOGBhDO/file16ec59566cdb,000001F898A75930,000001F898A75890] -x [NA,NA] --float 1 --write-composite-transform 0 -v 1

Next moment, I saw this error

 file 000001F898A756B0 does not exist . 
Exception Object caught: 

itk::ExceptionObject (0000007EB4F99020)
Location: "unknown" 

However, somehow Windows does not read in the image/transform pointers correctly.

By the way, i'm using Python 3.8.16 on AMD 64x

@stnava
Copy link
Member

stnava commented Feb 26, 2023 via email

@dipterix
Copy link

Gotcha, if I save the files to the file system, can I call libfn from Python with file paths as arguments instead of pointers? I saw https://github.com/ANTsX/ANTs/blob/e62eca0988c3ad3cd151ef380465e230b95891a7/Scripts/newAntsExample.sh

However, I don't know how to implement.

@dipterix
Copy link

dipterix commented Feb 26, 2023

@ninea-anasovi I created a patch to deal with this issue for my package: https://github.com/dipterix/rpyANTs/blob/main/inst/patches/win_patch.py

Basically it allows the functions to store the data in temporary files instead of keeping them in memory. You can run this code via python import or just copy-paste them after importing ants:

Please edit accordingly:

import ants

# now import win_patch.py to apply patch. You might want edit the following line
import win_patch.py

@cookpa
Copy link
Member

cookpa commented Mar 27, 2023

I believe this should be fixed by #442

@cookpa cookpa closed this as completed Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants