Geometric
geometric
¶
Functions:¶
ellipse_mask(image_shape, center, axes, angle_rad=0.0)
¶
Return a boolean mask with True inside the specified ellipse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_shape
|
Tuple[int, int]
|
(Height, width) tuple for the shape of the mask we want to return |
required |
center
|
Tuple[int, int]
|
(x0, y0) center of the ellipse in x and y (pixels) |
required |
axes
|
Tuple[int, int]
|
(a, b) semi-major and semi-minor axis lengths in pixels |
required |
angle_rad
|
float
|
Rotation angle of the semi-major axis, in radians. CCW from x-axis (a.k.a. right-hand rule out of the image). Defaults to 0. |
0.0
|
Returns:
| Name | Type | Description |
|---|---|---|
mask |
np.ndarray of shape (H, W), dtype=bool |
Source code in tree_detection_framework/utils/geometric.py
get_shapely_transform_from_matrix(matrix_transform)
¶
Take a matrix transform and convert it into format expected by shapely: [a, b, d, e, xoff, y_off]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix_transform
|
ndarray
|
(2, 3) or (3, 3) 2D transformation matrix such that the matrix-vector product produces the transformed value. |
required |
Source code in tree_detection_framework/utils/geometric.py
make_polygon_set_nonoverlapping(polygons, epsilon=1e-06, vis=False)
¶
Take a set of polygons and return an updated set representing the "core" nonoverlapping regions such that each core region represents the space which is farthest interior to that polygon, compared to all other polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygons
|
List[Polygon]
|
A list of polygons which may have pairwise overlaps. Note, this approach may fail if two polygons are identical or a strict subset of another one. |
required |
epsilon
|
float
|
Used for numerical stability. Defaults to 1e-6. |
1e-06
|
vis
|
bool
|
Show the pairwise compuations. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If there are multiple polygons in an intersecting region. |
Returns:
| Type | Description |
|---|---|
List[Polygon]
|
List[shapely.geometry.polygon.Polygon]: The core regions, ordered the same way as the input |
Source code in tree_detection_framework/utils/geometric.py
mask_to_shapely(mask, simplify_tolerance=0, backend='contourpy')
¶
Convert a binary mask to a Shapely MultiPolygon representing positive regions, with optional simplification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
ndarray
|
A (n, m) A mask with boolean values. |
required |
simplify_tolerance
|
float
|
Tolerance for simplifying polygons. A value of 0 means no simplification. |
0
|
backend
|
str
|
The backend to use for contour extraction. Choose from "cv2" and "contourpy". Defaults to contourpy. |
'contourpy'
|
Returns:
| Type | Description |
|---|---|
MultiPolygon
|
shapely.MultiPolygon: A MultiPolygon representing the positive regions. |
Source code in tree_detection_framework/utils/geometric.py
ordered_voronoi(points, tolerance=1e-06)
¶
The shapely version we are using does not order the voronoi polygons in the same way as the input points. This wrapper does that.
Source code in tree_detection_framework/utils/geometric.py
split_overlapping_region(poly1, poly2, epsilon=1e-06, vis=False, segmentize_multiplier=20.0)
¶
Take two potentially-overlapping polygons and return the non-overlapping version of them such that any overlapping regions are split between the two. This is done by finding any overlapping regions and splitting them with a straight line that is equidistant to the two non-overlapping portions of the polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poly1
|
Polygon
|
First polygon |
required |
poly2
|
Polygon
|
Second polygon |
required |
epsilon
|
float
|
Used for numerical stability. Defaults to 1e-6. |
1e-06
|
vis
|
bool
|
Whether to show intermediate results. Defaults to False. |
False
|
segmentize_multiplier
|
float
|
Use roughly this many points per dimension when calling "segmentize" to densify the polygon boundary. Defaults to 20.0. |
20.0
|
Returns:
| Type | Description |
|---|---|
Tuple[Polygon, Polygon]
|
Tuple[shapely.Polygon, shapely.Polygon]: The non-overlapping versions of the input polygons |
Source code in tree_detection_framework/utils/geometric.py
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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |