Skip to content

OBIA

PyPI PyPI Downloads Docker Pulls Tests Docs Contributors License

Object-based image analysis tools for geospatial rasters.

OBIA groups raster pixels into objects, measures their properties, and classifies them using labelled examples. Results are stored in a GeoDataFrame: a table of polygons and their attributes that you can inspect, save, and use in GIS.

With OBIA, you can:

  • Load GeoTIFFs with their coordinate reference system and spatial transform.
  • Segment imagery into object polygons.
  • Measure each object's band statistics, spectral indices, shape, and texture.
  • Transfer point labels to objects and train a classifier.
  • Train on labelled point pixels and produce a raster class map.
  • Evaluate models with grouped or spatial splits, buffers, and cross-validation.
  • Add point-cloud measurements or process large rasters in tiles when needed.

Get started

Follow the installation guide to set up OBIA. The example notebooks walk through segmentation, feature extraction, and classification with runnable code and plots.

Segment a raster

This example uses the bundled Chesapeake imagery to create polygons and measure their raster values. Replace the sample path with your GeoTIFF for your own data.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from obia.datasets import chesapeake_sample
from obia.handlers.geotif import open_geotiff
from obia.segmentation.segment import segment

image = open_geotiff(chesapeake_sample("train")["image"])

objects = segment(
    image,
    segmentation_bands=[0, 1, 2],
    statistics_bands=[0, 1, 2, 3],
    method="slic",
    n_segments=600,
    compactness=0.3,
    convert2lab=False,
)

objects.segments.to_file("segments.gpkg", driver="GPKG")
image.rasterio_obj.close()

Each row of objects.segments contains a polygon, a segment_id, and feature columns. Band indices start at zero: 0 refers to the first loaded band. segmentation_bands determines the boundaries; statistics_bands determines which bands are measured within each object.

Continue the workflow

For other workflows, see point-cloud features, large rasters, and experimental detection. The API reference documents function arguments and return values.