我如何转换numpy的数组(和显示)的图像? [英] How do I convert a numpy array to (and display) an image?

查看:137
本文介绍了我如何转换numpy的数组(和显示)的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个数组正是如此:

I have created an array thusly:

import numpy as np
data = np.zeros( (512,512,3), dtype=np.uint8)
data[256,256] = [255,0,0]

我想这做的是显示512×512图像的中心有一个红点什么。 (至少要开始...我想我可以计算出从那里休息)

What I want this to do is display a single red dot in the center of a 512x512 image. (At least to begin with... I think I can figure out the rest from there)

推荐答案

您可以使用PIL创建静止图像:

You could use PIL to create a still image:

from PIL import Image
import numpy as np

w, h = 512, 512
data = np.zeros((h, w, 3), dtype=np.uint8)
data[256, 256] = [255, 0, 0]
img = Image.fromarray(data, 'RGB')
img.save('my.png')

这篇关于我如何转换numpy的数组(和显示)的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