我有一个 csv 文件,每行都有 RGB 值。我想生成一个 512 x 512 的图像,每个像素值取自 csv 的行。我该怎么做?任何帮助将非常感激。
2.053 163.5011 0.0522
2.053 163.4489 0.0517
2.053 163.3972 0.0511
2.053 163.3461 0.0506
2.053 163.2955 0.0501
...
我想代码应该是这样的
import numpy as np
import PIL
import matplotlib.pyplot as plt
# load the data
im_l = np.genfromtxt('image.csv', delimiter=',')
# resphape the data
img = np.reshape(im_l, (256,256,3)) # change 256's according to your data
# visualize the data
plt.figure
plt.imshow(img)
# finally save the image as jpg file
image = PIL.Image.fromarray(img.astype('uint8'), 'RGB')
image.save('my_im.jpg')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句