示例#1
0
文件: process.py 项目: yidongVSI/s2p
def generate_cloud(tile_info, do_offset=False, utm_zone=None):
    """
    Args:
        tile_info: a dictionary that provides all you need to process a tile
        do_offset (optional, default: False): boolean flag to decide wether the
            x, y coordinates of points in the ply file will be translated or not
            (translated to be close to 0, to avoid precision loss due to huge
            numbers)
    """
    print "\nComputing point cloud..."

    # get info
    tile_dir = tile_info['directory']
    x, y, w, h = tile_info['coordinates']
    img1, rpc1 = cfg['images'][0]['img'], cfg['images'][0]['rpc']

    #height_map = tile_dir + '/local_merged_height_map.tif'
    height_map = tile_dir + '/local_merged_height_map_crop.tif'
    crop_color = tile_dir + '/roi_color_ref.tif'
    if not os.path.exists(crop_color):
        crop_color = ''

    z = cfg['subsampling_factor']

    # Compute the homography transforming the coordinates system of the
    # original full size image into the coordinates system
    # of the crop we are dealing with
    # col and row have been divided by z inside 'finalize_tile' for
    # convinience; col*z and row*z allow to get the initial values back.
    A = common.matrix_translation(-x * z, -y * z)
    z = cfg['subsampling_factor']
    f = 1.0 / z
    Z = np.diag([f, f, 1])
    A = np.dot(Z, A)
    trans = tile_dir + '/trans.txt'
    np.savetxt(trans, A, fmt='%9.3f')

    # compute coordinates (offsets) of the point we want to use as origin in
    # the local coordinate system of the computed cloud
    if do_offset:
        r = rpc_model.RPCModel(rpc1)
        lat = r.latOff
        lon = r.lonOff
        off_x, off_y = geographiclib.geodetic_to_utm(lat, lon)[0:2]
    else:
        off_x, off_y = 0, 0

    # output
    cloud = tile_dir + '/cloud.ply'

    triangulation.compute_point_cloud(cloud,
                                      height_map,
                                      rpc1,
                                      trans,
                                      crop_color,
                                      off_x,
                                      off_y,
                                      utm_zone=utm_zone)

    common.garbage_cleanup()
示例#2
0
文件: process.py 项目: jguinet/s2p
def generate_cloud(tile_info, do_offset=False):
    """
    Args:
        tile_info: a dictionary that provides all you need to process a tile
        do_offset (optional, default: False): boolean flag to decide wether the
            x, y coordinates of points in the ply file will be translated or not
            (translated to be close to 0, to avoid precision loss due to huge
            numbers)
    """
    print "\nComputing point cloud..."
    # get info
    tile_dir = tile_info['directory']
    x, y, w, h = tile_info['coordinates']
    img1, rpc1 = cfg['images'][0]['img'], cfg['images'][0]['rpc']

    #height_map = tile_dir + '/local_merged_height_map.tif'
    height_map = tile_dir + '/local_merged_height_map_crop.tif'
    crop_color = tile_dir + '/roi_color_ref.tif'
    if not os.path.exists(crop_color):
        crop_color = ''

    z = cfg['subsampling_factor']

    # Compute the homography transforming the coordinates system of the
    # original full size image into the coordinates system
    # of the crop we are dealing with
    # col and row have been divided by z inside 'finalize_tile' for
    # convinience; col*z and row*z allow to get the initial values back.
    A = common.matrix_translation(-x * z, -y * z)
    z = cfg['subsampling_factor']
    f = 1.0 / z
    Z = np.diag([f, f, 1])
    A = np.dot(Z, A)
    trans = tile_dir + '/trans.txt'
    np.savetxt(trans, A, fmt='%9.3f')

    # compute coordinates (offsets) of the point we want to use as origin in
    # the local coordinate system of the computed cloud
    if do_offset:
        r = rpc_model.RPCModel(rpc1)
        lat = r.latOff
        lon = r.lonOff
        off_x, off_y = geographiclib.geodetic_to_utm(lat, lon)[0:2]
    else:
        off_x, off_y = 0, 0

    # output
    cloud = tile_dir + '/cloud.ply'

    triangulation.compute_point_cloud(cloud, height_map, rpc1, trans, crop_color,
                                      off_x, off_y)

    common.garbage_cleanup()
