NIfTI-Image-Converter icon indicating copy to clipboard operation
NIfTI-Image-Converter copied to clipboard

scipy.misc.imsave is deprecated

Open rien333 opened this issue 5 years ago • 7 comments

According to the scipy documentation, the scipy.misc.imsave function is deprecated. More so, it has been completely removed in newer scipy 1.3+ versions, so that nii2png now fails:

$ python nii2png.py -i in.png -o foo/
Reading NIfTI file...
Saving image...
Traceback (most recent call last):
  File "nii2png.py", line 158, in <module>
    main(sys.argv[1:])
  File "nii2png.py", line 142, in main
    scipy.misc.imsave(image_name, data)
AttributeError: module 'scipy.misc' has no attribute 'imsave'

However, the documentation linked above does recommend another way to save images.

rien333 avatar Dec 27 '19 21:12 rien333

Thanks for this, this is something I have been trying to overcome. Any contributions are welcome on this issue... for the time being, I recommend downgrading scipy for nii2png

alexlaurence avatar Feb 12 '20 02:02 alexlaurence

What about just doing what the documentation says, and introducing a new dependency to save images? I think that's what I did to fix this, and it worked just fine from what I can remember.

rien333 avatar Feb 12 '20 09:02 rien333

What about just doing what the documentation says, and introducing a new dependency to save images? I think that's what I did to fix this, and it worked just fine from what I can remember.

Can confirm. I installed the imageio library and changed all scypi.misc.imsave instances to imageio.imwrite and it worked like a charm.

petremihaivalentin avatar Mar 17 '20 06:03 petremihaivalentin

imageio.imwrite seems the way to go, I've submitted a PR.

aviogit avatar Mar 27 '20 12:03 aviogit

imageio.imwrite seems the way to go, I've submitted a PR.

Hi, I've been trying to get the code to run with imageio.imwrite, but get the following error:

OSError: cannot write mode F as PNG

Does anyone know the fix for this?

Thanks. Best, Vicent

vcasellesb avatar Sep 21 '23 09:09 vcasellesb

I've added a PR that fixes this - it's because nibabel deprecated get_data so you have to pass it to numpy.asanyarray

OliJimbo avatar Apr 27 '24 12:04 OliJimbo

I've added a PR that fixes this - it's because nibabel deprecated get_data so you have to pass it to numpy.asanyarray

Hi,

Thanks for your reply. Wouldn't it be better using nibabel's .get_fdata()? I think that's the recommended way.

vcasellesb avatar Apr 27 '24 14:04 vcasellesb