Пример #1
0
def get_pixel_lon_lats(overhead_image,  # type: AbstractEarthOverheadImage
                       dem=None,  # type: AbstractDem
                       band=None,  # type: list
                       pixels_x=None,  # type: int
                       pixels_y=None,  # type: int
                       pixel_error_threshold=0.01,  # type: float
                       max_iter=1000  # type: int
                       ):  # type: (...) -> (ndarray, ndarray)

    if dem is None:
        dem = DemFactory.constant_elevation(0)
    point_calc = overhead_image.get_point_calculator()
    if pixels_x is None or pixels_y is None:
        pixels_x, pixels_y = image_utils.create_pixel_grid(overhead_image.get_metadata().get_npix_x(),
                                                           overhead_image.get_metadata().get_npix_y())
    alts = dem.get_highest_alt()
    lons_highest, lats_highest = point_calc.pixel_x_y_alt_to_lon_lat(pixels_x, pixels_y, alts,
                                                                     band=band,
                                                                     pixel_error_threshold=pixel_error_threshold,
                                                                     max_iter=max_iter)
    # get differences from the highest alt using the dem
    alt_diff = alts - dem.get_elevations(lons_highest, lats_highest)
    new_alts = alts - alt_diff
    lons_low, lats_low = point_calc.pixel_x_y_alt_to_lon_lat(pixels_x, pixels_y, new_alts,
                                                             band=band,
                                                             pixel_error_threshold=pixel_error_threshold,
                                                             max_iter=max_iter)
    return lons_low, lats_low
Пример #2
0
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
Пример #3
0
def ortho_micasense_to_flat_earth_native():
    elevation = np.nanmean(dem_image.dem_data)
    const_elevation_dem = DemFactory.constant_elevation(elevation)

    ortho_nx, ortho_ny = photogrammetry_utils.get_nx_ny_pixels_in_extent(extent_native, gsd_m, gsd_m)
    print("making ortho of size: " + str(ortho_nx) + "x" + str(ortho_ny))

    output_fullpath = os.path.join(save_dir, "micasense_ortho_w_const_elevation_dem_native.tif")

    ortho_tools.create_ortho_gtiff_image_world_to_sensor(micasense_image, ortho_nx, ortho_ny, extent_native,
                                                         world_proj=dem_image.get_projection(),
                                                         dem=const_elevation_dem, nodata_val=0,
                                                         output_fname=output_fullpath)
    print("wrote orthorectified micasense image to " + output_fullpath)
Пример #4
0
def create_igm_image(
        overhead_image,  # type: AbstractEarthOverheadImage
        dem=None,  # type: AbstractDem
        dem_sample_distance=None,  # type: int
):  # type: (...) -> IgmImage
    if dem is None:
        dem = DemFactory.constant_elevation()
    pixels_x, pixels_y = image_utils.create_pixel_grid(
        overhead_image.metadata.get_npix_x(),
        overhead_image.metadata.get_npix_y())
    lons, lats, alts = overhead_image.pointcalc.pixel_x_y_to_lon_lat_alt(
        pixels_x, pixels_y, dem, dem_sample_distance=dem_sample_distance)
    igm_image = IgmImage.from_params(overhead_image.get_image_data(), lons,
                                     lats, alts,
                                     overhead_image.get_image_data().shape[2],
                                     overhead_image.pointcalc.get_projection())
    return igm_image
Пример #5
0
# set up where digital surface model is stored
dsm_fullpath = file_utils.get_path_from_subdirs(micasense_dir,
                                                ['pix4d_1703_mica_imgs85_1607',
                                                 '3_dsm_ortho',
                                                 'pix4d_1704_mica_85_1607_dsm.tif'])

# load up the pix4d info
pix4d_master_dict = pix4d.make_master_dict(params_dir)

# make the micasense camera object
micasense_image = ImageFactory.micasense.from_image_number_and_pix4d(band_fname_dict, pix4d_master_dict)
micasense_native_projection = micasense_image.get_point_calculator().get_projection()

# make the dem camera object
dem_image = DemFactory.from_gtiff_file(dsm_fullpath)
dem_native_projection = dem_image.get_projection()

if dem_native_projection.srs != micasense_native_projection.srs:
    raise ValueError("pix4d dem and micasense projections should be in same CRS!")

# get the extent in native coordinates
extent_native = ortho_tools.get_extent(micasense_image, dem=dem_image, pixel_error_threshold=0.1)


# functions to make various ortho types
def ortho_micasense_to_dem_native():
    output_fullpath = os.path.join(save_dir, "micasense_ortho_w_dem_native.tif")

    ortho_nx, ortho_ny = photogrammetry_utils.get_nx_ny_pixels_in_extent(extent_native, gsd_m, gsd_m)
    print("making ortho of size: " + str(ortho_nx) + "x" + str(ortho_ny))
from tests.demo_tests import demo_data_base_dir
from resippy.image_objects.image_factory import GeotiffImageFactory
from resippy.utils.physical_camera_simulator import PhysicalCameraSimulator
from resippy.photogrammetry import ortho_tools
from resippy.photogrammetry.dem.dem_factory import DemFactory

gtiff_fname = os.path.join(
    demo_data_base_dir,
    "image_data/digital_globe/WashingtonDC_View-Ready_Stereo_50cm/056082264010/056082264010_01_P001_PAN/12SEP21160917-P2AS_R3C2-056082264010_01_P001.TIF"
)
gtiff_basemap_image_obj = GeotiffImageFactory.from_file(gtiff_fname)

dem_fname = os.path.join(
    demo_data_base_dir,
    "dems/washingtonDC/Normalized_DSM_2018/nDSM_resampled.tif")
dem = DemFactory.from_gtiff_file(dem_fname)

lon_center, lat_center = gtiff_basemap_image_obj.get_point_calculator(
).pixel_x_y_alt_to_lon_lat(
    gtiff_basemap_image_obj.get_metadata().get_npix_x() / 2,
    gtiff_basemap_image_obj.get_metadata().get_npix_y() / 2, 0)

sensor_alt = 1000

camera_npix_x = 640
camera_npix_y = 480
flen = 3

yaw = 0.00000001

simulator = PhysicalCameraSimulator(gtiff_fname, flen, camera_npix_x,