首页 > 解决方案 > 数组到带有颜色图的图像

问题描述

我在 2048x2048 数组中有一些数据要转换为图像。

import numpy as np
from PIL import Image    

path = 'E:\\petra_2018_backup\\final\\raw\data\zn_2_run\\'
file = 'Zn_2_Pos1-01537.tif'   

im = Image.open(path+file)

a = np.array(im)

img = Image.frombytes('CMYK', (2048, 2048), a) # pass in the bytestring
img.save('pic.pdf')
img.show()

该结果非常暗,并且还混合了绿色和蓝色。我应该提到,附加的图片是结果的屏幕转储,因为结果图片太大而无法附加。'a' 数组的可视化

如果人们可以就压缩结果图像的方法提出建议,这也会很有用。

标签: pythonimagepython-imaging-library

解决方案


我根本找不到使用枕头的解决方案。所以我开始使用 scikit。

代码如下:

import numpy as np
from skimage import io
import matplotlib.pyplot as plt   

path = 'E:\\petra_2018_backup\\final\\raw\data\zn_2_run\\'
file = 'Zn_2_Pos1-01537.tif'

im =io.imread(path+file,as_gray=True)

b = np.array([im],dtype=np.uint16 )
b[b<150]=150  #Modification to array not included in original code
b[b>6000]=6000 #Modification to array not included in original code
c=b.squeeze() 
fig = plt.figure()
ax = plt.subplot(111)
ax = io.imshow(c)
fig.savefig('result_figure.png',dpi=320)

它产生以下情节。在此处输入图像描述


推荐阅读