Segment¶
geoops.segment wraps skimage.segmentation. Outputs are integer-labelled GeoArrays with the
input CRS / transform preserved.
- Thresholding:
Threshold— absolute, Otsu or"percentile:<p>"global threshold to a boolean mask (nodata excluded from the statistic and alwaysFalse) - Superpixels:
SLIC,Quickshift,Felzenszwalb - Region-based:
Watershed,RandomWalker,ChanVese - Post-processing:
ExpandLabels,MarkBoundaries,MergeNearbyInstances,MaskNMS - Tier-A primitives:
threshold_mask,otsu_threshold,resolve_threshold,fill_invalid,merge_nearby_instances,mask_nms(geoops.plume.PlumeMaskuses the same thresholding)
Operators that accept non-JSON-safe carrier params (mask, markers, label_img) set
forbid_in_yaml=True so hydra-zen won't try to round-trip them.
geoops.segment
¶
Segmentation operators backed by :mod:skimage.segmentation.
ChanVese
¶
Bases: Operator
Active-contour segmentation via :func:skimage.segmentation.chan_vese.
Expects a single-band (H, W) or (1, H, W) image. Nodata pixels
(non-finite or fill_value) are median-filled before
evolution and forced to label 0 in the output. Accepts a
GeoArray or a plain np.ndarray and returns an int32 label
map (0 = outside, 1 = inside) in the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float
|
Edge-length penalty weight; higher values give smoother boundaries. |
0.25
|
lambda1
|
float
|
Weight of the interior fitting term. |
1.0
|
lambda2
|
float
|
Weight of the exterior fitting term. |
1.0
|
tol
|
float
|
Convergence tolerance on the level set. |
0.001
|
max_num_iter
|
int
|
Maximum number of iterations. |
500
|
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
ExpandLabels
¶
Bases: Operator
Grow label regions by a fixed pixel distance without overlap.
Wraps :func:skimage.segmentation.expand_labels. Expects a
single-band (H, W) or (1, H, W) integer label map. Accepts a
GeoArray or a plain np.ndarray and returns an int32
label map in the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
float
|
Euclidean distance (in pixels) by which each labelled region is grown into the background. |
1.0
|
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
Felzenszwalb
¶
Bases: Operator
Graph-based segmentation via :func:skimage.segmentation.felzenszwalb.
Nodata pixels (non-finite or fill_value in any band) are
median-filled before segmentation and forced to label 0 in the
output; valid segments are labelled from 1.
Accepts a GeoArray or a plain
np.ndarray (channel-first) and returns an int32 label map in
the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
Free parameter controlling segment size; larger values produce larger segments. |
1.0
|
sigma
|
float
|
Width of the Gaussian pre-smoothing kernel, in pixels. |
0.8
|
min_area_px
|
int
|
Minimum segment area in pixels, enforced by
postprocessing (skimage's |
20
|
dim
|
str | None
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Called as op(image, mask=None). The optional mask is an
(H, W) (or (1, H, W)) boolean carrier on the image's pixel grid
(ValueError otherwise); pixels outside it get label 0. Pass it
positionally to wire it as a graph input,
Felzenszwalb()(Input("image"), Input("mask")).
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
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 | |
MarkBoundaries
¶
Bases: Operator
Overlay segmentation boundaries on an image for visual inspection.
Wraps :func:skimage.segmentation.mark_boundaries. Accepts a
single-band (H, W) / (1, H, W) image or a 3-band (3, H, W)
RGB image; channel-first inputs are moved to channel-last for skimage
and back afterwards. The output is always a (3, H, W) RGB overlay.
Any other band count raises ValueError. Accepts a GeoArray
or a plain np.ndarray and returns the overlay in the same carrier
kind.
Called as op(image, label_img): label_img is the single-band
integer label map whose region boundaries are drawn, on the image's
pixel grid (ValueError otherwise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
tuple[float, float, float]
|
RGB color (floats in 0-1) of the boundary lines. |
(1.0, 1.0, 0.0)
|
mode
|
str
|
Boundary style — |
'thick'
|
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
MaskNMS
¶
Bases: Operator
Mask-IoU non-maximum suppression over a stack of instance masks.
Adapted from Pérez Carrasco et al. (2026), metrics_instance_segmentation.
non_max_suppression_masks. The operator ranks instance masks by
their score (or by pixel area when no scores are supplied), then
suppresses any later mask whose mask-IoU against a kept mask exceeds
iou_threshold. Surviving masks are pasted into a 2-D label map
numbered from start_label in keep order.
Input is a (N, H, W) mask stack carrier — one plane per candidate
instance. This is the natural shape for raw detector output before
fragments have been merged into a single non-overlapping label map;
use this before :class:MergeNearbyInstances when multiple
detections may cover the same object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iou_threshold
|
float
|
Pairs with mask-IoU above this are suppressed. |
0.1
|
scores
|
ndarray | None
|
Optional length- |
None
|
start_label
|
int
|
Starting integer label for the renumbered output. |
1
|
Accepts a GeoArray or a plain np.ndarray mask stack and
returns an int32 label map in the same carrier kind, with
fill_value=0; pixels that are nodata in any plane are 0.
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
MergeNearbyInstances
¶
Bases: Operator
Merge instance labels whose bboxes are close and partially overlap.
Adapted from Pérez Carrasco et al. (2026), Plume Segmentation from
MethaneSAT with Cross-Sensor Transfer Learning and Physics-Informed
Postprocessing (merging.merge_spatial_fragments_v2). Used there as
Mask R-CNN postprocessing to stitch instance fragments split across
sliding-window patches.
Two instances are connected when their bounding boxes are within
distance_threshold pixels edge-to-edge and their box IoU is in
the open interval (iou_threshold_min, iou_threshold_max). Connected
components are then merged into single instances via pixel-wise union.
Note that the IoU lower bound is strict, so two close-but-disjoint
boxes (IoU = 0) never merge — match the paper's behavior; loosen
iou_threshold_min to 0.0 to recover proximity-only merging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance_threshold
|
float
|
Maximum edge-to-edge bbox distance (pixels). |
40.0
|
iou_threshold_min
|
float
|
Lower (exclusive) bound on box IoU. |
0.01
|
iou_threshold_max
|
float
|
Upper (exclusive) bound on box IoU. |
0.65
|
classes
|
Mapping[int, int] | list[list[int]] | None
|
Optional |
None
|
start_label
|
int
|
Starting integer label for the relabeled output. |
1
|
Accepts a single-band GeoArray or a plain np.ndarray label
map and returns an int32 label map in the same carrier kind, with
fill_value=0; nodata input pixels are 0.
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
Quickshift
¶
Bases: Operator
Mode-seeking superpixels via :func:skimage.segmentation.quickshift.
Nodata pixels (non-finite or fill_value in any band) are
median-filled before segmentation and forced to label 0 in the
output; valid segments are labelled from 1.
Accepts a GeoArray or a plain
np.ndarray (channel-first) and returns an int32 label map in
the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
float
|
Width of the Gaussian kernel used to estimate the local density. |
5.0
|
max_dist
|
float
|
Cut-off point for data distances; higher values mean fewer clusters. |
10.0
|
ratio
|
float
|
Balance (0-1) between color-space and image-space proximity. |
1.0
|
sigma
|
float
|
Width of the Gaussian pre-smoothing kernel, in pixels. |
0.0
|
dim
|
str | None
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
convert2lab
|
bool
|
Convert the image to LAB space first. Defaults to
|
False
|
Called as op(image, mask=None). The optional mask is an
(H, W) (or (1, H, W)) boolean carrier on the image's pixel grid
(ValueError otherwise); pixels outside it get label 0. Pass it
positionally to wire it as a graph input,
Quickshift()(Input("image"), Input("mask")).
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
RandomWalker
¶
Bases: Operator
Seeded segmentation via :func:skimage.segmentation.random_walker.
Expects a single-band (H, W) or (1, H, W) image. Nodata pixels
(non-finite or fill_value) are median-filled, marked
inactive (removed from the diffusion graph) and labelled 0 in the
output. Accepts a GeoArray
or a plain np.ndarray and returns an int32 label map in the
same carrier kind.
Called as op(image, markers): markers is a single-band integer
carrier of seed labels (0 = unseeded) on the image's pixel grid
(ValueError otherwise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
beta
|
float
|
Penalisation coefficient for the random-walk motion; higher values make diffusion harder across intensity edges. |
130.0
|
mode
|
str
|
Linear-system solver mode (see skimage docs). |
'cg_j'
|
tol
|
float
|
Solver convergence tolerance. |
0.001
|
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
SLIC
¶
Bases: Operator
SLIC superpixels via :func:skimage.segmentation.slic.
Nodata pixels (non-finite or fill_value in any band) are
median-filled, excluded from clustering and forced to label 0 in
the output. Accepts a GeoArray or a plain
np.ndarray (channel-first) and returns an int32 label map in
the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_segments
|
int
|
Approximate number of superpixels to produce. |
100
|
compactness
|
float
|
Balance between color and spatial proximity; higher values yield more compact (squarer) segments. |
10.0
|
sigma
|
float
|
Width of the Gaussian pre-smoothing kernel, in pixels. |
0.0
|
dim
|
str | None
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
start_label
|
int
|
First label assigned to a superpixel. |
1
|
Called as op(image, mask=None). The optional mask is an
(H, W) (or (1, H, W)) boolean carrier on the image's pixel grid
(ValueError otherwise); pixels outside it get label 0. Pass it
positionally to wire it as a graph input,
SLIC()(Input("image"), Input("mask")).
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
Threshold
¶
Bases: Operator
Binary mask of the pixels strictly above a global threshold.
Delegates to :func:geoops.segment.threshold_mask: the threshold is
an absolute number, Otsu's (1979) between-class-variance optimum, or
a percentile of the input, and the mask is values > t. The
data-driven modes use one threshold over every band and pixel of a
frame; a (T, C, H, W) time stack is thresholded frame by frame.
Nodata pixels (non-finite or equal to the input's fill value, in any
band) are excluded from the Otsu / percentile statistic and are always
False; the output declares fill_value=False. Accepts a
GeoArray or a plain np.ndarray and returns a boolean mask of
the input's shape in the same carrier kind.
:class:geoops.plume.PlumeMask is this thresholding followed by a
minimum-component-size filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
ThresholdMode
|
|
'otsu'
|
nbins
|
int
|
Histogram bins for the |
256
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> mask = gz.segment.Threshold(threshold="otsu")(score_map)
>>> hot = gz.segment.Threshold(threshold="percentile:99")(score_map)
>>> above = gz.segment.Threshold(threshold=0.5)(probability)
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
Watershed
¶
Bases: Operator
Watershed segmentation via :func:skimage.segmentation.watershed.
Expects a single-band (H, W) or (1, H, W) image. Nodata pixels
(non-finite or fill_value) are median-filled, masked out of
the flooding and forced to label 0 in the output. Accepts a
GeoArray or a plain np.ndarray and returns an int32 label
map in the same carrier kind.
Called as op(image, markers=None, mask=None), both optional
carriers on the image's pixel grid (ValueError otherwise):
markers is a single-band integer array seeding the basins (when
omitted, local minima of the image are used) and mask an
(H, W) (or (1, H, W)) boolean mask; pixels outside it get
label 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connectivity
|
Connectivity
|
|
4
|
compactness
|
float
|
Compactness parameter; higher values produce more regularly-shaped basins. |
0.0
|
watershed_line
|
bool
|
Separate basins with a zero-labelled line. |
False
|
Source code in packages/geotoolz-ops/src/geoops/segment/_src/operators.py
fill_invalid(image, valid)
¶
Float copy of image with every invalid pixel set to the valid median.
The fill statistic is the median over valid pixels only, so neither a
fill_value sentinel nor +/-inf can leak into it. The
segmenters run on the filled image, because skimage has no notion of
nodata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Num[ndarray, '*dims']
|
|
required |
valid
|
Bool[ndarray, 'h w']
|
|
required |
Returns:
| Type | Description |
|---|---|
Float[ndarray, '*dims']
|
A float copy ( |
Float[ndarray, '*dims']
|
valid). An image with no valid pixel is filled with |
Examples:
>>> image = np.array([[1.0, 2.0], [3.0, -9999.0]])
>>> fill_invalid(image, image != -9999.0)
array([[1., 2.],
[3., 2.]])
Source code in packages/geotoolz-ops/src/geoops/segment/_src/array.py
mask_nms(masks, scores, iou_threshold, start_label)
¶
Suppress overlapping mask predictions via mask-IoU and stitch survivors into a 2-D label map (suppressed planes -> background).
Mirrors Pérez Carrasco et al. (2026), non_max_suppression_masks.
When scores is None instances are ranked by area, largest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
Num[ndarray, 'n h w'] | Bool[ndarray, 'n h w']
|
|
required |
scores
|
Float[ndarray, ' n'] | None
|
|
required |
iou_threshold
|
float
|
Masks whose IoU with a kept mask exceeds this are suppressed. |
required |
start_label
|
int
|
Label of the first kept mask. |
required |
Returns:
| Type | Description |
|---|---|
Int[ndarray, 'h w']
|
|
Int[ndarray, 'h w']
|
overlapping pixels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> masks = np.zeros((2, 3, 3), dtype=bool)
>>> masks[0, :2], masks[1, :3] = True, True
>>> mask_nms(masks, None, 0.5, 1)
array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
Source code in packages/geotoolz-ops/src/geoops/segment/_src/array.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
merge_nearby_instances(labels, *, distance_threshold, iou_threshold_min, iou_threshold_max, classes, start_label)
¶
Merge instance labels whose bboxes are close and partially overlap.
Connectivity rule (from Pérez Carrasco et al. 2026):
two instances are connected iff their bbox edge-to-edge distance is
strictly below distance_threshold and their box IoU lies in the
open interval (iou_threshold_min, iou_threshold_max).
Connected components are then merged via pixel-wise union.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Num[ndarray, 'h w']
|
|
required |
distance_threshold
|
float
|
Maximum edge-to-edge bbox distance (pixels), exclusive. |
required |
iou_threshold_min
|
float
|
Lower (exclusive) bound on box IoU. |
required |
iou_threshold_max
|
float
|
Upper (exclusive) bound on box IoU. |
required |
classes
|
Mapping[int, int] | None
|
Optional |
required |
start_label
|
int
|
First label of the relabelled output. |
required |
Returns:
| Type | Description |
|---|---|
Int[ndarray, 'h w']
|
|
Int[ndarray, 'h w']
|
in order of their first member label. |
Examples:
>>> labels = np.full((4, 4), 2) # an L-shaped 1 wrapping a block of 2
>>> labels[0, :], labels[:, 0] = 1, 1
>>> np.unique(merge_nearby_instances(
... labels, distance_threshold=5, iou_threshold_min=0.0,
... iou_threshold_max=1.0, classes=None, start_label=1))
array([1])
Source code in packages/geotoolz-ops/src/geoops/segment/_src/array.py
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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
otsu_threshold(values, *, nbins=256)
¶
Compute Otsu's between-class-variance threshold, ignoring NaNs.
Builds an nbins-bin histogram of the finite values and returns
the bin center that maximises the between-class variance
w_bg * w_fg * (mu_bg - mu_fg)^2 (Otsu, 1979). A constant input
returns that constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Num[ndarray, '*dims']
|
Array of any shape; non-finite entries are ignored. |
required |
nbins
|
int
|
Number of histogram bins. Default |
256
|
Returns:
| Type | Description |
|---|---|
float
|
The threshold; pixels strictly above it are foreground. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Source code in packages/geotoolz-ops/src/geoops/segment/_src/array.py
resolve_threshold(values, threshold, *, nbins=256)
¶
Resolve an absolute, Otsu, or percentile threshold to a float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Num[ndarray, '*dims']
|
Data the data-driven modes are evaluated on. |
required |
threshold
|
ThresholdMode
|
A number (returned as-is), |
required |
nbins
|
int
|
Histogram bins for the |
256
|
Returns:
| Type | Description |
|---|---|
float
|
The resolved threshold value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a string threshold is neither |
Examples:
>>> resolve_threshold(np.arange(101.0), "percentile:90")
90.0
>>> resolve_threshold(np.arange(101.0), 3)
3.0
Source code in packages/geotoolz-ops/src/geoops/segment/_src/array.py
threshold_mask(values, threshold='otsu', *, nbins=256)
¶
Binary mask of the samples strictly above a resolved threshold.
mask = values > t, t = resolve_threshold(values, threshold)
Non-finite samples are ignored by the data-driven modes and are never
foreground (NaN > t is False).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Num[ndarray, '*dims']
|
Array of any shape; mark nodata as |
required |
threshold
|
ThresholdMode
|
A number, |
'otsu'
|
nbins
|
int
|
Histogram bins for the |
256
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*dims']
|
Boolean array shaped like |
Examples: