Пример #1
0
def plot_tiles_hdiff(dict_values, args):

    from matplotlib.collections import PatchCollection
    from matplotlib.patches import Rectangle

    fns = dict_values.keys()
    _, _, _, _, r, x_offset, y_offset, _, _, _, _ = args

    # Get origin from initial filename
    m, n = fns[0][:17].split('_')
    [mm0, nn0] = coord(m, n, r, x_offset, y_offset)

    # Create figure and axes
    fig, ax = plt.subplots(1)

    patches = []
    values = []

    for fn in fns:

        if fn in dict_values:

            if dict_values[fn] != None and not math.isnan(dict_values[fn]):

                values.append(dict_values[fn])

                # Get origin from filename
                m, n = fn[:17].split('_')
                [mm, nn] = coord(m, n, r, x_offset, y_offset)

                mm = float(mm) - mm0
                nn = float(nn) - nn0

                # Create a Rectangle patch
                rect = Rectangle((mm, nn),
                                 r,
                                 r,
                                 linewidth=1,
                                 edgecolor='r',
                                 facecolor='r')
                patches.append(rect)

    collection = PatchCollection(patches, cmap=plt.cm.jet, alpha=0.8)
    collection.set_array(np.abs(values))

    #collection.set_clim(-0.5, 0.5)
    ax.add_collection(collection)
    fig.colorbar(collection)

    plt.xlim(0, 1000)
    plt.ylim(0, 1000)

    plt.gca().set_aspect('equal', adjustable='box')
    plt.show()
Пример #2
0
def ground_filter_aligned_data(fn, args):
    #[pointcloud_path, ground_filtering_out_dir, r, x_offset, y_offset, geoid, sigma_geoid] = args
    pts_dir, ref_dir, tmp_dir, out_dir, r, x_offset, y_offset, geoid, sigma_geoid, radius, res_list = args
    
    m,n = fn[:17].split('_')
    [mm,nn] = coord(m, n, r, x_offset, y_offset)

    if fn not in os.listdir(ref_dir):
        return False
    
    # Load mms
    data_mms = read_bin_xyzrid_scale(pts_dir + fn, 12)
    
    # Rough filter based on given DTM
    data_mms = filter_by_reference(data_mms, ref_dir + fn, geoid, sigma_geoid)
    
    if len(data_mms) < 200:
        return False

    data_mms = global2local(data_mms, mm, nn)
    reduced, _  = ground_filter(data_mms, radius, res_list, r, is_plot = False)
    
    if len(reduced) < 200:
        return False

    write_points_double(local2global(reduced, mm, nn)[:,:3], 
                        out_dir + fn)
    return True
Пример #3
0
def load_aligned_data_runid(fn, pointcloud_path, ref_out_dir):

    # Get origin from filename
    m, n = fn[:17].split('_')
    [mm, nn] = coord(m, n, r, x_offset, y_offset)

    # Load reference dtm
    data_ref = np.array(read_bin(ref_out_dir + fn, 7))

    # Height range of the point cloud
    height_max, height_min = max(data_ref[:, 2]) + geoid + sigma_geoid, min(
        data_ref[:, 2]) + geoid - sigma_geoid

    # Load mms data
    #data_mms = read_bin_xyz_scale(pointcloud_path + fn, 10)         # 40m Ricklingen
    #data_mms = read_bin_xyz_norm_scale(pointcloud_path + fn, 13)    # Broken tiles
    #data_mms = read_bin_xyzr_scale(pointcloud_path + fn, 11)        # 25m Hildesheim
    data_mms = read_bin_xyzrid_scale(pointcloud_path + fn,
                                     12)  # 25m Hildesheim
    data_mms = np.array(data_mms)

    # Remove points based on reference dtm
    data_mms = data_mms[(data_mms[:, 2] > height_min) *
                        (data_mms[:, 2] < height_max)]

    # Get runids and points
    data_runids = data_mms[:, 4]
    data_mms = data_mms[:, 0:3] - [mm, nn, 0]

    return data_mms, data_runids
Пример #4
0
def plot_tiles(fns, args):

    from matplotlib.collections import PatchCollection
    from matplotlib.patches import Rectangle

    _, _, _, _, r, x_offset, y_offset, _, _, _, _ = args

    # Get origin from initial filename
    m, n = fns[0][:17].split('_')
    [mm0, nn0] = coord(m, n, r, x_offset, y_offset)

    # Create figure and axes
    fig, ax = plt.subplots(1)

    patches = []

    for fn in fns:

        # Get origin from filename
        m, n = fn[:17].split('_')
        [mm, nn] = coord(m, n, r, x_offset, y_offset)

        mm = float(mm) - mm0
        nn = float(nn) - nn0

        # Create a Rectangle patch
        rect = Rectangle((mm, nn),
                         r,
                         r,
                         linewidth=1,
                         edgecolor='r',
                         facecolor='r')
        patches.append(rect)

    collection = PatchCollection(patches, cmap=plt.cm.jet, alpha=0.8)

    #collection.set_clim(-0.5, 0.5)
    ax.add_collection(collection)

    plt.xlim(0, 1000)
    plt.ylim(0, 1000)

    plt.gca().set_aspect('equal', adjustable='box')
    plt.show()
