예제 #1
0
파일: preprocess.py 프로젝트: tangwudu/s2p
def minmax_color_on_tile(tile_info):
    """
    Compute min and max intensities on a given tile and save them to a txt file.

    Args:
        tile_info: dictionary containing all the information needed to process
            the tile
    """
    # read info
    img1 = cfg['images'][0]['img']
    coords = tile_info['coordinates']
    tile_dir = tile_info['directory']
    z = cfg['subsampling_factor']

    # output files
    crop_ref = os.path.join(tile_dir, 'roi_ref.tif')
    local_minmax = os.path.join(tile_dir, 'local_minmax.txt')

    # do the job
    common.cropImage(img1, crop_ref, *coords, zoom=z)
    if os.path.isfile(os.path.join(tile_dir, 'this_tile_is_masked.txt')):
        print 'tile %s is masked, skip' % tile_dir
    elif os.path.isfile(os.path.join(tile_dir, 'local_minmax.txt')) and cfg['skip_existing']:
        print 'extrema intensities on tile %s already computed, skip' % tile_dir
    else:
        common.image_getminmax(crop_ref, local_minmax)
예제 #2
0
파일: preprocess.py 프로젝트: jguinet/s2p
def minmax_color_on_tile(tile_info):
    """
    Compute min and max intensities on a given tile and save them to a txt file.

    Args:
        tile_info: dictionary containing all the information needed to process
            the tile
    """
    # read info
    img = cfg['images'][0]['img']
    coords = tile_info['coordinates']
    tile_dir = tile_info['directory']
    z = cfg['subsampling_factor']

    # output files
    crop_ref = os.path.join(tile_dir, 'roi_ref.tif')
    local_minmax = os.path.join(tile_dir, 'local_minmax.txt')

    # do the job
    common.cropImage(img, crop_ref, *coords, zoom=z)
    if os.path.isfile(os.path.join(tile_dir, 'this_tile_is_masked.txt')):
        print 'tile %s is masked, skip' % tile_dir
    elif os.path.isfile(os.path.join(
            tile_dir, 'local_minmax.txt')) and cfg['skip_existing']:
        print 'extrema intensities on tile %s already computed, skip' % tile_dir
    else:
        common.image_getminmax(crop_ref, local_minmax)
예제 #3
0
파일: process.py 프로젝트: jguinet/s2p
def finalize_tile(tile_info, height_maps):
    """
    Finalize the processing of a tile.

    Merge the height maps from the N pairs, remove overlapping areas, get the
    colors from a XS image and use it to color and generate a ply file
    (colorization is not mandatory)

    Args:
        tile_info: a dictionary that provides all you need to process a tile
        height_maps: list of the height maps generated from N pairs
    """
    # get info
    tile_dir = tile_info['directory']
    nb_pairs = tile_info['number_of_pairs']
    x, y, w, h = tile_info['coordinates']
    ov = tile_info['overlap']
    pos = tile_info['position_type']
    img1, rpc1 = cfg['images'][0]['img'], cfg['images'][0]['rpc']

    # merge the n height maps
    local_merged_height_map = os.path.join(tile_dir,
                                           'local_merged_height_map.tif')
    if len(height_maps) > 1:
        merge_height_maps(height_maps, tile_dir, cfg['fusion_thresh'],
                          cfg['fusion_conservative'], 1, [])
    else:
        common.run('cp %s %s' % (height_maps[0], local_merged_height_map))

    # remove overlapping areas
    # By tile
    local_merged_height_map = tile_dir + '/local_merged_height_map.tif'
    local_merged_height_map_crop = tile_dir + '/local_merged_height_map_crop.tif'
    crop_ref = tile_dir + '/roi_ref.tif'
    crop_ref_crop = tile_dir + '/roi_ref_crop.tif'

    dicoPos = {}
    dicoPos['M'] = [ov / 2, ov / 2, -ov, -ov]
    dicoPos['L'] = [0, ov / 2, -ov / 2, -ov]
    dicoPos['R'] = [ov / 2, ov / 2, -ov / 2, -ov]
    dicoPos['U'] = [ov / 2, 0, -ov, -ov / 2]
    dicoPos['B'] = [ov / 2, ov / 2, -ov, -ov / 2]
    dicoPos['UL'] = [0, 0, -ov / 2, -ov / 2]
    dicoPos['UR'] = [ov / 2, 0, -ov / 2, -ov / 2]
    dicoPos['BR'] = [ov / 2, ov / 2, -ov / 2, -ov / 2]
    dicoPos['BL'] = [0, ov / 2, -ov / 2, -ov / 2]
    dicoPos['Single'] = [0, 0, 0, 0]

    z = cfg['subsampling_factor']
    newcol, newrow, difftw, diffth = np.array(dicoPos[pos]) / z
    x = x / z + newcol
    y = y / z + newrow
    w = w / z + difftw
    h = h / z + diffth
    tile_info['coordinates'] = (x, y, w, h)
    
    # z=1 beacause local_merged_height_map, crop_ref (and so forth) have
    # already been zoomed. So don't zoom again to crop these images.
    common.cropImage(local_merged_height_map, local_merged_height_map_crop,
                     newcol, newrow, w, h)
    common.cropImage(crop_ref, crop_ref_crop, newcol, newrow, w, h)

    # by pair
    for i in range(1, nb_pairs + 1):
        single_height_map = os.path.join(tile_dir, 'pair_%d/height_map.tif' % i)
        single_height_map_crop = os.path.join(tile_dir, 'pair_%d/height_map_crop.tif' % i)
        single_rpc_err = os.path.join(tile_dir, 'pair_%d/rpc_err.tif' % i)
        single_rpc_err_crop = os.path.join(tile_dir, 'pair_%d/rpc_err_crop.tif' % i)
        common.cropImage(single_height_map, single_height_map_crop, newcol,
                         newrow, w, h)
        common.cropImage(single_rpc_err, single_rpc_err_crop, newcol, newrow, w, h)
    # colors
    color_crop_ref(tile_info, cfg['images'][0]['clr'])

    # generate cloud
    generate_cloud(tile_info, cfg['offset_ply'])
