mask¶
Mask creation and manipulation for page regions and text/line detection.
This module provides:
- A helper function (
box) to generate structuring elements for morphological ops. - A
Maskclass, which thresholds the page image, applies morphological operations, and blends the resulting mask with a page mask. - An interface to retrieve the final contours from this mask.
Mask ¶
A thresholded mask builder for text (or line) detection.
Combines adaptive thresholding, morphological dilations/erosions, and
a given pagemask to produce the final mask used for contour extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
A string identifier for debugging/logging. |
required |
small
|
|
A reduced-size (downsampled) version of the original image. |
required |
pagemask
|
|
A binary mask indicating the valid page region. |
required |
text
|
|
If True, process as text; if False, process as lines. |
True
|
Source code in src/page_dewarp/mask.py
calculate ¶
Apply adaptive thresholding and morphological ops to create self.value.
Steps:
- Convert
self.smallto grayscale. - Use an adaptive threshold (binary inverse).
- Depending on
self.text, either dilate or erode the result, log intermediate steps. - Combine with
self.pagemaskto finalize the mask (store inself.value).
Source code in src/page_dewarp/mask.py
log ¶
Optionally display or log the intermediate mask state at a given step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
|
A numeric code or fraction indicating the process step. |
required |
text
|
|
A label describing what operation was just done (e.g. 'dilated'). |
required |
display
|
|
The mask or image array to show for debugging. |
required |
Source code in src/page_dewarp/mask.py
contours ¶
Extract the final contours from self.value.
Calls get_contours to find external contours in the thresholded,
morphological-processed mask stored in self.value.
Returns:
| Type | Description |
|---|---|
|
A list of ContourInfo objects describing each discovered contour. |
Source code in src/page_dewarp/mask.py
box ¶
Return a structuring element of ones with shape (height, width).
Used in morphological operations (e.g., dilate, erode).