Skip to content

Add image segmentation for object-based raster analysis #1138

@brendancol

Description

@brendancol

Motivation

Object-based image analysis (OBIA) is a standard workflow in land cover mapping and remote sensing. The typical pipeline is: segment the image into regions, compute statistics per region, then classify regions. xarray-spatial has nothing for the segmentation step, so users can't do OBIA without leaving the library.

Scope

Segmentation algorithms:

  • Superpixel segmentation (SLIC or similar) that works on multi-band rasters
  • Watershed segmentation from gradient/edge images
  • Region growing from user-supplied seed points

Segment-level statistics:

  • Mean, std, min, max of spectral values per segment
  • Shape metrics per segment: area, perimeter, compactness, elongation
  • Output as a segment attribute table (pandas/xarray Dataset)

Implementation notes

  • Output should be an integer-labeled raster, consistent with what regions() already produces. This lets existing zonal stats functions work on the segments directly.
  • The hard part is dask compatibility. Segmentation is inherently a global operation since segments can span chunk boundaries. Realistic options:
    • Run segmentation on the full array (fine for moderate sizes, and what most users actually do)
    • Two-pass approach: segment each chunk independently, then merge segments that touch at boundaries
    • Keep segmentation as a non-dask operation, but make the downstream stat extraction dask-friendly
  • For GPU support, SLIC and watershed both have known CUDA implementations. Region growing is trickier on GPU but possible with iterative kernel launches.
  • Multi-band input means the segmentation functions need to accept a 3D (band, y, x) DataArray or a list of 2D DataArrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions