dewarp¶
Remapping and thresholding logic for page dewarping.
This module provides:
- A helper function,
round_nearest_multiple, to round integers up to the nearest multiple. - A
RemappedImageclass that transforms (remaps) an input image to a rectified, thresholded output using a cubic parameterization of the page.
RemappedImage ¶
RemappedImage(name: str, img: ndarray, small: ndarray, page_dims: list | ndarray, params: ndarray, config: Config = Config())
Rectify and threshold an image based on a cubic page parameterization.
This class takes an input image and outputs a warped, thresholded version (optionally binarized) according to parameters specifying the page's layout.
Note
It's currently implemented as a class but may be refactored into a standalone function, as it stores little permanent state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
A string name or identifier for the output file. |
required |
img
|
|
The original, full-resolution image as a NumPy array. |
required |
small
|
|
A downsampled version of |
required |
page_dims
|
|
A (width, height) tuple or array specifying the target page dimensions in normalized units. |
required |
params
|
|
The cubic parameters for warping (rotation, translation, etc.). |
required |
config
|
|
A |
|
Source code in src/page_dewarp/dewarp.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
round_nearest_multiple ¶
Round an integer i up to the nearest multiple of factor.
If i is already a multiple of factor, it remains unchanged;
otherwise, we add the difference to i to reach the multiple.