Ejemplo n.º 1
0
def write_LAS(pc_xyz,
              v,
              output_las_fn,
              input_las_fn,
              cmap=cm.terrain,
              rescale='none'):
    import datetime
    from laspy.file import File
    from skimage import exposure
    import copy

    inFile = File(input_las_fn, mode='r')

    #normalize input and generate colors for height using colormap
    #stretch to 10-90th percentile
    #v_1090p = np.percentile(v, [10, 90])
    #stretch to 2-98th percentile
    v_0298p = np.percentile(v, [2, 98])
    if rescale == 'none':
        v_rescale = exposure.rescale_intensity(v,
                                               in_range=(v_0298p[0],
                                                         v_0298p[1]))
    elif rescale == 'median':
        bounds = np.round(np.median(np.abs(v_0298p)), decimals=2)
        v_rescale = exposure.rescale_intensity(v, in_range=(-bounds, bounds))

    colormap_terrain = cmap
    rgb = colormap_terrain(v_rescale)
    #remove last column - alpha value
    rgb = (rgb[:, :3] * (np.power(2, 16) - 1)).astype('uint16')
    outFile = File(output_las_fn, mode='w', header=inFile.header)
    new_header = copy.copy(outFile.header)
    #setting some variables
    new_header.created_year = datetime.datetime.now().year
    new_header.created_day = datetime.datetime.now().timetuple().tm_yday
    new_header.x_max = pc_xyz[:, 0].max()
    new_header.x_min = pc_xyz[:, 0].min()
    new_header.y_max = pc_xyz[:, 1].max()
    new_header.y_min = pc_xyz[:, 1].min()
    new_header.z_max = pc_xyz[:, 2].max()
    new_header.z_min = pc_xyz[:, 2].min()
    new_header.point_records_count = pc_xyz.shape[0]
    new_header.point_return_count = 0
    outFile.header.count = v.shape[0]
    new_header.scale = inFile.header.scale
    new_header.offset = inFile.header.offset
    outFile.X = (pc_xyz[:, 0] -
                 inFile.header.offset[0]) / inFile.header.scale[0]
    outFile.Y = (pc_xyz[:, 1] -
                 inFile.header.offset[1]) / inFile.header.scale[1]
    outFile.Z = (pc_xyz[:, 2] -
                 inFile.header.offset[2]) / inFile.header.scale[2]
    outFile.Red = rgb[:, 0]
    outFile.Green = rgb[:, 1]
    outFile.Blue = rgb[:, 2]
    outFile.close()
Ejemplo n.º 2
0
    def write_las(self, file_name: str, alt_header: File = None):
        """ Writes the current points in a las format

        Header used will be the same as the one provided during loading otherwise given.
        """

        f = File(file_name,
                 mode='w',
                 header=alt_header if alt_header else self.header)
        data = self.data(transformed=False)

        f.X = data[:, 0]
        f.Y = data[:, 1]
        f.Z = data[:, 2]

        f.Red = data[:, 3]
        f.Green = data[:, 4]
        f.Blue = data[:, 5]

        f.close()