现在 scipy.misc.imresize 已从 scipy 中删除,如何调整图像大小?
How to resize an image now that scipy.misc.imresize has been removed from scipy?
我想使用一个使用 scipy.misc.imresize
的旧脚本。
但不幸的是,它已从 scipy 中完全删除。
我不明白它的作用,所以什么代码将执行与上面一行相同的操作。
我尝试使用 skimage.transform.resize(image, (num_px*num_px*3, 1), order = 3)
但是得到错误 - ValueError: cannot reshape array of size 12288 into shape (1200,1)
编辑:更多信息
它将图片分类为属于两组中的一组。
my_image = "anyimage.jpg" #any image form the internet
#Preprocessing the image
fname = "images/" + my_image
image = np.array(ndimage.imread(fname, flatten=False))
image = image/255.
my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape((1, num_px*num_px*3)).T #The original code which worked perfectly
my_predicted_image = predict(d["w"], d["b"], my_image) #predict function uses
#linear regression where the third parameter must be data of
#size (num_px * num_px * 3, number of examples)
您可以使用 pillow
而不是使用 scipy
图像例程 imread()
和 imresize()
,您应该这样做已经有了,因为它是 scipy
函数工作所必需的。
from PIL import Image
import numpy as np
my_image = "anyimage.jpg" #any image form the internet
fname = "images/" + my_image
num_px = 20 # a guess based on the shape of (1200, 1) in your error message
#Preprocessing the image
image = Image.open(fname).resize(size=(num_px, num_px)) # use PIL to open and reshape image
my_image = np.array(image, dtype=float) / 255 # convert to numpy array and scale values
my_image = my_image.reshape((1, num_px*num_px*3)).T # reshape and transpose
my_predicted_image = predict(d["w"], d["b"], my_image) #predict function uses
#linear regression where the third parameter must be data of
#size (num_px * num_px * 3, number of examples)
from PIL import Image
import numpy as np
my_image = "anyimage.jpg" #any image form the internet
fname = "images/" + my_image
#Preprocessing the image
image = Image.open(fname).resize(size=(num_px, num_px)) # use PIL to open and reshape image
my_image = np.array(image, dtype=float) / 255 # convert to numpy array and scale values
my_image = my_image.reshape((1, num_px*num_px*3)).T # reshape and transpose
my_predicted_image = predict(d["w"], d["b"], my_image)
我想使用一个使用 scipy.misc.imresize
的旧脚本。
但不幸的是,它已从 scipy 中完全删除。
我不明白它的作用,所以什么代码将执行与上面一行相同的操作。
我尝试使用 skimage.transform.resize(image, (num_px*num_px*3, 1), order = 3)
但是得到错误 - ValueError: cannot reshape array of size 12288 into shape (1200,1)
编辑:更多信息
它将图片分类为属于两组中的一组。
my_image = "anyimage.jpg" #any image form the internet
#Preprocessing the image
fname = "images/" + my_image
image = np.array(ndimage.imread(fname, flatten=False))
image = image/255.
my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape((1, num_px*num_px*3)).T #The original code which worked perfectly
my_predicted_image = predict(d["w"], d["b"], my_image) #predict function uses
#linear regression where the third parameter must be data of
#size (num_px * num_px * 3, number of examples)
您可以使用 pillow
而不是使用 scipy
图像例程 imread()
和 imresize()
,您应该这样做已经有了,因为它是 scipy
函数工作所必需的。
from PIL import Image
import numpy as np
my_image = "anyimage.jpg" #any image form the internet
fname = "images/" + my_image
num_px = 20 # a guess based on the shape of (1200, 1) in your error message
#Preprocessing the image
image = Image.open(fname).resize(size=(num_px, num_px)) # use PIL to open and reshape image
my_image = np.array(image, dtype=float) / 255 # convert to numpy array and scale values
my_image = my_image.reshape((1, num_px*num_px*3)).T # reshape and transpose
my_predicted_image = predict(d["w"], d["b"], my_image) #predict function uses
#linear regression where the third parameter must be data of
#size (num_px * num_px * 3, number of examples)
from PIL import Image
import numpy as np
my_image = "anyimage.jpg" #any image form the internet
fname = "images/" + my_image
#Preprocessing the image
image = Image.open(fname).resize(size=(num_px, num_px)) # use PIL to open and reshape image
my_image = np.array(image, dtype=float) / 255 # convert to numpy array and scale values
my_image = my_image.reshape((1, num_px*num_px*3)).T # reshape and transpose
my_predicted_image = predict(d["w"], d["b"], my_image)