magmap.cv.verifier module

magmap.cv.verifier.find_closest_blobs_cdist(blobs, blobs_master, thresh=None, scaling=None)[source]

Find the closest blobs within a given tolerance using the Hungarian algorithm to find blob matches.

Parameters:
  • blobs (ndarray) – Blobs as a 2D array of [n, [z, row, column, ...]].

  • blobs_master (ndarray) – Array in same format as blobs.

  • thresh (Optional[float], default: None) – Threshold distance beyond which blob pairings are excluded; defaults to None to include all matches.

  • scaling (Optional[Sequence[float]], default: None) – Sequence of scaling factors by which to multiply the blob coordinates before computing distances, used to scale coordinates from an anisotropic to isotropic ROI before computing distances, which assumes isotropy. Defaults to None.

Returns:

  • rowis and colis, arrays of row and corresponding column indices of the closest matches

  • dists_closest, an array of corresponding distances for these matches. Only matches within the given tolerance will be included.

Return type:

Tuple of

magmap.cv.verifier.match_blobs_roi(blobs, blobs_base, offset, size, thresh, scaling, inner_padding, resize=None)[source]

Match blobs from two sets of blobs in an ROI.

Prioritizes the inner portion of ROIs to avoid missing detections because of edge effects while also adding matches between a blob in the inner ROI and another blob in the remaining portion of the ROI.

Parameters:
  • blobs (ndarray) – The blobs to be matched against blobs_base, given as 2D array of [[z, row, column, radius, ...], ...].

  • blobs_base (ndarray) – The blobs to which blobs will be matched, in the same format as blobs.

  • offset (Sequence[int]) – ROI offset from which to select blobs in x,y,z.

  • size (Sequence[int]) – ROI size in x,y,z.

  • thresh (float) – Distance map threshold

  • scaling (Sequence[float]) – Scaling normalized by tol.

  • inner_padding (Sequence[float]) – ROI padding shape.

  • resize (Optional[Sequence[float]], default: None) – Resize sequence retrieved from ROI profile; defaults to None.

Returns:

  • blobs_inner_plus: array of blobs from blobs

  • blobs_truth_inner_plus: corresponding array from blobs_base matching blobs in blobs

  • offset_inner: offset of the inner portion of the ROI in absolute coordinates of x,y,z

  • size_inner: shape of this inner portion of the ROI

  • matches: Blob matches

Return type:

Tuple of

magmap.cv.verifier.meas_detection_accuracy(blobs, verified=False, treat_maybes=0)[source]

Measure detection accuracy based on blob confirmation statuses.

Parameters:
  • blobs (np.ndarray) – 2D array of blobs in the format, [[z, row, column, radius, confirmation, truth, ...], ...].

  • verified (bool) – True to assume that blobs have undergone verification.

  • treat_maybes (int) – 0 to ignore maybes; 1 to treat maybes as correct, and 1 to treat maybes as incorrect.

Returns:

Sensivity, positive predictive value (PPV), and summary of stats as a string. If blobs is None or empty, returns None for each of these values.

Return type:

float, float, str

magmap.cv.verifier.setup_match_blobs_roi(tol, blobs=None)[source]

Set up tolerances for matching blobs in an ROI.

Parameters:
  • tol (Sequence[float]) – Sequence of tolerances.

  • blobs (Optional[Blobs], default: None) – Blobs to resize if the first ROI profile (magmap.config.roi_profiles) resize_blobs value is given.

Return type:

Tuple[float, Sequence[float], ndarray, Sequence[float], ndarray]

Returns:

Distance map threshold, scaling normalized by tol, ROI padding shape, resize sequence retrieved from ROI profile, and blobs after any resizing.

magmap.cv.verifier.verify_rois(rois, blobs, blobs_truth, tol, output_db, exp_id, exp_name, channel)[source]

Verify blobs in ROIs by comparing detected blobs with truth sets of blobs stored in a database.

Save the verifications to a separate database with a name in the same format as saved processed files but with “_verified.db” at the end. Prints basic statistics on the verification.

Note that blobs are found from ROI parameters rather than loading from database, so blobs recorded within these ROI bounds but from different ROIs will be included in the verification.

Parameters:
  • rois – Rows of ROIs from sqlite database.

  • blobs (Blobs) – The blobs to be checked for accuracy.

  • blobs_truth (np.ndarray) – The list by which to check for accuracy, in the same format as blobs.

  • tol – Tolerance as z,y,x of floats specifying padding for the inner ROI and used to generate a single tolerance distance within which a detected and ground truth blob will be considered potential matches.

  • output_db – Database in which to save the verification flags, typical the database in :attr:config.verified_db.

  • exp_id – Experiment ID in output_db.

  • exp_name (str) – Name of experiment to store as the sample name for each row in the output data frame.

  • channel (List[int]) – Filter blobs_truth by this channel.

Returns:

Tuple of pos, true_pos, false_pos stats, feedback message, and accuracy metrics in a data frame.

Return type:

tuple[int, int, int], str, pandas.DataFrame

magmap.cv.verifier.verify_stack(filename_base, subimg_path_base, settings, segments_all, channels, overlap_base)[source]