ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
628 stars 161 forks source link

'ANTsImage' object has no attribute 'endswith' #688

Open Planetdtudy opened 2 months ago

Planetdtudy commented 2 months ago

Hi, I am trying to use ANTS, but getting this issue:

I am trying to open .nii file

image='path/brain.nii'

brain_extracted_image = ants.image_read(image) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ants/core/ants_image_io.py", line 495, in image_read if filename.endswith(".npy"): AttributeError: 'ANTsImage' object has no attribute 'endswith'

cookpa commented 2 months ago

Are you certain image is a string? I can read ".nii" files on my machine.

What happens if you do

type(image)

?

If image is an image and not a str, you'll see this error.

Planetdtudy commented 2 months ago

Thank you. But it is a nii file. And I can read it with nibabel package.

cookpa commented 2 months ago

OK, I'm going to try to replicate more closely. What antspyx version do you have installed? (pip freeze | grep ants) What OS are you using?

Planetdtudy commented 2 months ago

Should I use something like this img = ants.image_read(ants.get_ants_data('brain.nii'))

cookpa commented 2 months ago

ants.get_ants_data is a convenience function to return the path to certain built-in ANTs images for examples. It should return a string, so you will see things like

img = ants.image_read(ants.get_ants_data('mni'))

If you have a string, then using your example

image='path/brain.nii'
img = ants.image_read(image) 

should work. What happens if you use the literal string?

img = ants.image_read('path/brain.nii')
Planetdtudy commented 2 months ago

Sonoma, pip freeze | grep ants antspyx==0.3.8

Planetdtudy commented 2 months ago

img = ants.image_read('path/brain.nii') - seams like it works.

cookpa commented 2 months ago

Very weird. But

fn = 'path/brain.nii'
type(fn)
img = ants.image_read(fn)

doesn't work? I'm having a hard time imagining how that could happen. Might be worth upgrading to 0.4.2, just in case there was some logic fix I missed.

cookpa commented 1 month ago

I think this error might also be caused by running python from the ANTsPy/ source directory