我已经创建了一个数组:

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

我想要做的是在512x512图像的中心显示一个红点。(至少开始时……我想我可以从那里弄清楚剩下的)


当前回答

使用pygame,您可以打开一个窗口,以像素数组的形式获取曲面,并从那里任意操作。不过,您需要将numpy数组复制到surface数组中,这比在pygame表面上进行实际的图形操作要慢得多。

其他回答

import numpy as np
from keras.preprocessing.image import array_to_img
img = np.zeros([525,525,3], np.uint8)
b=array_to_img(img)
b

使用pygame,您可以打开一个窗口,以像素数组的形式获取曲面,并从那里任意操作。不过,您需要将numpy数组复制到surface数组中,这比在pygame表面上进行实际的图形操作要慢得多。

补充使用matplotlib这样做。我发现做计算机视觉任务很方便。假设有dtype = int32的数据

from matplotlib import pyplot as plot
import numpy as np

fig = plot.figure()
ax = fig.add_subplot(1, 1, 1)
# make sure your data is in H W C, otherwise you can change it by
# data = data.transpose((_, _, _))
data = np.zeros((512,512,3), dtype=np.int32)
data[256,256] = [255,0,0]
ax.imshow(data.astype(np.uint8))

这可能是一个可能的代码解决方案:

from skimage import io
import numpy as np
data=np.random.randn(5,2)
io.imshow(data)

使用枕头的fromarray,例如:

from PIL import Image
from numpy import *

im = array(Image.open('image.jpg'))
Image.fromarray(im).show()