예제 #4
0
파일: process.py 프로젝트: tangwudu/s2p
def finalize_tile(tile_info, height_maps):
    """
    Finalize the processing of a tile.

    Merge the height maps from the N pairs, remove overlapping areas, get the
    colors from a XS image and use it to color and generate a ply file
    (colorization is not mandatory)

    Args:
        tile_info: a dictionary that provides all you need to process a tile
        height_maps: list of the height maps generated from N pairs
    """
    # get info
    tile_dir = tile_info['directory']
    nb_pairs = tile_info['number_of_pairs']
    x, y, w, h = tile_info['coordinates']
    ov = tile_info['overlap']
    pos = tile_info['position_type']
    img1, rpc1 = cfg['images'][0]['img'], cfg['images'][0]['rpc']

    # merge the n height maps
    local_merged_height_map = os.path.join(tile_dir,
                                           'local_merged_height_map.tif')
    if len(height_maps) > 1:
        merge_height_maps(height_maps, tile_dir, cfg['fusion_thresh'],
                          cfg['fusion_conservative'], 1, [])
    else:
        common.run('cp %s %s' % (height_maps[0], local_merged_height_map))

    # remove overlapping areas
    # By tile
    local_merged_height_map = tile_dir + '/local_merged_height_map.tif'
    local_merged_height_map_crop = tile_dir + '/local_merged_height_map_crop.tif'
    crop_ref = tile_dir + '/roi_ref.tif'
    crop_ref_crop = tile_dir + '/roi_ref_crop.tif'

    dicoPos = {}
    dicoPos['M'] = [ov / 2, ov / 2, -ov, -ov]
    dicoPos['L'] = [0, ov / 2, -ov / 2, -ov]
    dicoPos['R'] = [ov / 2, ov / 2, -ov / 2, -ov]
    dicoPos['U'] = [ov / 2, 0, -ov, -ov / 2]
    dicoPos['B'] = [ov / 2, ov / 2, -ov, -ov / 2]
    dicoPos['UL'] = [0, 0, -ov / 2, -ov / 2]
    dicoPos['UR'] = [ov / 2, 0, -ov / 2, -ov / 2]
    dicoPos['BR'] = [ov / 2, ov / 2, -ov / 2, -ov / 2]
    dicoPos['BL'] = [0, ov / 2, -ov / 2, -ov / 2]
    dicoPos['Single'] = [0, 0, 0, 0]

    z = cfg['subsampling_factor']
    newcol, newrow, difftw, diffth = np.array(dicoPos[pos]) / z
    x = x / z + newcol
    y = y / z + newrow
    w = w / z + difftw
    h = h / z + diffth

    # z=1 beacause local_merged_height_map, crop_ref (and so forth) have
    # already been zoomed. So don't zoom again to crop these images.
    common.cropImage(local_merged_height_map, local_merged_height_map_crop,
                     newcol, newrow, w, h)
    common.cropImage(crop_ref, crop_ref_crop, newcol, newrow, w, h)

    # by pair
    for i in range(1, nb_pairs + 1):
        single_height_map = os.path.join(tile_dir,
                                         'pair_%d/height_map.tif' % i)
        single_height_map_crop = os.path.join(
            tile_dir, 'pair_%d/height_map_crop.tif' % i)
        single_rpc_err = os.path.join(tile_dir, 'pair_%d/rpc_err.tif' % i)
        single_rpc_err_crop = os.path.join(tile_dir,
                                           'pair_%d/rpc_err_crop.tif' % i)
        common.cropImage(single_height_map, single_height_map_crop, newcol,
                         newrow, w, h)
        common.cropImage(single_rpc_err, single_rpc_err_crop, newcol, newrow,
                         w, h)
    # colors
    color_crop_ref(tile_info, cfg['images'][0]['clr'])

    # generate cloud
    generate_cloud(tile_info, cfg['offset_ply'])
