0

I want to use an old script which uses scipy.misc.imresize. But unfortunately it is removed entirely from scipy. I do not understand what it does so what code will perform the same action as the above line.

I tried using skimage.transform.resize(image, (num_px*num_px*3, 1), order = 3) But get the error - ValueError: cannot reshape array of size 12288 into shape (1200,1)

Edit: More Information

It's classifying pictures as belonging to one of two sets.

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)
Craig
  • 4,605
  • 1
  • 18
  • 28
A___
  • 83
  • 5
  • 1
    Does this answer your question? [Alternative to scipy.misc.imresize()](https://stackoverflow.com/questions/57414277/alternative-to-scipy-misc-imresize) – Craig May 24 '20 at 17:41
  • No. I have edited the question accordingly – A___ May 24 '20 at 18:03
  • 1
    Please provide more details (ideally an [mcve]) and someone might be able to help you. Right now, we're just guessing based on a partial error message and no data. – Craig May 24 '20 at 18:22
  • Does that help? – A___ May 24 '20 at 18:35

2 Answers2

0

Instead of using the scipy image routines imread() and imresize() which have been deprecated and removed, you can do the same thing using pillow, which you should already have since it is required for the scipy functions to work.

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)
Craig
  • 4,605
  • 1
  • 18
  • 28
0
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)
Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
Abin
  • 1