def pinhole_timings(): point_calc = PinholeCamera() point_calc.init_pinhole_from_coeffs(0.0, 0.0, 1000.0, 0.0, 0.0, 0.0, 50.0) lon_center = 0 lat_center = 0 d_lon = 500 d_lat = 500 nx = 2000 ny = 2000 ground_grid = photogrammetry_utils.create_ground_grid( lon_center - d_lon, lon_center + d_lon, lat_center - d_lat, lat_center + d_lat, nx, ny) lons = image_utils.flatten_image_band(ground_grid[0]) lats = image_utils.flatten_image_band(ground_grid[1]) alts = np.zeros_like(lats) n_loops = 4 tic = time.time() for n in range(n_loops): point_calc.world_to_image_plane(lons, lats, alts) toc = time.time() print("calculated " + str(n_loops * nx * ny) + " pixels in " + str(toc - tic) + " seconds.") print( str(n_loops * nx * ny / (toc - tic) / 1e6) + " Megapixels per second")
def create_ortho_gtiff_image_world_to_sensor(overhead_image, # type: AbstractEarthOverheadImage ortho_nx_pix, # type: int ortho_ny_pix, # type: int world_polygon, # type: Polygon world_proj=crs_defs.PROJ_4326, # type: Proj dem=None, # type: AbstractDem bands=None, # type: List[int] nodata_val=0, # type: float output_fname=None, # type: str interpolation='nearest', # type: str mask_no_data_region=False # type: bool ): # type: (...) -> GeotiffImage envelope = world_polygon.envelope minx, miny, maxx, maxy = envelope.bounds image_ground_grid_x, image_ground_grid_y = create_ground_grid(minx, maxx, miny, maxy, ortho_nx_pix, ortho_ny_pix) geo_t = world_poly_to_geo_t(envelope, ortho_nx_pix, ortho_ny_pix) if dem is None: dem = DemFactory.constant_elevation(0) dem.set_projection(crs_defs.PROJ_4326) alts = dem.get_elevations(image_ground_grid_x, image_ground_grid_y, world_proj) if bands is None: bands = list(range(overhead_image.get_metadata().get_n_bands())) images = [] if overhead_image.get_point_calculator().bands_coregistered() is not True: for band in bands: pixels_x, pixels_y = overhead_image.get_point_calculator(). \ lon_lat_alt_to_pixel_x_y(image_ground_grid_x, image_ground_grid_y, alts, band=band, world_proj=world_proj) image_data = overhead_image.read_band_from_disk(band) im_tp = image_data.dtype regridded = image_utils.grid_warp_image_band(image_data, pixels_x, pixels_y, nodata_val=nodata_val, interpolation=interpolation) regridded = regridded.astype(im_tp) images.append(regridded) else: pixels_x, pixels_y = overhead_image.get_point_calculator(). \ lon_lat_alt_to_pixel_x_y(image_ground_grid_x, image_ground_grid_y, alts, band=0, world_proj=world_proj) for band in bands: image_data = overhead_image.read_band_from_disk(band) im_tp = image_data.dtype regridded = image_utils.grid_warp_image_band(image_data, pixels_x, pixels_y, nodata_val=nodata_val, interpolation=interpolation) regridded = regridded.astype(im_tp) images.append(regridded) orthorectified_image = np.stack(images, axis=2) if mask_no_data_region: orthorectified_image = mask_image(orthorectified_image, nodata_val) gtiff_image = GeotiffImageFactory.from_numpy_array(orthorectified_image, geo_t, world_proj) gtiff_image.get_metadata().set_nodata_val(nodata_val) if output_fname is not None: gtiff_image.write_to_disk(output_fname) return gtiff_image
def sarpy2ortho(ro, pix, decimation=10): nx = ro.sicdmeta.ImageData.FullImage.NumCols ny = ro.sicdmeta.ImageData.FullImage.NumRows nx_dec = round(nx / decimation) ny_dec = round(ny / decimation) xv, yv = np.meshgrid(range(nx), range(ny), indexing='xy') xv = xv[::decimation, ::decimation] yv = yv[::decimation, ::decimation] npix = xv.size xv = np.reshape(xv, (npix, 1)) yv = np.reshape(yv, (npix, 1)) im_points = np.concatenate([yv, xv], axis=1) ground_coords = image_to_ground(im_points, ro.sicdmeta) ground_coords = ecf_to_geodetic(ground_coords) minx = np.min(ground_coords[:, 1]) maxx = np.max(ground_coords[:, 1]) miny = np.min(ground_coords[:, 0]) maxy = np.max(ground_coords[:, 0]) xi, yi = create_ground_grid(minx, maxx, miny, maxy, nx_dec, ny_dec) ground_coords[:, [0, 1]] = ground_coords[:, [1, 0]] pix = np.reshape(pix, npix) gridded = griddata(ground_coords[:, 0:2], pix, (xi, yi), method='nearest').astype(np.uint8) ul = [maxy, minx] lr = [miny, maxx] extent = [ul, lr] extent_poly = bounds_2_shapely_polygon(min_x=minx, max_x=maxx, min_y=miny, max_y=maxy) geot = world_poly_to_geo_t(extent_poly, npix_x=nx_dec, npix_y=ny_dec) return gridded, extent, geot
def rpc_timings(): samp_num_coeff = [ -2.401488e-03, 1.014755e+00, 1.773499e-02, 2.048626e-02, -4.609470e-05, 4.830748e-04, -2.015272e-04, 1.212827e-03, 5.065720e-06, 3.740396e-05, -1.582743e-07, 1.437278e-06, 3.620892e-08, 2.144755e-07, -1.333671e-07, 0.000000e+00, -5.229308e-08, 1.111695e-06, -1.337535e-07, 0.000000e+00 ] samp_den_coeff = [ 1.000000e+00, 1.197118e-03, 9.340466e-05, -4.381989e-04, 3.359669e-08, 0.000000e+00, 2.959469e-08, 1.412447e-06, 8.398708e-08, -1.782544e-07, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] samp_scale = 1283.0 samp_off = 1009.0 height_off = 42.0 height_scale = 501.0 lat_off = 32.8902 lat_scale = 0.0142 line_num_coeff = [ 3.448567e-03, 1.975650e-02, -1.147937e+00, 1.622923e-01, 5.249710e-05, 4.231537e-05, 3.559660e-04, -9.052539e-05, -1.932047e-03, -2.341649e-05, -1.025999e-06, 0.000000e+00, -1.116629e-07, 1.635365e-07, -1.704056e-07, -3.139215e-06, 1.607936e-06, 1.281797e-07, 1.412060e-06, -2.638793e-07 ] line_den_coeff = [ 1.000000e+00, -1.294475e-05, 1.682046e-03, -1.481430e-04, 1.503771e-07, 7.529185e-07, -4.596928e-07, 0.000000e+00, 2.736755e-06, -1.609702e-06, 3.466453e-08, 1.066716e-08, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, -7.020142e-08, 1.766701e-08, 2.536018e-07, 0.000000e+00 ] line_off = 856.0 line_scale = 1143.0 lon_off = 13.1706 lon_scale = 0.0167 point_calc = RPCPointCalc.init_from_coeffs(samp_num_coeff, samp_den_coeff, samp_scale, samp_off, line_num_coeff, line_den_coeff, line_scale, line_off, lat_scale, lat_off, lon_scale, lon_off, height_scale, height_off) lon_center = lon_off lat_center = lat_off d_lon = 0.001 d_lat = 0.001 nx = 2000 ny = 2000 ground_grid = photogrammetry_utils.create_ground_grid( lon_center - d_lon, lon_center + d_lon, lat_center - d_lat, lat_center + d_lat, nx, ny) lons = image_utils.flatten_image_band(ground_grid[0]) lats = image_utils.flatten_image_band(ground_grid[1]) alts = np.zeros_like(lats) n_loops = 4 tic = time.time() for n in range(n_loops): point_calc.compute_p(samp_num_coeff, lats, lons, alts) toc = time.time() print("calculated " + str(n_loops * nx * ny) + " pixels in " + str(toc - tic) + " seconds.") print( str(n_loops * nx * ny / (toc - tic) / 1e6) + " Megapixels per second")