Пример #5
0
def load_mms(fn, args):

    mms_dir, _, _, r, x_offset, y_offset, _, _ = args

    # Get origin from filename
    m, n = fn[:17].split('_')
    [mm, nn] = coord(m, n, r, x_offset, y_offset)

    # Load points
    try:  # Some of are ddd, and some are ddfi
        data_mms = read_bin_double(mms_dir + fn, 7)
    except:
        data_mms = read_bin_xyz_scale(mms_dir + fn, 8)
        data_mms = data_mms[:, :3]
        print('Changed loaded...', fn)

    data_mms = global2local(data_mms, mm, nn)
    return data_mms
Пример #6
0
def apply_height_updates_folder(list_pts,
                                pts_dir,
                                dict_update_pts,
                                res_ref,
                                res_update,
                                out_dir,
                                args,
                                global_shift=0,
                                is_xyz=False):

    r, x_offset, y_offset = args

    for fn in tqdm(list_pts):

        m, n = fn[:17].split('_')
        [mm, nn] = coord(m, n, r, x_offset, y_offset)

        # Apply updates
        data_updates = dict_update_pts[fn]

        # Load mms original points
        if is_xyz:
            data_mms = load_corr_mms(fn, pts_dir, args)

        else:
            data_mms = read_bin_xyzrid_scale(pts_dir + fn, 12)

            # Trans to local system
            data_mms = global2local(data_mms, mm, nn)

        data_updated = apply_height_updates(data_mms, data_updates, res_update,
                                            r, global_shift)

        # Write updated points
        if len(data_updated) > 0:
            write_points_double(local2global(data_updated[:, :3], mm, nn),
                                out_dir + '//' + fn)
Пример #7
0
    dict_shift_value = np.load(tmp_dir + project_name + "_shift.npy",
                               allow_pickle=True)[0]
    dict_shift_value = shifts_cleaning(dict_shift_value, list_mms)

if 1:
    from tqdm import tqdm
    from lib.util import local2global
    from lib.load import load_mms
    args = mms_dir, ref_dir, res_ref, r, x_offset, y_offset, geoid, sigma_geoid

    for fn in tqdm(list_mms):

        #print(fn)

        m, n = fn[:17].split('_')
        [mm, nn] = coord(m, n, r, x_offset, y_offset)

        data_ref = read_bin(ref_dir + fn, 7)
        data_mms = load_mms(fn, args)
        #data_mms = read_bin(mms_dir + fn, 7)
        #data_mms = read_bin_double(mms_dir + fn, 7)
        #data_mms = global2local(data_mms, mm, nn)

        d_ref = rasterize(data_ref, res_ref, dim=2)
        d_mms = rasterize(data_mms, res_ref, dim=2)

        data_mms = np.array(data_mms)
        data_ref = np.array(data_ref)

        index_list = []
