P2 //which format it is
width height //dimensions
maxValue //the highest value a pixel can have (represents white)
a b c ... //the pixel values (new line needed at the end of each row)
如何从CSV中获取值应该很简单,然后可以使用如下函数(未测试):
def toFile(array, filename):
f = file(filename, 'w')
f.write("P2\n%d %d\n255\n" %(len(array[1]), len(array))
for i in array:
for j in i:
f.write("%d " %(j))
f.write("\n")
f.close()
对于一个非常简单的解决方案,如果您只想了解图像的外观,可以使用pgm格式。
您可以通过将像素写为ascii来创建它。链接会更详细,但要点是您有一个格式的文件:
如何从CSV中获取值应该很简单,然后可以使用如下函数(未测试):
两个步骤:
来自@Andrew onHow to read csv into record array in numpy?
相关问题 更多 >
编程相关推荐