I want to use an old script which still uses scipy.misc.imresize()
which is not only deprevated but removed entirely from scipy. Instead the devs recommend to u
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).
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)
Just do one thing that resolves all the version 2 problems
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
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 Image
resized_img = Image.fromarray(orj_img).resize(size=(new_h, new_w))
Tensorflow 1:
image = np.array(ndimage.imread(fname, flatten=False))
image = np.array(im)
image = image/255.
my_image = scipy.misc.imresize(image, size=(64,64)).reshape((1, 64*64*3)).T
my_image_prediction = predict(my_image, parameters)
Tensorflow 2:
import imageio
im = imageio.imread(fname)
image = np.array(im)
image = image/255.
num_px = 64
my_image = image.reshape((1, num_px*num_px*3)).T # WITHOUT RESIZE
my_image_prediction = predict(my_image, parameters)