graph.edge — Network Edge

The graph.edge module contains the Edge class that extends NetworkX edges.

New in version 0.1.0.

class autocnet.graph.edge.Edge(source=None, destination=None)[source]
source

The source node

Type

hashable

destination

The destination node

Type

hashable

masks

A list of the available masking arrays

Type

set

weights

Dictionary with two keys overlap_area, and overlap_percn overlap_area returns the area overlaped by both images overlap_percn retuns the total percentage of overlap

Type

dict

add_coordinates_to_matches()[source]

Add source and destination x/y columns to the matches dataframe. This will add to the overall memory needed to store matches, but makes access to x,y easier as a join on the keypoints is not requires.

clean(clean_keys)[source]

Given a list of clean keys compute the mask of valid matches

Parameters

clean_keys (list) – of columns names (clean keys)

Returns

  • matches (dataframe) – A masked view of the matches dataframe

  • mask (series) – A boolean series to inflate back to the full match set

compute_fundamental_error(method='equality', clean_keys=[])[source]

Given a fundamental matrix, compute the reprojective error between a two sets of keypoints.

Parameters

clean_keys (list) – of string keys to masking arrays (created by calling outlier detection)

Returns

error – of reprojective error indexed to the matches data frame

Return type

pd.Series

compute_fundamental_matrix(clean_keys=[], maskname='fundamental', **kwargs)[source]

Estimate the fundamental matrix (F) using the correspondences tagged to this edge.

Parameters
  • clean_keys (list) – Of strings used to apply masks to omit correspondences

  • method ({linear, nonlinear}) – Method to use to compute F. Linear is significantly faster at the cost of reduced accuracy.

See also

autocnet.transformation.transformations.FundamentalMatrix

compute_homography(method='ransac', clean_keys=[], pid=None, maskname='homography', **kwargs)[source]

For each edge in the (sub) graph, compute the homography :param outlier_algorithm: An openCV outlier detections algorithm, e.g. cv2.RANSAC :type outlier_algorithm: object :param clean_keys: of string keys to masking arrays

(created by calling outlier detection)

Returns

  • transformation_matrix (ndarray) – The 3x3 transformation matrix

  • mask (ndarray) – Boolean array of the outliers

compute_overlap(buffer_dist=0, **kwargs)[source]

Estimate a source and destination minimum bounding rectangle, in pixel space.

compute_weights(clean_keys, **kwargs)[source]

Computes a voronoi diagram for the overlap between two images then gets the area of each polygon resulting in a voronoi weight. These weights are then appended to the matches dataframe.

Parameters

clean_keys (list) – Of strings used to apply masks to omit correspondences

coverage(clean_keys=[])[source]

Acts on the edge given either the source node or the destination node and returns the percentage of overlap covered by the keypoints. Data for the overlap is gathered from the source node of the edge resulting in a maximum area difference of 2% when compared to the destination.

Returns

total_overlap_percentage – returns the overlap area covered by the keypoints

Return type

float

decompose()[source]

Apply coupled decomposition to the images and match identified sub-images

decompose_and_match(k=2, maxiteration=3, size=18, buf_dist=3, **kwargs)

Similar to match, this method first decomposed the image into $4^{maxiteration}$ subimages and applys matching between each sub-image.

This method is potential slower than the standard match due to the overhead in matching, but can be significantly more accurate. The increase in accuracy is a function of the total image size. Suggested values for maxiteration are provided below.

Parameters
  • k (int) – The number of neighbors to find

  • method ({'coupled', 'whole'}) – whether to utilize coupled decomposition or match the whole image

  • maxiteration (int) –

    When using coupled decomposition, the number of recursive divisions to apply. The total number of resultant sub-images will be 4 ** maxiteration. Approximate values:

    Number of megapixels | maxiteration |

    |----------------------|————–| | m < 10 |1-2| | 10 < m < 30 | 3 | | 30 < m < 100 | 4 | | 100 < m < 1000 | 5 | | m > 1000 | 6 |

  • size (int) – When using coupled decomposition, the total number of points to check in each sub-image to try and find a match. Selection of this number is a balance between seeking a representative mid-point and computational cost.

  • buf_dist (int) – When using coupled decomposition, the distance from the edge of the (sub)image a point must be in order to be used as a partioning point. The smaller the distance, the more likely percision errors can results in erroneous partitions.

match(k=2, **kwargs)[source]

Given two sets of descriptors, utilize a FLANN (Approximate Nearest Neighbor KDTree) matcher to find the k nearest matches. Nearness is the euclidean distance between descriptors.

