Skip to main content

Python library for water segmentation in high to moderate resolution remotely sensed imagery

Project description

OmniWaterMask

OmniWaterMask is a Python library for high accuracy water segmentation in high to moderate resolution satellite imagery, supporting a wide range of resolutions, sensors, and processing levels.

Features

  • Process imagery resolutions from 0.2 m to 50 m.
  • Any imagery processing level
  • Only requires Red, Green, Blue and NIR bands
  • Known to work well with Sentinel-2, Landsat 8, PlanetScope, Maxar and NAIP

Try in Colab

Colab_Button

How it works

OmniWaterMask integrates a sensor agnostic deep learning segmentation model with NDWI and vector datasets to detect water bodies within remote sensing products.

Paper coming soon...

Installation

To install the package, use one of the following commands:

Make sure you are running Python 3.9 or above and

conda create -n owm python=3.12
conda activate owm

pip install omniwatermask
conda create -n owm python=3.12
conda activate owm

pip install git+https://github.com/DPIRD-DMA/OmniWaterMask.git

Usage

To predict a water mask for a list of scenes simply pass a list of geotiff files to the make_water_mask function along with the band order for the Red, Green, Blue and NIR bands. Predictions are saved to disk along side the input as geotiffs, a list of prediction file paths is returned:

from pathlib import Path
from omniwatermask import make_water_mask

scene_paths = [Path("path/to/scene1.tif"), Path("path/to/scene2.tif")]

# Predict water masks for scenes
water_mask_path = make_water_mask(
    scene_paths=[scene_paths],  # you can pass a list of images
    band_order=[1, 2, 3, 4],  # band order of the input images, expects RGB+NIR
)

Output

  • Output classes are:
  • 0 = Non-water
  • 1 = water

Usage tips

  • OWM requires an active internet connection to function properly, as it needs to download OpenStreetMap (OSM) data.

  • Hardware acceleration is strongly recommended:

    • NVIDIA GPU
    • Apple Silicon Mac
    • Other PyTorch-compatible accelerators
  • Consider enabling "bf16" inference_dtype on compatible hardware - this typically results in faster processing speeds.

  • If experiencing VRAM limitations even with batch_size=1, switching the 'mosaic_device' parameter to 'cpu' can help.

  • Improve accuracy by providing known water body locations as 'aux_vector_sources' - simply pass a list of file paths pointing to your water polygon datasets.

  • Reduce false positives by including vector data for common misidentification sources (buildings, roads) through the 'aux_negative_vector_sources' parameter.

  • When working with scenes containing no-data regions, explicitly set the 'no_data_value' parameter to ensure proper handling of these areas.

Parameters

  • scene_paths: List of paths or single path (supports both Path and string types) to the input satellite/aerial imagery

  • band_order: List of integers specifying the band order for input imagery (e.g., [1,2,3,4] if your input image is stored with band order red, green, blue then NIR data). This tells OWM which bands correspond to Red, Green, Blue, and Near-Infrared channels

  • batch_size: Number of patches processed simultaneously during inference. Default is 1, increase for better GPU utilization

  • version: Version identifier for the output files. Defaults to current OmniWaterMask version

  • output_dir: Optional path for output files. If not specified, outputs are saved alongside input files

  • mosaic_device: Device for mosaic operations ("cpu", "cuda" or "mps"). Defaults to system's default device

  • inference_device: Device for model inference ("cpu", "cuda" or "mps"). Defaults to system's default device

  • aux_vector_sources: List of paths to supplementary water body vector data to aid detection

  • aux_negative_vector_sources: List of paths to vector data marking areas commonly misidentified as water

  • inference_dtype: Data type for inference operations. Defaults to torch.float32

  • no_data_value: Value indicating no-data regions in the input imagery. Defaults to 0

  • inference_patch_size: Size of image patches for inference. Defaults to 1000 pixels

  • inference_overlap_size: Overlap between adjacent patches during inference. Defaults to 300 pixels

  • overwrite: Whether to overwrite existing output files. Defaults to True

  • use_cache: Whether to cache vector data processing results. Defaults to True

  • use_osm_building: Whether to use OpenStreetMap building data to reduce false positives. Defaults to True

  • use_osm_roads: Whether to use OpenStreetMap road data to reduce false positives. Defaults to True

  • cache_dir: Directory for storing cached vector data. Defaults to "OWM_cache" in current directory

  • destination_model_dir: Directory to save the model weights. Defaults to None

  • model_download_source: Source from which to download the model weights. Defaults to "hugging_face", can also be "google_drive".

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

License

This project is licensed under the MIT License

Acknowledgements

Special thanks to the S1S2-Water dataset authors and The FLAIR #1 dataset authors for providing the valuable training datasets.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

omniwatermask-0.3.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omniwatermask-0.3.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file omniwatermask-0.3.0.tar.gz.

File metadata

  • Download URL: omniwatermask-0.3.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for omniwatermask-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3c5f7c30592e4e5c99a00c92e252e7fccf4cf60799b782a83c15053cc65670da
MD5 7d943482f2bf5ae748df3f5a1d747abb
BLAKE2b-256 c47b0289849530acbedae1c7771093857b600a4182ee2896ce9728e9e024d1ad

See more details on using hashes here.

File details

Details for the file omniwatermask-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: omniwatermask-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for omniwatermask-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 593c88843bc7a2baaa1ae86552daf087b2edd79b9700df0c88ac999026cc734d
MD5 439b428672fbc2ceebc2bb2a0f8c96c2
BLAKE2b-256 8f774a6893f1ada3fc5fcc81db303750513c1c35f1b79844a5e535b09719de6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page