Wu solve AttributeError: module 'scipy.misc' has no attribute 'imread', imresize, imsave and other issues without downgrading scipy

Solve the following issues without downgrading scipy:
AttributeError: module 'scipy.misc' has no attribute 'imread',
AttributeError: module 'scipy.misc' has no attribute 'imresize',
AttributeError: module 'scipy.misc' has no attribute 'imsave'

imread,imresize,imsave

Recently encountered the following three errors
AttributeError: module 'scipy.misc' has no attribute 'imread',
AttributeError: module 'scipy.misc' has no attribute 'imresize',
AttributeError: module 'scipy.misc' has no attribute 'imsave '.
The reason is that scipy has deprecated a function in the misc library in the new version, including imread, imresize and imsave.

Many answers have mentioned reducing the version of scipy, but I feel that this solution is very uncomfortable. There must be a reason for the official deprecation of these functions. If you can't encounter problems, you always want to downgrade the version.

AttributeError: module 'scipy.misc' has no attribute 'imread' solution

code show as below

from scipy import misc
img = misc.imread(image_path)

The error is as follows

Traceback (most recent call last):
  File "Make_aligndata_git.py", line 57, in <module>
    img = misc.imread(image_path)
AttributeError: module 'scipy.misc' has no attribute 'imread'

amend as below

import imageio
img = imageio.imread(image_path)

AttributeError: module 'scipy.misc' has no attribute 'imresize' solution

code show as below

from scipy import misc
scaled_temp = misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear')

The error is as follows

Traceback (most recent call last):
  File "Make_aligndata_git.py", line 98, in <module>
    scaled_temp = misc.imresize(cropped_temp, (image_size, image_size), interp='bilinear')
AttributeError: module 'scipy.misc' has no attribute 'imresize'

amend as below

from skimage.transform import resize
scaled_temp = resize(cropped_temp,output_shape=(image_size, image_size))

AttributeError: module 'scipy.misc' has no attribute 'imsave' solution

code show as below

from scipy import misc
misc.imsave(output_filename, scaled_temp)

The error is as follows

Traceback (most recent call last):
  File "Make_aligndata_git.py", line 104, in <module>
    misc.imsave(output_filename, scaled_temp)
AttributeError: module 'scipy.misc' has no attribute 'imsave'

amend as below

import imageio
imageio.imwrite(output_filename,scaled_temp)

So the question is why scipy deprecates these functions in the new version of misc library, I don't know,
this misc is miscellaneous abbreviation (miscellaneous meaning)

Miscellaneous routines (scipy.misc)
Various utilities that don’t have another home.

It means that the functions that I don't know where to put are put here.
insert image description here
We can see that many functions related to cv have been deprecated.
I guess it may be because the Python Imaging Library (PIL) library must be installed to use these functions. The developers of scipy feel that this is not in line with their character, maybe It will be deprecated...
In the future, you can directly use the functions under the imageio library to use the
imageio API

Guess you like

Origin blog.csdn.net/qq_42859149/article/details/119508200