I'm using google colab for running python code and trying to downscale images.
from keras.layers import Lambda
import tensorflow as tf
from skimage import data, io, filters
import numpy as np
from numpy import array
from numpy.random import randint
from scipy.misc import imresize
import os
import sys
import matplotlib.pyplot as plt
plt.switch_backend('agg')
# Takes list of images and provide LR images in form of numpy array
def lr_images(images_real , downscale):
images = []
for img in range(len(images_real)):
images.append(imresize(images_real[img],[images_real[img].shape[0]//downscale,images_real[img].shape[1]//downscale], interp='bicubic', mode=None))
images_lr = array(images)
return images_lr
It should downscale the images but show this error.
from scipy.misc import imresize ImportError: cannot import name 'imresize'
How to get the same results as Matlab by python. dtest = [1,2,3; 4,5,6; 7,8,9]; scale = 1.4; dim = imresize(dtest,1/scale); These two pieces of code return different results.
The Scipy module misc contains a method derivative() that finds the nth derivative of a given function at a point. The syntax is given below. scipy.misc.derivative(func, x0, dx=1.0, n=1, args=(), order=3)
install scipy 1.1.0 by :
pip install scipy==1.1.0
It is deprecated. Use cv2 resize function instead
import cv2
size = (80,80)
cv2.resize(img, size)
You can use pillow as suggested in the comments. The changes for your code would be as mentioned below:
import PIL
images.append(np.array(PIL.Image.fromarray(images_real[img]).resize(
[images_real[img].shape[0]//downscale,
images_real[img].shape[1]//downscale],resample=PIL.Image.BICUBIC)))
If your image is represented as a float you will get an error saying "Cannot handle this data type". In which case you need to convert the image to uint format like this:
images.append(np.array(PIL.Image.fromarray(
(images_real[img]*255).astype(np.uint8)).resize(
[images_real[img].shape[0]//downscale,
images_real[img].shape[1]//downscale],resample=PIL.Image.BICUBIC)))
This work for me... In the imports i changed this:
from scipy.misc import imresize
for this:
from skimage.transform import resize
and example of the implementation i changed:
this:
img = imresize(img, (150, 150, 3)).astype('float32')/255.
for this:
img = resize(img, (150, 150, 3)).astype('float32')/255.
i hope this will help you too...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With