preprocessing.extract_segments
Functions
- extract_segments_from_labels
Extracts segments from a label classification.
- extract_segments_from_bounds
Extracts segments from
Rect
bounds.- remove_small_segments_from_labels
Removes small segments from a label classification.
Extract with Boundaries
A boundary is a Rect
object that represents the minimum bounding box of a segment, with x0, y0, x1, y1 coordinates.
It simply slices the original image to the bounding box. The origin is the top left corner of the image.
Extract with Labels
A label classification is a np.ndarray
where each pixel is mapped to a segment. The segments are mapped to a unique integer. In our project, the 0th label is the background.
For example, a label classification of 3 segments will look like this:
The extraction will take the minimum bounding box of each segment and return a list of segments.
For example, the label 1 and 2 extracted images will be
If cropped is False, the segments are padded with 0s to the original image size. While this can ensure shape consistency, it can consume more memory for large images.
If cropped is True, the segments are cropped to the minimum bounding box. This can save memory, but the shape of the segments will be inconsistent.
Usage
Extract from Bounds and Labels
Extract segments from bounds and labels.
Extract from Auto-Segmentation
Extract segments from a label classification.
API
- extract_segments_from_labels(ar, ar_labels, cropped)
Extracts segments from a label classification.
ar_labels
is a label classification as anp.ndarray
- extract_segments_from_bounds(ar, bounds, cropped)
Extracts segments from
Rect
bounds.bounds
is a list ofRect
bounds.- remove_small_segments_from_labels(ar_labels, min_height, min_width)
Removes small segments from a label classification.