import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage
%matplotlib inline
num_px = 64
my_image = "my_image4.jpg" # 修改你图像的名字
fname = "images/" + my_image # 图片位置
image = np.array(ndimage.imread(fname, flatten=False)) # 读入图片为矩阵
plt.imshow(image)
# my_image = scipy.misc.imresize(image, size=(num_px, num_px)).reshape((1, num_px * num_px * 3)).T # 转置图片为 (num_px*num_px*3, 1)向量
# 重新设置图像像素
my_image = scipy.misc.imresize(image, size=(num_px, num_px))
plt.imshow(my_image)
scipy笔记—scipy.misc.imresize用法(方便训练图像数据)
原文:https://www.cnblogs.com/douzujun/p/10280213.html