Alternative to scipy.misc.imresize() Alternative to scipy.misc.imresize() numpy numpy

Alternative to scipy.misc.imresize()


You can lookup the documentation and the source code of the deprecated function. In short, using Pillow (Image.resize) you can do:

im = Image.fromarray(old_image)size = tuple((np.array(im.size) * 0.99999).astype(int))new_image = np.array(im.resize(size, PIL.Image.BICUBIC))

With skimage (skimage.transform.resize) you should get the same with:

size = (np.array(old_image.size) * 0.99999).astype(int)new_image  = skimage.transform.resize(old_image, size, order=3)


Scipy Official Docs

imresize is now deprecated!
imresize is deprecated in SciPy 1.0.0, and will be removed in 1.3.0. Use Pillow instead:
numpy.array(Image.fromarray(arr).resize()).

from PIL import Imageresized_img = Image.fromarray(orj_img).resize(size=(new_h, new_w))


It almost looks like that line was a hacky way to transform your array from a 0..1 scale to 0..255 without any actual resizing. If that is the case you could simply do the following:

new_image = (old_image * 255).astype(np.uint8)

However, I do realize that the floats in your first sample array don't quite match the integers in the second...

Update: If you combine the rescaling to 0..255 with a resizing operation, e.g. one of the ways that jdehesa pointed out in their answer, you will reproduce your expected result (up to rounding errors). However, without knowing anything else about your code, I can't imagine that its functionality depends on resizing the image by such a small amount, which is why I'm guessing the purpose of this line of code was to transform the image to 0..255 (which is better done as above).