The matches are then added as an attribute to the edge object.

Parameters

k (int) – The number of neighbors to find

overlap()[source]

Acts on an edge and returns the overlap area and percentage of overlap between the two images on the edge. Data is returned to the weights dictionary

overlap_check()[source]

Creates a mask for matches on the overlap

project_matches(semimajor, semiminor, on='source', srid=None)[source]

Project matches.

subpixel_register(method='phase', clean_keys=[], template_size=251, search_size=251, **kwargs)[source]

For the entire graph, compute the subpixel offsets using pattern-matching and add the result as an attribute to each edge of the graph.

Parameters
  • clean_keys (list) – of string keys to masking arrays (created by calling outlier detection)

  • threshold (float) – On the range [-1, 1]. Values less than or equal to this threshold are masked and can be considered outliers

  • upsampling (int) – The multiplier to the template and search shapes to upsample for subpixel accuracy

  • template_size (int) – The size of the template in pixels, must be odd. If using phase, only the template size is used.

  • search_size (int) – The size of the search area. When method=’template’, this size should be >= the template size

suppress(suppression_func=<function correlation>, clean_keys=[], maskname='suppression', **kwargs)[source]

Apply a disc based suppression algorithm to get a good spatial distribution of high quality points, where the user defines some function to be used as the quality metric.

Parameters
  • suppression_func (object) – A function that returns a scalar value to be used as the strength of a given row in the matches data frame.

  • suppression_args (tuple) – Arguments to be passed on to the suppression function

  • clean_keys (list) – of mask keys to be used to reduce the total size of the matches dataframe.

class autocnet.graph.edge.NetworkEdge(*args, **kwargs)[source]
compute_fundamental_matrix(method='ransac', maskname='fundamental', **kwargs)[source]

Estimate the fundamental matrix (F) using the correspondences tagged to this edge.

Parameters
  • method ({'ransac', 'lmeds', 'normal', '8point'}) – The method that will be used when computing the homography.

  • maskname (str) – The column that the mask will be saved under in the masks dataframe. If the column already exists, then the mask in that column will be overwritten.

  • kwargs (dict) – Extra arguments that will be passed to the fundamental matrix computation.

See also

autocnet.transformation.transformations.fundamental_matrix.compute_fundamental_matrix

compute_homography(method='ransac', maskname='homography', **kwargs)[source]

Estimate the homography and reprojective error on this edge of the graph.

Parameters
  • method ({'ransac', 'lmeds', 'normal'}) – The method that will be used when computing the homography.

  • maskname (str) – The column that the mask will be saved under in the masks dataframe. If the column already exists, then the mask in that column will be overwritten.

  • kwargs (dict) – Extra arguments that will be passed to the homography computation.

See also

autocnet.transformation.transformations.homography.compute_homography

find_IQR_outliers(scaling=1.5, filters={'template_metric': 1, 'template_shift': 0}, n_tolerance=10)[source]

Based on the interquartile range, find the measure outliers from line and sample shifts.

Parameters
  • scaling (float) – scaling factor to use on IQR when determining outlier range

  • filters (dict) – filters used on a match’s source measure, only source measures which satisfy filter will be used in outlier calculation

  • n_tolerance (int) – minimum number of measures needed to calculate outliers

Returns

  • measure_ids (list) – list of measure ids corresponding to outliers

  • resultlog (dict) – status of finding outlier

ignore_outliers(outlier_method='IQR', **kwargs)[source]

Find and ignore outlier measures as determined by outlier method

Parameters

outlier_method (str) –

method used to determine outliers. Current methods:

  • interquartile range (‘IQR’) of line/sample shift

Returns

resultlog – status of finding and ignoring outliers

Return type

dict

mask_to_counter(mask)[source]

Take a mask on an edge and convert the mask into a counter where the key is the match id and value is 1 (the match is flagged false).

TODO: Allow the mask to be an iterable (list). The caller of this should then worry about normalization as n-mask strings can come in and we cannot anticipate how the user might want to normalize the return.

Parameters

mask (str) – The name of the mask

Returns

With keys equal to the indices of the False matches and values equal to one

Return type

collections.Counter

network_to_matches(ignore_point=False, ignore_measure=False, rejected_jigsaw=False)[source]

For the edge, take any points/measures that are in the database and convert them into matches on the associated edge.

Parameters
  • ignore_point (bool) – If False (default) only select the points that are not ignored (currently active).

  • ignore_measure (bool) – If False (default) only add the measures that are not ignored (currently active).

  • rejected_jigsaw (bool) – If False (default) add any points that are not set to jigsaw rejected.