Exemplo n.º 1
0
def merge_height_maps(height_maps,
                      tile_dir,
                      thresh,
                      conservative,
                      k=1,
                      garbage=[]):
    """
    Merges a list of height maps recursively, computed for one tile from N image pairs.

    Args :
         - height_maps : list of height map directories
         - tile_dir : directory of the tile from which to get a merged height map
         - thresh : threshold used for the fusion algorithm, in meters.
         - conservative (optional, default is False): if True, keep only the
            pixels where the two height map agree (fusion algorithm)
         - k : used to identify the current call of merge_height_maps (default = 1, first call)
         - garbage : a list used to remove temp data (default = [], first call)

    """

    # output file
    local_merged_height_map = tile_dir + '/local_merged_height_map.tif'

    if len(height_maps) == 0:
        return

    if os.path.isfile(local_merged_height_map) and cfg['skip_existing']:
        print 'final height map %s already done, skip' % local_merged_height_map
    else:
        list_height_maps = []
        for i in range(len(height_maps) - 1):
            height_map = tile_dir + '/height_map_' + \
                str(i) + '_' + str(i + 1) + '_' + str(k) + '.tif'
            fusion.merge(height_maps[i], height_maps[i + 1], thresh,
                         height_map, conservative)
            list_height_maps.append(height_map)
            garbage.append(height_map)

        if len(list_height_maps) > 1:
            merge_height_maps(list_height_maps, tile_dir, thresh, conservative,
                              k + 1, garbage)
        else:
            common.run('cp %s %s' %
                       (list_height_maps[0], local_merged_height_map))
            for imtemp in garbage:
                common.run('rm -f %s' % imtemp)
Exemplo n.º 2
0
def merge_height_maps(height_maps, tile_dir, thresh, conservative, k=1, garbage=[]):
    """
    Merges a list of height maps recursively, computed for one tile from N image pairs.

    Args :
         - height_maps : list of height map directories
         - tile_dir : directory of the tile from which to get a merged height map
         - thresh : threshold used for the fusion algorithm, in meters.
         - conservative (optional, default is False): if True, keep only the
            pixels where the two height map agree (fusion algorithm)
         - k : used to identify the current call of merge_height_maps (default = 1, first call)
         - garbage : a list used to remove temp data (default = [], first call)

    """

    # output file
    local_merged_height_map = tile_dir + '/local_merged_height_map.tif'

    if os.path.isfile(local_merged_height_map) and cfg['skip_existing']:
        print 'final height map %s already done, skip' % local_merged_height_map
    else:
        list_height_maps = []
        for i in range(len(height_maps) - 1):
            height_map = tile_dir + '/height_map_' + \
                str(i) + '_' + str(i + 1) + '_' + str(k) + '.tif'
            fusion.merge(height_maps[i], height_maps[i + 1], thresh, height_map,
                         conservative)
            list_height_maps.append(height_map)
            garbage.append(height_map)

        if len(list_height_maps) > 1:
            merge_height_maps(list_height_maps, tile_dir,
                              thresh, conservative, k + 1, garbage)
        else:
            common.run('cp %s %s' %
                       (list_height_maps[0], local_merged_height_map))
            for imtemp in garbage:
                common.run('rm -f %s' % imtemp)
Exemplo n.º 3
0
def process_triplet(out_dir, img1, rpc1, img2, rpc2, img3, rpc3, x=None, y=None,
                    w=None, h=None, thresh=3, tile_w=None, tile_h=None,
                    overlap=None, prv1=None, cld_msk=None, roi_msk=None):
    """
    Computes a height map from three Pleiades images.

    Args:
        out_dir: path to the output directory
        img1: path to the reference image.
        rpc1: paths to the xml file containing the rpc coefficients of the
            reference image
        img2: path to the secondary image of the first pair
        rpc2: paths to the xml file containing the rpc coefficients of the
            secondary image of the first pair
        img3: path to the secondary image of the second pair
        rpc3: paths to the xml file containing the rpc coefficients of the
            secondary image of the second pair
        x, y, w, h: four integers defining the rectangular ROI in the reference
            image. (x, y) is the top-left corner, and (w, h) are the dimensions
            of the rectangle. The ROI may be as big as you want, as it will be
            cutted into small tiles for processing.
        thresh: threshold used for the fusion algorithm, in meters.
        tile_w, tile_h: dimensions of the tiles
        overlap: width of overlapping bands between tiles
        prv1 (optional): path to a preview of the reference image
        cld_msk (optional): path to a gml file containing a cloud mask
        roi_msk (optional): path to a gml file containing a mask defining the
            area contained in the full image.

    Returns:
        Nothing
    """
    # create a directory for the experiment
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    # duplicate stdout and stderr to log file
    tee.Tee('%s/stdout.log' % out_dir, 'w')

    # select ROI
    try:
        print "ROI x, y, w, h = %d, %d, %d, %d" % (x, y, w, h)
    except TypeError:
        x, y, w, h = common.get_roi_coordinates(rpc1, prv1)
        print "ROI x, y, w, h = %d, %d, %d, %d" % (x, y, w, h)

    # process the two pairs
    out_dir_left = '%s/left' % out_dir
    height_map_left = process_pair(out_dir_left, img1, rpc1, img2, rpc2, x, y,
                                   w, h, tile_w, tile_h, overlap, cld_msk,
                                   roi_msk)

    out_dir_right = '%s/right' % out_dir
    height_map_right = process_pair(out_dir_right, img1, rpc1, img3, rpc3, x,
                                    y, w, h, tile_w, tile_h, overlap, cld_msk,
                                    roi_msk)

    # merge the two height maps
    height_map = '%s/height_map.tif' % out_dir
    fusion.merge(height_map_left, height_map_right, thresh, height_map)

    common.garbage_cleanup()
    return height_map