spymicmac.resample#

spymicmac.resample is a collection of tools for resampling images

declassified images#

spymicmac.resample.resample_hex(fn_img, scale, ori='InterneScan', alg=1, tps=True, order=None)[source]#

Resample a KH-9 Mapping Camera image based on the reseau grid, using gdal.Warp

Parameters:
  • fn_img (str | Path) – the filename of the image to resample

  • scale (int) – the number of pixels per mm of the scanned image

  • ori (str) – the Ori directory that contains both MeasuresCamera.xml and MeasuresIm

  • alg – the gdal resampling algorithm to use (default: gdal.GRA_Bilinear)

  • tps (bool) – use a thin plate spline transformer to transform based on reseau grid

  • order (int | None) – the order (1-3) of polynomial GCP interpolation (default: not used)

Return type:

None

spymicmac.resample.crop_panoramic(fn_img, flavor, marker_size=31, fact=None, return_vals=False)[source]#

Crop a declassified panoramic (KH4 or KH9) image, after rotating based on horizontal rail markers or “wagon wheel” fiducial markers.

Parameters:
  • fn_img (str | Path) – the filename of the image to rotate and crop

  • flavor (str) – the camera type (KH4 or KH9)

  • marker_size (int) – The approximate size of the wagon wheels to identify in the image (default: 31 pixels)

  • fact (int | None) – the number by which to divide the image width and height to scale the image (default: do not scale)

  • return_vals (bool) – Return estimated image border and rotation angle (default: False)

Returns:

  • border – the estimated image border (left, right, top, bot)

  • angle – the estimated rotation angle. Only returned if return_vals is True.

Return type:

None | tuple[tuple, float]

spymicmac.resample.rotate_from_rails(img, rails)[source]#

Use the rail marks or other horizontal points in an image to rotate the image.

Parameters:
  • img (ndarray[Any, dtype[_ScalarType_co]]) – the image to rotate.

  • rails (ndarray[Any, dtype[_ScalarType_co]]) – an Nx2 array of (row, col) points

Returns:

  • rotated – the rotated image

  • angle – the calculated angle of rotation, in degrees

Return type:

tuple[ndarray[Any, dtype[_ScalarType_co]], float]

aerial images#

spymicmac.resample.resample_fiducials(fn_img, scale, transform=<AffineTransform(matrix=     [[1., 0., 0.],      [0., 1., 0.],      [0., 0., 1.]])>, fn_cam=None, nproc=1)[source]#

Resample image(s) using fiducial markers.

Parameters:
  • fn_img (str | Path | list[str] | list[Path]) – the filename, or a list of filenames, of the image(s)

  • scale (float) – the image scale (in mm/pixel) to use

  • transform – the type of transformation to use. Should be an instance of skimage.transform (default: AffineTransform)

  • fn_cam (str | Path | None) – the filename for the MeasuresCamera.xml file (default: Ori-InterneScan/MeasuresCamera.xml)

  • nproc (int) – the number of processors to use (default: 1)

Return type:

None

generic resampling#

spymicmac.resample.crop_from_extent(fn_img, border, angle=None, fact=None)[source]#

Crop an image given the coordinates of the image border.

Parameters:
  • fn_img (str | Path) – the filename of the image to rotate and crop

  • border (ndarray[Any, dtype[_ScalarType_co]]) – the estimated image border coordinates (left, right, top, bot)

  • angle (float | None) – the angle by which to rotate the image (default: None)

  • fact (int | None) – the number by which to divide the image width and height to scale the image (default: do not scale)

Return type:

None

spymicmac.resample.downsample(img, fact=4)[source]#

Rescale an image using Lanczos resampling

Parameters:
  • img (ndarray[Any, dtype[_ScalarType_co]]) – the image to rescale

  • fact (int | float) – the number by which to divide the image width and height

Returns:

rescaled – the rescaled image

Return type:

ndarray[Any, dtype[_ScalarType_co]]