8 """Read image from file.
14 im = sp.misc.imread(filename)
16 return im / 127.5 - 1.0
19 def imsave(np_image, filename):
20 """Save image to file.
25 # im = sp.misc.toimage(np_image, cmin=0, cmax=1.0)
26 im = sp.misc.toimage(np_image, cmin=-1.0, cmax=1.0)
29 def imwrite(filename, np_image):
30 """Save image to file.
35 # im = sp.misc.toimage(np_image, cmin=0, cmax=1.0)
36 im = sp.misc.toimage(np_image, cmin=-1.0, cmax=1.0)
39 def imwrite_batch(filenames, np_images):
40 """Save batch images to file.
47 def imresize(np_image, new_dims):
48 """Image resize similar to Matlab.
50 This function resize images to the new dimension, and properly handles
51 alaising when downsampling.
53 np_image: numpy array of dimension [height, width, 3]
54 new_dims: A python list containing the [height, width], number of rows, columns.
56 im: numpy array resized to dimensions specified in new_dims.
58 # im = np.uint8(np_image*255)
59 im = np.uint8((np_image+1.0)*127.5)
60 im = Image.fromarray(im)
61 new_height, new_width = new_dims
62 im = im.resize((new_width, new_height), Image.ANTIALIAS)