从numpy数组生成灰度图像,并从图像中恢复相同的numpy数组

时间:2017-04-18 02:26:57

标签: python arrays image numpy matplotlib

我是python的新手,我正在从numpy数组生成灰度图像,如下所示:

我的数组是:[ 7.09688331 9.17397351 -21.01224545 ..., 84.3304575 162.08131367 247.96525907]

数组的长度为44100

#Generating Image
import scipy.misc as mi

from PIL import Image

import numpy as np

import matplotlib.pyplot as plt

img = Image.fromarray(sample.reshape(210,210), 'L')
print(img)
OUTPUT:<PIL.Image.Image image mode=L size=210x210 at 0xB5FD5304A8>

#Saving Image
filename='image1.png'

mi.imsave(filename, img)

#Now when I read the grey scale image I get different values from my original sample array? 


img1 = Image.open('image1.png')

array = np.reshape(img1, (1,np.product([210,210])))

print(array)

数组输出为:[ 133 133 131 ..., 136 140 144]

我想要恢复原始数组:[ 7.09688331 9.17397351 -21.01224545 ..., 84.3304575 162.08131367 247.96525907]

当我读取灰度图像时,如何取回原始数组?

0 个答案:

没有答案