示例#3
0
def generate_cloud(img_name, exp_name, x, y, w, h, height_map,
    reference_image_id=1):
    """
    Args:
        img_name: name of the dataset, located in the 'pleiades_data/images'
            directory
        exp_name: string used to identify the experiment
        x, y, w, h: four integers defining the rectangular ROI in the original
            panchro image. (x, y) is the top-left corner, and (w, h) are the
            dimensions of the rectangle.
        height_map: path to the height_map, produced by the process_pair of
            process_triplet function
        reference_image_id: id (1, 2 or 3) of the image used as the reference
            image. The height map has been resampled on its grid.
    """


    rpc = 'data/%s/%04d.png.P' % (img_name, reference_image_id)
    im = 'data/%s/%04d.png' % (img_name, reference_image_id)
    im_color = 'data/%s/%04d.png' % (img_name, reference_image_id)   
    crop   = '/tmp/%s_roi_ref%02d.tif' % (exp_name, reference_image_id)
    crop_color = '/tmp/%s_roi_color_ref%02d.tif' % (exp_name, reference_image_id)
    cloud   = '/tmp/%s_cloud.ply'  % (exp_name)



    # read the zoom value
    zoom = global_params.subsampling_factor

    # colorize, then generate point cloud
    tmp_crop = common.image_crop_TIFF(im, x, y, w, h)
    tmp_crop = common.image_safe_zoom_fft(tmp_crop, zoom)
    common.run('cp %s %s' % (tmp_crop, crop))
    A = common.matrix_translation(-x, -y)
    f = 1.0/zoom
    Z = np.diag([f, f, 1])
    A = np.dot(Z, A)
    trans = common.tmpfile('.txt')
    np.savetxt(trans, A)
    
#    compute_point_cloud(common.image_qauto(crop),
#            height_map, rpc, trans, cloud)
    sz = common.image_size(crop)
    compute_point_cloud(common.image_qauto(crop),
          common.image_crop(height_map,0,0,sz[0],sz[1]) , rpc, trans, cloud)

    # cleanup
    while common.garbage:
        common.run('rm ' + common.garbage.pop())

    print "v %s %s %s" % (crop, crop_color, height_map)
    print "meshlab %s" % (cloud)
示例#4
0
文件: s2p.py 项目: jmichel-otb/s2p
def generate_cloud(out_dir, height_map, rpc1, x, y, w, h, im1, clr,
                   do_offset=False):
    """
    Args:
        out_dir: output directory. The file cloud.ply will be written there
        height_map: path to the height map, produced by the process_pair
            or process_triplet function
        rpc1: path to the xml file containing rpc coefficients for the
            reference image
        x, y, w, h: four integers defining the rectangular ROI in the original
            panchro image. (x, y) is the top-left corner, and (w, h) are the
            dimensions of the rectangle.
        im1:  path to the panchro reference image
        clr:  path to the xs (multispectral, ie color) reference image
        do_offset (optional, default: False): boolean flag to decide wether the
            x, y coordinates of points in the ply file will be translated or
            not (translated to be close to 0, to avoid precision loss due to
            huge numbers)
    """
    print "\nComputing point cloud..."

    # output files
    crop_ref = '%s/roi_ref.tif' % out_dir
    cloud = '%s/cloud.ply' % out_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    # ensure that the coordinates of the ROI are multiples of the zoom factor,
    # to avoid bad registration of tiles due to rounding problems.
    z = cfg['subsampling_factor']
    x, y, w, h = common.round_roi_to_nearest_multiple(z, x, y, w, h)

    # build the matrix of the zoom + translation transformation
    if cfg['full_img'] and z == 1:
        trans = None
    else:
        A = common.matrix_translation(-x, -y)
        f = 1.0/z
        Z = np.diag([f, f, 1])
        A = np.dot(Z, A)
        trans = '%s/trans.txt' % out_dir
        np.savetxt(trans, A)

    # compute offset
    if do_offset:
        r = rpc_model.RPCModel(rpc1)
        lat = r.latOff
        lon = r.lonOff
        off_x, off_y = geographiclib.geodetic_to_utm(lat, lon)[0:2]
    else:
        off_x, off_y = 0, 0

    # crop the ROI in ref image, then zoom
    if cfg['full_img'] and z == 1:
        crop_ref = im1
    else:
        if z == 1:
            common.image_crop_TIFF(im1, x, y, w, h, crop_ref)
        else:
            # gdal is used for the zoom because it handles BigTIFF files, and
            # before the zoom out the image may be that big
            tmp_crop = common.image_crop_TIFF(im1, x, y, w, h)
            common.image_zoom_gdal(tmp_crop, z, crop_ref, w, h)

    if cfg['color_ply']:
        crop_color = '%s/roi_color_ref.tif' % out_dir
        if clr is not None:
            print 'colorizing...'
            triangulation.colorize(crop_ref, clr, x, y, z, crop_color)
        elif common.image_pix_dim_tiffinfo(crop_ref) == 4:
            print 'the image is pansharpened fusioned'
            tmp = common.rgbi_to_rgb(crop_ref, out=None, tilewise=True)
            common.image_qauto(tmp, crop_color, tilewise=False)
        else:
            print 'no color data'
            common.image_qauto(crop_ref, crop_color, tilewise=False)
    else:
        crop_color = ''

    triangulation.compute_point_cloud(cloud, height_map, rpc1, trans, crop_color,
                                      off_x, off_y)
    common.garbage_cleanup()