Features Subpackage
- cv2_group.features.feature_extraction.analyze_primary_root(root_instances: List[ndarray | None], original_roi_indices: List[int]) List[Dict[str, Any]]
Analyze each primary root binary mask instance to extract geometric and path features.
- Parameters:
root_instances (list of np.ndarray or None) – List of binary masks representing individual root instances. Elements can be None if no root was detected.
original_roi_indices (list of int) – Indices mapping each root instance back to the original ROI.
- Returns:
- Each dict contains:
’roi_index’ (int): ROI index for this root.
’length’ (float): Length of the primary root path.
’tip_coords’ (list or None): Coordinates [y, x] of the root tip.
’base_coords’ (list or None): Coordinates [y, x] of the root base.
’primary_path’ (list or None): List of coordinates of the primary root.
- Return type:
list of dict
- cv2_group.features.feature_extraction.extract_root_instances(label_ids: ndarray, max_label_ids_for_rois: List[int | None]) List[ndarray | None]
Extract binary masks for individual root instances from a labeled image. Each extracted mask will have values 0 or 1.
- Parameters:
label_ids (np.ndarray) – Array with labeled connected components.
max_label_ids_for_rois (List[Optional[int]]) – List of label IDs to extract, corresponding to identified ROIs. Can contain None for ROIs where no label was found.
- Returns:
List of binary masks (0 or 1) for each root instance, or None if no instance was found for a given ROI.
- Return type:
List[Optional[np.ndarray]]
- cv2_group.features.feature_extraction.find_labels_in_rois(label_ids: ndarray, total_labels: int, stats: ndarray, rois: List[Tuple[int, int, int, int]]) Tuple[Dict[str, int | None], List[int]]
Identify root labels within defined regions of interest (ROIs). Prioritizes the label with the maximum height within each ROI. Handles cases where no ROIs are provided, returning no specific labels.
- Parameters:
label_ids (np.ndarray) – Array with labeled connected components.
total_labels (int) – Total number of labels found.
stats (np.ndarray) – Statistics for each connected component.
rois (List[Tuple[int, int, int, int]]) – List of ROIs, each as (x, y, width, height).
- Returns:
- max_label_dict: Dictionary mapping “label_idx” to the identified
label ID, or None if no label found in ROI.
max_label_list: List of identified label IDs (can contain None).
- Return type:
Tuple[Dict[str, Optional[int]], List[int]]
- cv2_group.features.feature_extraction.process_predicted_mask(predicted_mask: ndarray) Tuple[ndarray, ndarray, int, ndarray, ndarray]
Process a binary mask to generate labeled root instances using connected components analysis. This function is designed to accept masks from both model prediction and user edits.
- Parameters:
predicted_mask (np.ndarray) – Input mask (2D array), values can be 0 or 1, or 0-255. It will be normalized to 0 or 255 (uint8) for processing.
- Returns:
binary_mask: The input mask ensured to be 0/255 uint8.
label_ids: Labeled connected components.
total_labels: Total number of labels found.
stats: Statistics for each connected component.
centroids: Centroids for each connected component.
- Return type:
Tuple[np.ndarray, np.ndarray, int, np.ndarray, np.ndarray]