Orthorectification

Orthorectification using DEM and camera model input.

class orthority.ortho.Ortho(src_file, dem_file, camera, crs=None, dem_band=1)

Bases: object

Orthorectifier.

Uses a supplied DEM and camera model to correct a source image for sensor and terrain distortion. The camera model, and a portion of the DEM corresponding to the ortho bounds are stored internally.

Parameters:
  • src_file (str | PathLike | OpenFile | rio.DatasetReader) – Source image to be orthorectified. Can be a path or URI string, an OpenFile object in binary mode ('rb'), or a dataset reader.

  • dem_file (str | PathLike | OpenFile | rio.DatasetReader) – DEM file covering the source image. Can be a path or URI string, an OpenFile object in binary mode ('rb'), or a dataset reader.

  • camera (Camera) – Source image camera model.

  • crs (str | CRS | None) – CRS of the camera world coordinates, and ortho image, as an EPSG, proj4 or WKT string, or CRS object. If set to None (the default), the CRS will be read from the source image if possible. If the source image is not projected in the world / ortho CRS, crs should be supplied.

  • dem_band (int) – Index of the DEM band to use (1-based).

property camera: Camera | FrameCamera

Source image camera model.

process(ortho_file, resolution=None, interp=cubic, dem_interp=cubic, per_band=False, write_mask=None, dtype=None, compress=None, build_ovw=True, creation_options=None, driver=gtiff, overwrite=False, progress=False)

Orthorectify the source image.

The source image is read and processed band-by-band, or all bands at once, depending on the value of per_band. If necessary, the portion of the DEM stored internally is reprojected to the world / ortho CRS and ortho resolution. Using the camera model and DEM, the ortho image is remapped from the source image tile-by-tile. Up to N ortho tiles are processed concurrently, where N is the number of CPUs.

Note

An occlusion masking option will be added in a future release.

Parameters:
  • ortho_file (str | PathLike | OpenFile) – Ortho image file to create. Can be a path or URI string, or an OpenFile object in binary mode ('wb').

  • resolution (tuple[float, float]) – Ortho image pixel (x, y) size in units of the world / ortho CRS. If set to None (the default), an approximate ground sampling distance is used as the resolution.

  • interp (str | Interp) – Interpolation method for remapping the source to ortho image.

  • dem_interp (str | Interp) – Interpolation method for reprojecting the DEM.

  • per_band (bool) – Remap the source to ortho image all bands at once (False), or band-by-band (True). False is faster but requires more memory.

  • write_mask (bool | None) – Mask valid ortho pixels with an internal mask (True), or with a nodata value based on dtype (False). An internal mask helps remove nodata noise caused by lossy compression. If set to None (the default), the mask will be written when JPEG compression is used.

  • dtype (str) – Ortho image data type (uint8, uint16, int16, float32 or float64). If set to None (the default), the source image data type is used.

  • compress (str | Compress | None) – Ortho image compression type (jpeg, deflate or lzw). deflate and lzw can be used with any dtype, and jpeg with the uint8 dtype. With supporting Rasterio builds, jpeg can also be used with uint16, in which case the ortho is 12 bit JPEG compressed. If compress is set to None (the default), jpeg is used for the uint8 dtype, and deflate otherwise.

  • build_ovw (bool) – Whether to build overviews for the ortho image.

  • creation_options (dict | None) – Ortho image creation options as dictionary of name: value pairs. If supplied, compress is ignored. See the GDAL docs for details.

  • driver (str | Driver) – Ortho image driver (gtiff or cog).

  • overwrite (bool) – Whether to overwrite the ortho image if it exists.

  • progress (bool | dict) – Whether to display a progress bar monitoring the portion of ortho tiles written. Can be set to a dictionary of arguments for a custom tqdm bar.

Return type:

None