spymicmac.orientation

spymicmac.orientation is a collection of tools for working with image orientation using micmac.

spymicmac.orientation.block_orientation(blocks, meas_out='AutoMeasures', gcp_out='AutoGCPs', fn_mes='AutoMeasures_block', fn_gcp='AutoGCPs_block', dirname='auto_gcps', rel_ori='Relative', outori='TerrainFinal', homol='Homol', ref_dx=15, ortho_res=8, allfree=True, max_iter=1)[source]

Combine GCPs, Measures files, and Ori directories from multiple sub-blocks into a single file and orientation.

Parameters:
  • blocks (list) – a list of the sub-block numbers to combine

  • meas_out (str) – the output filename for the Measures file (no extension). (default: AutoMeasures)

  • gcp_out (str) – the output filename for the GCP file (no extension). (default: AutoGCPs)

  • fn_mes (str) – the name pattern of the measures files to combine (default: AutoMeasures_block)

  • fn_gcp (str) – the name pattern of the GCP files to combine (default: AutoGCPs_block)

  • dirname (str) – the output directory where the files are saved (default: auto_gcps)

  • rel_ori (str) – the name of the relative orientation to input to GCPBascule (default: Relative -> Ori-Relative)

  • outori (str) – the output orientation from Campari (default: TerrainFinal -> Ori-TerrainFinal)

  • homol (str) – the Homologue directory to use (default: Homol)

  • ref_dx (int|float) – the pixel resolution of the reference image, in meters. (default: 15)

  • ortho_res (int|float) – the pixel resolution of the orthoimage being used, in meters. (default: 8)

  • allfree (bool) – run Campari with AllFree=1 (True), or AllFree=0 (False). (default: True)

  • max_iter (int) – the maximum number of iterations to run. (default: 1)

Returns:

gcps (GeoDataFrame) – the combined GCPs output from spymicmac.micmac.iterate_campari

spymicmac.orientation.combine_block_measures(blocks, meas_out='AutoMeasures', gcp_out='AutoGCPs', fn_mes='AutoMeasures_block', fn_gcp='AutoGCPs_block', dirname='auto_gcps')[source]

Combine GCPs and Measures files from multiple sub-blocks into a single file.

Parameters:
  • blocks (list) – a list of the sub-block numbers to combine

  • meas_out (str) – the output filename for the Measures file (no extension). (default: AutoMeasures)

  • gcp_out (str) – the output filename for the GCP file (no extension). (default: AutoGCPs)

  • fn_mes (str) – the name pattern of the measures files to combine (default: AutoMeasures_block)

  • fn_gcp (str) – the name pattern of the GCP files to combine (default: AutoGCPs_block)

  • dirname (str) – the output directory where the files are saved (default: auto_gcps)

spymicmac.orientation.extend_line(df, first, last)[source]

Extend a flightline using existing camera positions.

Parameters:
  • df (GeoDataFrame) – a GeoDataFrame containing the camera positions and image names

  • first (str) – the name of the image to start interpolating from.

  • last (str) – the name of the image to end interpolating at.

Returns:

outpt (shapely.Point) – the new point along the flightline.

spymicmac.orientation.fix_orientation(cameras, ori_df, ori, nsig=4)[source]

Correct erroneous Tapas camera positions using an estimated affine transformation between the absolute camera locations and the relative locations read from the orientation directory.

Once the positions have been updated, you should re-run Tapas using the InOri set to the directory; e.g., if you have updated Ori-Relative, you should run:

mm3d Tapas RadialBasic “OIS.*tif” InOri=Relative Out=Relative LibFoc=0

Parameters:
  • cameras (pandas.DataFrame) – A DataFrame containing camera positions (x, y, z) and a ‘name’ column that contains the image names.

  • ori_df (pandas.DataFrame) – A DataFrame output from sPyMicMac.micmac.load_all_orientations, or that contains a ‘name’ column and camera positions in relative space (x, y, z)

  • ori (str) – the Orientation directory to update (e.g., Ori-Relative)

  • nsig (int|float) – the number of normalized absolute deviations from the median residual value to consider a camera an outlier (default: 4)

spymicmac.orientation.interp_line(df, first, last, nimgs=None, pos=None)[source]

Interpolate camera positions along a flightline.

Parameters:
  • df (GeoDataFrame) – a GeoDataFrame containing the camera positions and image names

  • first (str) – the name of the image to start interpolating from.

  • last (str) – the name of the image to end interpolating at.

  • nimgs (int) – the number of images to interpolate (default: calculated based on the image numbers)

  • pos (int) – which image position to return (default: all images between first and last)

Returns:

ptList (list) – a list containing the interpolated camera positions (or, a tuple of the requested position).

spymicmac.orientation.load_all_orientation(ori, imlist=None)[source]

Load all of the orientation parameters for a set of images from a given directory.

Parameters:
  • ori (str) – the orientation directory to read

  • imlist (list) – the images to load. If not set, loads all orientation files from the given directory.

Returns:

ori_df (pandas.DataFrame) – a DataFrame containing the orientation parameters for each image

spymicmac.orientation.load_orientation(fn_img, ori)[source]

Read camera position and rotation information from an Orientation xml file.

Parameters:
  • fn_img (str) – the name of the image to read the orientation file for.

  • ori (str) – the name of the orientation directory (e.g., Ori-Relative).

Returns:

  • centre (list) – the camera position (x, y, z)

  • l1 (list) – the L1 orientation parameters

  • l2 (list) – the L2 orientation parameters

  • l3 (list) – the L3 orientation parameters

  • prof (float) – the ‘Profondeur’ value from the xml file.

  • altisol (float) – the ‘AltiSol’ value from the xml file.

spymicmac.orientation.plot_camera_centers(ori, ax=None)[source]

Plot camera center locations in a 3D axis using matplotlib.

Parameters:
  • ori (str) – the name of the orientation directory (e.g., Ori-Relative).

  • ax – an existing 3d matplotlib axis. If None, one will be created.

Returns:

ax – a matplotlib axis with the camera centers plotted

spymicmac.orientation.transform_centers(img_gt, ref, imlist, footprints, ori, imgeom=True)[source]

Use the camera centers in relative space provided by MicMac Orientation files, along with camera centers or footprints, to estimate a transformation between the relative coordinate system and the absolute coordinate system.

Parameters:
  • img_gt (array-like) – the image GeoTransform (as read from a TFW file)

  • ref (Raster) – the reference image to use to determine the output image shape

  • imlist (list) – a list of the images that were used for the relative orthophoto

  • footprints (GeoDataFrame) – the (approximate) image footprints or camera centers. If geom_type is Polygon, the centroid will be used for the absolute camera positions.

  • ori (str) – name of orientation directory

  • imgeom (bool) – calculate a transformation between image ij locations (True)

Returns:

  • model (AffineTransform) – the estimated Affine Transformation between relative and absolute space

  • inliers (array-like) – a list of the inliers returned by skimage.measure.ransac

  • join (GeoDataFrame) – the joined image footprints and relative orientation files

spymicmac.orientation.transform_points(ref, ref_pts, rel_gt, rel_pts)[source]

Given x,y points and two “geo”-referenced images, finds an affine transformation between the two images.

Parameters:
  • ref (Raster) – the reference image

  • ref_pts (np.array) – an Mx2 array of the x,y points in the reference image

  • rel_gt (array-like) – the “geo” transform for the second image, as read from a .tfw file.

  • rel_pts (np.array) – an Mx2 array of the x,y points in the second image.

Returns:

  • model (AffineTransform) – the estimated Affine Transformation between relative and absolute space

  • inliers (array-like) – a list of the inliers returned by skimage.measure.ransac

spymicmac.orientation.update_center(fn_img, ori, new_center)[source]

Update the camera position in an Orientation file.

Parameters:
  • fn_img (str) – the name of the image to update the orientation for (e.g., ‘OIS-Reech_ARCSEA000590122.tif’)

  • ori (str) – the name of the orientation directory (e.g., ‘Ori-Relative’)

  • new_center (list) – a list of the new camera position [x, y, z]

spymicmac.orientation.update_params(fn_img, ori, profondeur, altisol)[source]

Update the profondeur and altisol parameters in an orientation file.

Parameters:
  • fn_img (str) – the name of the image to update the orientation for (e.g., ‘OIS-Reech_ARCSEA000590122.tif’)

  • ori (str) – the name of the orientation directory (e.g., ‘Ori-Relative’)

  • profondeur (float) – the new profondeur value

  • altisol (float) – the new altisol value

spymicmac.orientation.update_pose(fn_img, ori, new_rot)[source]

Update the camera pose (rotation matrix) in an Orientation file.

Parameters:
  • fn_img (str) – the name of the image to update the orientation for (e.g., ‘OIS-Reech_ARCSEA000590122.tif’)

  • ori (str) – the name of the orientation directory (e.g., ‘Ori-Relative’)

  • new_rot (array-like) – the new 3x3 rotation matrix