image_to_graph
pleat.image_to_graph ¶
Extract a half-edge graph from a raster image of a line drawing.
Thresholds an input image, skeletonises the foreground, and reconstructs a
planar graph from the skeleton via :mod:mahotas and :mod:networkx.
Intended for digitising hand-drawn or otherwise genereated images of line drawings.
branchedPoints ¶
Detect branch points (degree>=3 pixels) in a binary skeleton via hit-or-miss matching.
Source code in pleat/image_to_graph.py
endPoints ¶
Detect endpoints (degree-1 pixels) in a binary skeleton via hit-or-miss matching.
Source code in pleat/image_to_graph.py
pruning ¶
remove iteratively end points "size" times from the skeleton
Source code in pleat/image_to_graph.py
image_to_graph ¶
image_to_graph(
image: str | ndarray,
threshold: float = 75,
closing_iterations: int = 3,
edge_length_cutoff: float = 40,
max_size: int = 1000,
) -> "pleat.half.EuclideanPositionHEG"
Extract a planar half-edge graph from a raster image of a line drawing.
Pipeline: downscale, threshold, morphological close, skeletonise, prune,
detect branch points, build a NetworkX graph, then convert to a
:class:~pleat.half.EuclideanPositionHEG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str | ndarray
|
Path to an RGB image file or an |
required |
threshold
|
float
|
Grayscale cutoff separating dark foreground from light background, on the scale of the image values. The plotted grayscale histogram helps tune it per image. |
75
|
closing_iterations
|
int
|
Number of binary closing iterations applied to connect broken lines. |
3
|
edge_length_cutoff
|
float
|
Distance (in pixels) below which adjacent branch points are merged. The plotted edge-length histogram helps tune it. |
40
|
max_size
|
int
|
Maximum image side length; image is halved repeatedly until it fits. |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
'pleat.half.EuclideanPositionHEG'
|
class: |
'pleat.half.EuclideanPositionHEG'
|
derived from the skeleton's branch points. |
Source code in pleat/image_to_graph.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |