spymicmac.orientation#

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

reading/writing orientations#

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 | None) – the images to load. If not set, loads all orientation files from the given directory.

Returns:

ori_df – a DataFrame containing the orientation parameters for each image

Return type:

DataFrame

spymicmac.orientation.write_orientation(ori_df, dir_ori, calfile, known_conv='eConvApero_DistM2C')[source]#

Write orientation xml files for a set of images

Parameters:
  • ori_df (pd.DataFrame) – a pandas DataFrame like the kind output by load_all_orientation()

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

  • calfile (str) – the path to the calibration file for this orientation

  • known_conv (str) – the name of a conversion used by MicMac

transforming orientations#

spymicmac.orientation.transform_centers(rel, 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:
  • rel (Raster) – the relative image

  • 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, rather than real-world coordinates

Returns:

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

  • inliers – a list of the inliers returned by skimage.measure.ransac

  • join – the joined image footprints and relative orientation files

Return type:

tuple[AffineTransform, ndarray[tuple[Any, …], dtype[_ScalarT]], GeoDataFrame]

combining image blocks#

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, share_gcps=False)[source]#

Combine GCPs, Measures files, and Ori directories from multiple sub-blocks into a single file and orientation. After combining blocks into a single orientation, runs mm3d Campari to refine the orientation and shared camera parameters.

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

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

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

  • fn_mes (str) – the name pattern of the measures files to combine.

  • fn_gcp (str) – the name pattern of the GCP files to combine.

  • dirname (str) – the output directory where the files are saved.

  • 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.

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

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

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

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

  • share_gcps (bool) – GCPs are shared between blocks

Returns:

gcps – the combined GCPs output from spymicmac.micmac.iterate_campari

Return type:

GeoDataFrame

spymicmac.orientation.combine_block_measures(blocks, meas_out='AutoMeasures', gcp_out='AutoGCPs', fn_mes='AutoMeasures_block', fn_gcp='AutoGCPs_block', dirname='auto_gcps', share_gcps=False)[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).

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

  • fn_mes (str) – the name pattern of the measures files to combine.

  • fn_gcp (str) – the name pattern of the GCP files to combine.

  • dirname (str) – the output directory where the files are saved.

  • share_gcps (bool) – GCPs are shared between blocks.

Return type:

None

fixing orientations#

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 (DataFrame) – A DataFrame containing camera positions (x, y, z) and a ‘name’ column that contains the image names.

  • ori_df (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

Return type:

None

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

Extend a flightline using existing camera positions.

Parameters:
  • df (DataFrame) – 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 – the new point along the flightline.

Return type:

Point

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 | None) – the number of images to interpolate (default: calculated based on the image numbers)

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

Returns:

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

Return type:

list | Point

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[float, float, float]) – a list of the new camera position [x, y, z]

Return type:

None

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 (ndarray[tuple[Any, ...], dtype[_ScalarT]]) – the new 3x3 rotation matrix

Return type:

None

visualizing orientations#

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 (Axes3D | None) – an existing 3d matplotlib axis. If None, one will be created.

Returns:

ax – a matplotlib axis with the camera centers plotted

Return type:

Axes3D