2
我有一个测量数据文本文件,看起来像这样。坐标值为图像
x y z
1 3 -2
2 1 -3
3 1 1
2 2 3
1 2 2
2 3 0
这将意味着在以下测量(上一个x,y网格)
-2 0
2 3
-3 1
我想创建从这些值的图像,其中没有测量将意味着该图像是透明的。如果可能的话,我想将z值(从例如-9.4到+3.2)映射到一个颜色映射表,比如colormap.jet
我试图用Python Image Library和putpixel来做这个,但是这很缓慢,我相信必须有更好的方式来做到这一点。
我当前的代码: 基本路径= os.path.dirname(os.path.realpath(文件))#定义了当前文件驻留 srcFiles = glob.glob( '* PTS。')的目录
在srcFiles为文件名:
data = pd.read_csv(os.path.join(basePath, fileName), names=['x', 'y', 'z'], delim_whitespace=True)
print fileName
maxX = data.x.max()
minX = data.x.min()
maxY = data.y.max()
minY = data.y.min()
minZ = data.z.min()
maxZ = data.z.max()
width = maxX-minX
height = maxY-minY
img = Image.new('L', (int(width), int(height)))
for x in range(int(width)):
for y in range(int(height)):
value = data[(data['x'] == (minX+x)) & (data['y'] == (minY+y))]['z']
if len(value) == 0:
value = 99.;
img.putpixel((x,y),int(value))
img.save('test.png')