spymicmac.resample

spymicmac.resample is a collection of tools for resampling images

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) – the filename of the image to rotate and crop

  • border (array-like) – the estimated image border coordinates (left, right, top, bot)

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

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

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) – 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) – 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 (tuple) – the estimated image border (left, right, top, bot)

  • angle (float) – the estimated rotation angle.

Only returned if return_vals is True.

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

Rescale an image using Lanczos resampling

Parameters:
  • img (array-like) – the image to rescale

  • fact (numeric) – the number by which to divide the image width and height (default: 4)

Returns:

rescaled (array-like) – the rescaled image

spymicmac.resample.resample_hex(fn_img, scale, ori='InterneScan')[source]

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

Parameters:
  • fn_img (str) – 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 (default: InterneScan)

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 (array-like) – the image to rotate.

  • rails (array-like) – an Nx2 array of (row, col) points

Returns:

  • rotated (array-like) – the rotated image

  • angle (float) – the calculated angle of rotation, in degrees