首页 > 解决方案 > 将元组列表转换为灰度图像,知道它的大小

问题描述

我拥有一个从 tex 提取的元组列表,它是灰度图像上像素的位置。如何使用我的列表创建 y 图像?

我尝试使用数组和 pyplot 没有成功

   [(5, 160), (5, 160), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, 387), (10, ...

这是名为 Position 的夫妇名单,它继续下去,还有大约 3000 对夫妇

尺寸为 598 x 513

tab=np.full((A,B),255,dtype='uint8')

for i,j in Position:
    tab[i,j]=0

plt.imshow(tab,cmap='gray')

plt.show()

myarray = np.asarray(Position)

img = Image.fromarray(myarray)

img.save('test.png')

标签: pythonimagelist

解决方案


推荐阅读