def download_crop(outfile, asset, aoi, aoi_type): """ Download a crop defined in geographic coordinates using gdal or rasterio. Args: outfile (string): path to the output file asset (dict): dictionary containing the image information aoi (geojson.Polygon or 6-tuple): either a (lon, lat) polygon or a UTM rectangle (ulx, uly, lrx, lry, utm_zone, lat_band), where ulx, uly (floats): x/y UTM coordinates of the upper left (ul) corner lrx, lry (floats): x/y UTM coordinates of the lower right (lr) corner utm_zone (int): number between 1 and 60 indicating the UTM zone with respect to which the UTM coordinates have to be interpreted. lat_band (string): letter between C and X indicating the latitude band. aoi_type (string): "lonlat_polygon" or "utm_rectangle" """ url = poll_activation(asset) if url is not None: if aoi_type == "utm_rectangle": utils.crop_with_gdal_translate(outfile, url, *aoi) elif aoi_type == "lonlat_polygon": with rasterio.open(url, 'r') as src: rpc_tags = src.tags(ns='RPC') crop, x, y = utils.crop_aoi(url, aoi) utils.rio_write(outfile, crop, tags={'CROP_OFFSET_XY': '{} {}'.format(x, y)}, namespace_tags={'RPC': rpc_tags})
def sift_roi(file1, file2, aoi, z): """ Args: file1, file2 (str): paths or urls to two GeoTIFF images aoi (geojson.Polygon): area of interest z (float): base altitude for the aoi Returns: two numpy arrays with the coordinates of the matching points in the original (full-size) image domains """ # image crops crop1, x1, y1 = utils.crop_aoi(file1, aoi, z=z) crop2, x2, y2 = utils.crop_aoi(file2, aoi, z=z) # sift keypoint matches p1, p2 = match_pair(crop1, crop2) q1 = utils.points_apply_homography(utils.matrix_translation(x1, y1), p1) q2 = utils.points_apply_homography(utils.matrix_translation(x2, y2), p2) return q1, q2
def sift_roi(file1, file2, aoi, z): """ Args: file1, file2: filename of two satellite images aoi: area of interest z: base height for the aoi Returns: q1, q2: numpy arrays with the coordinates of the matching points in the original (full-size) image domains """ # image crops crop1, x1, y1 = utils.crop_aoi(file1, aoi, z=z) crop2, x2, y2 = utils.crop_aoi(file2, aoi, z=z) # sift keypoint matches p1, p2 = match_pair(crop1, crop2) q1 = utils.points_apply_homography(matrix_translation(x1, y1), p1) q2 = utils.points_apply_homography(matrix_translation(x2, y2), p2) return q1, q2
def trace_epipolar_curve(image1, image2, aoi, x0, y0): """auxiliary function to display in image2 the epipolar curve corresponding to the point x0,y0 in the cropped image1""" import matplotlib.pyplot as plt # get the altitude of the center of the AOI lon, lat = aoi['center'] z = srtm4.srtm4(lon, lat) # read the RPC coefficients of images i and j rpc1 = utils.rpc_from_geotiff(image1) rpc2 = utils.rpc_from_geotiff(image2) # crop the two images im1, x1, y1 = utils.crop_aoi(image1, aoi, z) im2, x2, y2 = utils.crop_aoi(image2, aoi, z) # translation matrices needed to compensate the crop offset H1 = matrix_translation(x1, y1) H2 = matrix_translation(x2, y2) # select a point in the first image #x0, y0 = 200, 200 # compensate the crop offset of the first image x, y = np.dot(H1, [x0, y0, 1])[:2] # compute the epipolar curve epi = epipolar_curve(rpc1, rpc2, x, y) # compensate for the crop offset of the second image p = np.array([np.dot(np.linalg.inv(H2), [x, y, 1])[:2] for x, y in epi]) # plot the epipolar curve on the second image f, ax = plt.subplots(1, 2, figsize=(13, 10)) ax[0].plot(x0, y0, 'r+') ax[1].plot(p[:, 0], p[:, 1], 'r-') ax[0].imshow(np.sqrt(im1.squeeze()), cmap='gray') ax[1].imshow(np.sqrt(im2.squeeze()), cmap='gray')
def crop_rectangular(image, aoi, base_h=0): a, _, _ = utils.crop_aoi(image, aoi, base_h) return a
def crop_vertical(image, aoi, base_h=0): rpc = utils.rpc_from_geotiff(image) a, _, _ = utils.crop_aoi(image, aoi, base_h) R = build_verticalizing_rotation(rpc, a.shape) Ra = ndimage.affine_transform(a.T, np.linalg.inv(R)).T return Ra