python - 数组到带有颜色图的图像
问题描述
我在 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()
该结果非常暗,并且还混合了绿色和蓝色。我应该提到,附加的图片是结果的屏幕转储,因为结果图片太大而无法附加。
如果人们可以就压缩结果图像的方法提出建议,这也会很有用。
解决方案
我根本找不到使用枕头的解决方案。所以我开始使用 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)
推荐阅读
- vba - 远程服务器机器不存在或不可用”
- sql - 如何为以下要求构建 SQL 查询?
- javascript - 声明增量 Javascript 变量
- java - java.lang.RuntimeException:无法启动活动 ComponentInfo。二进制 XML 文件第 8 行:膨胀类 com.mapbox.vision.view.VisionView 时出错
- javascript - 如何在标题上添加波纹效果
- java - 集成测试中@DirtiesContext 和 FlywayConfig bean 组合出现异常
- autodesk-forge - 欧特克锻造。如何模糊选定对象以外的对象?
- android-studio - 更新/安装最新的 Flutter 包 (pubspec.yaml)
- java - 在hibernate vs JDBC或mybatis之间选择的最佳实践仅在数据库中插入而在java中的表中没有任何关系
- hadoop - hive shell 在我的 hive 3.1.2 中显示了许多日志/警告