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, fact=None, fn_coords=None)[source]#
Crop a declassified panoramic (KH4 or KH9) image by finding the frame.
- Parameters:
fn_img (str | Path) – the filename of the image to rotate and crop
fact (int | None) – the number by which to divide the image width and height to scale the image (default: do not scale)
fn_coords (None | str | Path)
- Return type:
None
- 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[tuple[Any, ...], dtype[_ScalarT]]) – the image to rotate.
rails (ndarray[tuple[Any, ...], dtype[_ScalarT]]) – an Nx2 array of (row, col) points
- Returns:
rotated – the rotated image
angle – the calculated angle of rotation, in degrees
- Return type:
tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], 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[tuple[Any, ...], dtype[_ScalarT]]) – 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[tuple[Any, ...], dtype[_ScalarT]]) – 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[tuple[Any, …], dtype[_ScalarT]]