Пример #8
0
def calc_height_diff_grunid(grunid, queried_fns, args, fn_shifts_runid, fn_shiftimg_runid, 
                            is_save=True):
    # For a given runid group, calculate the difference to the other runids
    from lib.reference import filter_by_reference
    from lib.shift import calculate_tile_runid_shift
    
    pts_dir, ref_dir, tmp_dir, out_dir, r, x_offset, y_offset, geoid, sigma_geoid, radius, res_list = args
    
    dict_shifts_runid = dict()
    dict_shiftimg_runid = dict()
    
    for fn in tqdm(queried_fns):
        
        # Get origin from filename
        m,n = fn[:17].split('_')
        [mm,nn] = coord(m, n, r, x_offset, y_offset)
            
        if fn.split('.')[0] + '_changedx.ply' in os.listdir(out_dir):
            # Load points
            data_mms = read_bin_xyz_scale(out_dir + fn.split('.')[0] + '_changedx.ply', 8)
            print('read', fn.split('.')[0] + '_changedx.ply')
        else:
            # Load mms
            data_mms = read_bin_xyzrid_scale(pts_dir + fn, 12)
            # Rough filter based on given DTM
            data_mms = filter_by_reference(data_mms, ref_dir + fn, 
                                           geoid, sigma_geoid)
            data_mms = data_mms[:,[0,1,2,4]] # Remove reflectance
            
        if len(data_mms) < 200:
            continue
        
        # Get xyz, relectance and runids
        data_mms = global2local(data_mms, mm, nn)
        
        # Get mask for select grunid
        mask = generate_mask_grunid(data_mms[:,3], grunid)
        data_mms_grunid = data_mms[mask]
        data_mms_others = data_mms[~mask]
        
        if len(data_mms_grunid) < 200:
            continue

        # Ground filter seperately
        reduced_grunid, _  = ground_filter(data_mms_grunid, radius, res_list, r, cleaning = [])
        reduced_others, _  = ground_filter(data_mms_others, radius, res_list, r, cleaning = [])
        
        shift, shift_img = calculate_tile_runid_shift(reduced_grunid, reduced_others, 
                                                      res_ref=1.0, reject_threshold=1.0, r=r)
        
        # If the point are too less, ignore the points and save others
        if shift==None:
            save_pts = data_mms_others
        else:
            save_pts = data_mms
            
        if is_save:
            write_points_ddfi(local2global(save_pts, mm, nn), 
                              out_dir + fn.split('.')[0] + '_changed.ply')
        
        dict_shifts_runid[fn] = shift
        dict_shiftimg_runid[fn] = shift_img
    
    if is_save: 
        np.save(tmp_dir + fn_shifts_runid, [dict_shifts_runid, 0])
        np.save(tmp_dir + fn_shiftimg_runid, [dict_shiftimg_runid, 0]) 
    
    return dict_shifts_runid, dict_shiftimg_runid
Пример #9
0
def gen_dtm_runid(grunid, queried_fns, d_shifts_runid, args, res_update):
    # Create update values for select grunid
    
    from lib.adapt_height import check_update_necessity, update_pointcloud
    
    pts_dir, ref_dir, tmp_dir, out_dir, r, x_offset, y_offset, geoid, sigma_geoid, radius, res_list = args
    
    for fn in tqdm(queried_fns):    
        
        print(fn)
        
        # Get origin from filename
        m,n = fn[:17].split('_')
        [mm,nn] = coord(m, n, r, x_offset, y_offset)
        
        if fn.split('.')[0] + '_changed.ply' not in os.listdir(out_dir):
            continue
        
        if str(grunid[0]) + "_updated__" + fn in os.listdir(out_dir):
            continue
        
        # Load points
        data_mms = read_bin_xyz_scale(out_dir + fn.split('.')[0] + '_changed.ply', 8)
        data_mms = global2local(data_mms, mm, nn)
        
        # Get mask for select grunid
        mask = generate_mask_grunid(data_mms[:,3], grunid)
        data_mms_grunid = data_mms[mask]
        data_mms_others = data_mms[~mask]
        
        if len(data_mms_grunid)<200:
            print(fn, 'ignored because too less mms points')
            continue
        
        #data_mms_grunid = read_bin_double(out_dir + fn.split('.')[0] + '_grunid.ply', 7)
        #data_mms_others = read_bin_double(out_dir + fn.split('.')[0] + '_others.ply', 7)
        #data_mms_grunid = global2local(data_mms_grunid, mm, nn)
        #data_mms_others = global2local(data_mms_others, mm, nn)
                
        for nfn in search_neigh_tiles(fn):
            if nfn in d_shifts_runid:
                print(nfn, d_shifts_runid[nfn])
            else:
                print(nfn, "not found 0")
        
        if check_update_necessity(search_neigh_tiles(fn), d_shifts_runid):
        
            neigh_list = search_neigh_tiles(fn)
            data_update, z = generate_updates_mms(d_shifts_runid, neigh_list, r, res_update)
            
            # Only change selected runid
            mms_updated = update_pointcloud(data_mms_grunid, data_update, res_update)
            updated_pointcloud = np.vstack([mms_updated, data_mms_others])
            
            # Update the point clouds
            write_points_ddfi(local2global(updated_pointcloud.copy(), mm, nn), 
                              out_dir + fn.split('.')[0] + '_changedx.ply')
            
            reduced_pointcloud, _  = ground_filter(updated_pointcloud, radius, res_list, r) 
            identifier = "_updated__"               
        else:
            data_mms = np.vstack([data_mms_grunid, data_mms_others])
            reduced_pointcloud, _  = ground_filter(data_mms, radius, res_list, r)
            identifier = "_original_" 
            
        if len(reduced_pointcloud)>200: 
            write_points_ddfi(local2global(reduced_pointcloud.copy(), mm, nn), 
                              out_dir + str(grunid[0]) + identifier + fn)
Пример #10
0
def read_fn(fn, r, x_offset, y_offset):
    m, n = fn.split('_')
    [mm, nn] = coord(m, n, r, x_offset, y_offset)
    return mm, nn