【发布时间】:2020-05-31 18:15:55
【问题描述】:
我有 M 个向量,其中包含 4096 个介于 0 和 1 之间的数据点,它们代表人脸的亮度图。这是实际图像的示例。
现在,我的目的是将它们放在一个有情节的视觉效果中,但为此我需要提供一个代表图像的 PIL 对象,这是我的 MVC
import PIL.Image as pilim
import matplotlib.cm as cm
import numpy as np
greys = cm.get_cmap('Greys')
num_images = 10
num_faces = faces.shape[0]
sample_images = np.random.choice(num_faces, num_images, replace=False)
for index in sample_images:
greyscale = np.apply_along_axis(greys, 0, faces[index]).reshape((64, 64, 4))
im = pilim.fromarray(greyscale, mode='RGBA')
im.save('test{}.png'.format(index)) greys = cm.get_cmap('Greys')
Faces 是一个包含 698 个样本的 ndarray。类似于以下示例
[[0.01617647 0.01617647 0.01617647 ... 0. 0. 0. ]
[0.01617647 0.01617647 0.01617647 ... 0. 0. 0. ]
[0.01617647 0.01617647 0.01617647 ... 0. 0. 0. ]]
这是我令人沮丧的结果
【问题讨论】:
标签: python-3.x numpy matplotlib python-imaging-library