def genDSM_building(BD_footprint,PC_data,h,w,n,ground_height,affine_par,upper_bd_par):
[A,D,B,E,C,F] = np.loadtxt(affine_par)
BD_footprint = cv2.imread(BD_footprint,0)
point_cloud = pd.read_csv(PC_data,names=['X', 'Y', 'Z', 'R','G','B'],delim_whitespace=True)
X = point_cloud.X.copy()
Y = point_cloud.Y.copy() # Inverse the Y-axis
Z = point_cloud.Z.copy()
del point_cloud
Dsm_arr = np.zeros((h, w))
# cKDtree
tree = spatial.cKDTree(list(zip(Y, X)))
#Affine Trans
yv, xv = np.where(BD_footprint>127)
XA = A*xv+B*yv+C
YA = D*xv+E*yv+F
pts = np.dstack((YA,XA))
dis, loc = tree.query(pts, k=n ,distance_upper_bound=upper_bd_par)
#building use max
Dsm_arr[yv,xv] = Z[loc[:,:,:].ravel()].values.reshape(-1, n).max(axis=1)
Dsm_arr=np.float32(Dsm_arr)
return Dsm_arr
评论列表
文章目录