예제 #5
0
파일: process.py 프로젝트: cpalmann/s2p
def finalize_tile(tile_info, height_maps, utm_zone=None):
    """
    Finalize the processing of a tile.

    Merge the height maps from the N pairs, remove overlapping areas, get the
    colors from a XS image and use it to color and generate a ply file
    (colorization is not mandatory)

    Args:
        tile_info: a dictionary that provides all you need to process a tile
        height_maps: list of the height maps generated from N pairs
    """
    # get info
    tile_dir = tile_info["directory"]
    nb_pairs = tile_info["number_of_pairs"]
    x, y, w, h = tile_info["coordinates"]
    ov = tile_info["overlap"]
    pos = tile_info["position_type"]
    img1, rpc1 = cfg["images"][0]["img"], cfg["images"][0]["rpc"]

    # merge the n height maps
    local_merged_height_map = os.path.join(tile_dir, "local_merged_height_map.tif")
    if len(height_maps) > 1:
        merge_height_maps(height_maps, tile_dir, cfg["fusion_thresh"], cfg["fusion_conservative"], 1, [])
    elif len(height_maps) == 0:
        return
    else:
        common.run("cp %s %s" % (height_maps[0], local_merged_height_map))

    # remove overlapping areas
    # By tile
    local_merged_height_map = tile_dir + "/local_merged_height_map.tif"
    local_merged_height_map_crop = tile_dir + "/local_merged_height_map_crop.tif"
    crop_ref = tile_dir + "/roi_ref.tif"
    crop_ref_crop = tile_dir + "/roi_ref_crop.tif"

    dicoPos = {}
    dicoPos["M"] = [ov / 2, ov / 2, -ov, -ov]
    dicoPos["L"] = [0, ov / 2, -ov / 2, -ov]
    dicoPos["R"] = [ov / 2, ov / 2, -ov / 2, -ov]
    dicoPos["U"] = [ov / 2, 0, -ov, -ov / 2]
    dicoPos["B"] = [ov / 2, ov / 2, -ov, -ov / 2]
    dicoPos["UL"] = [0, 0, -ov / 2, -ov / 2]
    dicoPos["UR"] = [ov / 2, 0, -ov / 2, -ov / 2]
    dicoPos["BR"] = [ov / 2, ov / 2, -ov / 2, -ov / 2]
    dicoPos["BL"] = [0, ov / 2, -ov / 2, -ov / 2]
    dicoPos["Single"] = [0, 0, 0, 0]

    z = cfg["subsampling_factor"]
    newcol, newrow, difftw, diffth = np.array(dicoPos[pos]) / z
    x = x / z + newcol
    y = y / z + newrow
    w = w / z + difftw
    h = h / z + diffth
    tile_info["coordinates"] = (x, y, w, h)

    # z=1 beacause local_merged_height_map, crop_ref (and so forth) have
    # already been zoomed. So don't zoom again to crop these images.
    if not (os.path.isfile(local_merged_height_map_crop) and cfg["skip_existing"]):
        common.cropImage(local_merged_height_map, local_merged_height_map_crop, newcol, newrow, w, h)
    if not (os.path.isfile(crop_ref_crop) and cfg["skip_existing"]):
        common.cropImage(crop_ref, crop_ref_crop, newcol, newrow, w, h)

    # by pair
    for i in range(1, nb_pairs + 1):
        single_height_map = os.path.join(tile_dir, "pair_%d/height_map.tif" % i)
        single_height_map_crop = os.path.join(tile_dir, "pair_%d/height_map_crop.tif" % i)
        single_rpc_err = os.path.join(tile_dir, "pair_%d/rpc_err.tif" % i)
        single_rpc_err_crop = os.path.join(tile_dir, "pair_%d/rpc_err_crop.tif" % i)
        if not (os.path.isfile(single_height_map_crop) and cfg["skip_existing"]):
            common.cropImage(single_height_map, single_height_map_crop, newcol, newrow, w, h)
        if not (os.path.isfile(single_rpc_err_crop) and cfg["skip_existing"]):
            common.cropImage(single_rpc_err, single_rpc_err_crop, newcol, newrow, w, h)
    # colors
    color_crop_ref(tile_info, cfg["images"][0]["clr"])

    # generate cloud
    generate_cloud(tile_info, cfg["offset_ply"], utm_zone)