需要numpy和laspy库,使用pcloud将f中需要的属性提取成nupmy数组,将RGB的值归一化成0-255之间,最后保存
import numpy as np
from laspy import file
f = file.File('test.las', mode='r')
pcloud = np.vstack((f.X, f.Y, f.Z, f.Red, f.Green, f.Blue)).transpose()
min = np.min(pcloud, axis=0)
rmin = min[3]
gmin = min[4]
bmin = min[5]
max = np.max(pcloud, axis=0)
rmax = max[3]
gmax = max[4]
bmax = max[5]
for point in pcloud:
point[3] = (point[3]-rmin)/(rmax-rmin)*255
point[4] = (point[4]-gmin)/(gmax-gmin)*255
point[5] = (point[5]-bmin)/(bmax-bmin)*255
np.savetxt('las2txt_test.txt', pcloud, fmt='%d')