def crop_corresponding_areas(out_dir, images, roi, zoom=1): """ Crops areas corresponding to the reference ROI in the secondary images. Args: out_dir: images: sequence of dicts containing the paths to input data roi: dictionary containing the ROI definition zoom: integer zoom out factor """ rpc_ref = images[0]['rpc'] for i, image in enumerate(images[1:]): x, y, w, h = rpc_utils.corresponding_roi(rpc_ref, image['rpc'], roi['x'], roi['y'], roi['w'], roi['h']) if zoom == 1: common.image_crop_TIFF(image['img'], x, y, w, h, '%s/roi_sec_%d.tif' % (out_dir, i)) else: # gdal is used for the zoom because it handles BigTIFF files, and # before the zoom out the image may be that big tmp = common.image_crop_TIFF(image['img'], x, y, w, h) common.image_zoom_gdal(tmp, zoom, '%s/roi_sec_%d.tif' % (out_dir, i), w, h)
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()