Python读取图像
读取图像,转换为ndarray
代码源自:
------------------------------------------------------------------------
my_image = "my_image.jpg"
fname = "images/" + my_image image = np.array(ndimage.imread(fname, flatten=False)) my_image = scipy.misc.imresize(image, size=(num_px, num_px)).reshape((1, num_px * num_px * 3)).T my_predicted_image = predict(d["w"], d["b"], my_image)
-------------------------------------------------------------------------
1. scipy.ndimage.imread(fname,flatten=False): 将图片转换为数组,如果mode默认为‘RGB’,则返回的数组的形状为(height , width, 3)
2. matplotlib.pyplot.imshow(image): 将表示图片的(height , width, 3)数组转换为图片并显示出来。