Post processing¶
The dh_segment.post_processing
module contains functions to post-process probability maps.
Binarization
|
Computes the binary mask of the detected Page from the probabilities output by network. |
|
Uses mathematical morphology to clean and remove small elements from binary images. |
Detection
|
Finds the coordinates of the box in the binary image boxes_mask. |
|
Finds the shapes in a binary mask and returns their coordinates as polygons. |
Vectorization
|
Finds the longest central line for each connected component in the given binary mask. |
-
dh_segment.post_processing.
thresholding
(probs, threshold=-1)¶ Computes the binary mask of the detected Page from the probabilities output by network.
- Parameters
probs (
ndarray
) – array in range [0, 1] of shape HxWx2threshold (
float
) – threshold between [0 and 1], if negative Otsu’s adaptive threshold will be used
- Return type
ndarray
- Returns
binary mask
-
dh_segment.post_processing.
cleaning_binary
(mask, kernel_size=5)¶ Uses mathematical morphology to clean and remove small elements from binary images.
- Parameters
mask (
ndarray
) – the binary image to cleankernel_size (
int
) – size of the kernel
- Return type
ndarray
- Returns
the cleaned mask
-
dh_segment.post_processing.
find_boxes
(boxes_mask, mode='min_rectangle', min_area=0.2, p_arc_length=0.01, n_max_boxes=inf)¶ Finds the coordinates of the box in the binary image boxes_mask.
- Parameters
boxes_mask (
ndarray
) – Binary image: the mask of the box to find. uint8, 2D arraymode (
str
) – ‘min_rectangle’ : minimum enclosing rectangle, can be rotated ‘rectangle’ : minimum enclosing rectangle, not rotated ‘quadrilateral’ : minimum polygon approximated by a quadrilateralmin_area (
float
) – minimum area of the box to be found. A value in percentage of the total area of the image.p_arc_length (
float
) – used to compute the epsilon value to approximate the polygon with a quadrilateral. Only used when ‘quadrilateral’ mode is chosen.n_max_boxes – maximum number of boxes that can be found (default inf). This will select n_max_boxes with largest area.
- Return type
list
- Returns
list of length n_max_boxes containing boxes with 4 corners [[x1,y1], …, [x4,y4]]
-
dh_segment.post_processing.
find_polygonal_regions
(image_mask, min_area=0.1, n_max_polygons=inf)¶ Finds the shapes in a binary mask and returns their coordinates as polygons.
- Parameters
image_mask (
ndarray
) – Uint8 binary 2D arraymin_area (
float
) – minimum area the polygon should have in order to be considered as valid (value within [0,1] representing a percent of the total size of the image)n_max_polygons (
int
) – maximum number of boxes that can be found (default inf). This will select n_max_boxes with largest area.
- Return type
list
- Returns
list of length n_max_polygons containing polygon’s n coordinates [[x1, y1], … [xn, yn]]
-
dh_segment.post_processing.
find_lines
(lines_mask)¶ Finds the longest central line for each connected component in the given binary mask.
- Parameters
lines_mask (
ndarray
) – Binary mask of the detected line-areas- Return type
list
- Returns
a list of Opencv-style polygonal lines (each contour encoded as [N,1,2] elements where each tuple is (x,y) )