Skip to main content

Tool for creating patches from geo-referenced and non geo-referenced image and label pairs

Project description

GeoTIFF Tiler

A Python package for creating training patches from geospatial imagery and label pairs for machine learning applications.

Overview

GeoTIFF Tiler is designed to streamline the creation of training data patches from geo-referenced and non-geo-referenced image and label pairs. It helps prepare data for machine learning models requiring consistent input dimensions, particularly for geospatial applications.

Features

  • Create patches of specified size from image-label pairs
  • Support for various input formats:
    • Images: GeoTIFFs (geo-referenced and non-geo-referenced), STAC imagery
    • Labels: GeoTIFFs (geo-referenced and non-geo-referenced), vector data (.geojson, .gpkg, .shp)
  • Intelligent patch filtering based on label content
  • Padding for edge patches to maintain consistent dimensions
  • Automatic handling of CRS and alignment issues
  • Output in Zarr format for efficient storage and access
  • Visualization tools for quality assessment

Installation

pip install geotiff-tiler

Quick Start

from geotiff_tiler.tiler import Tiler

# Define your image-label pairs with metadata
data = [{
    "image": "./path/to/image.tif",
    "label": "./path/to/label.tif",
    "metadata": {"collection": "satellite-name", "gsd": 0.5}
}]

# Initialize the tiler with your configuration
tiler = Tiler(
    input_dict=data,
    patch_size=(256, 256),  # Height, Width
    attr_field=["class", "category"],  # Field(s) in vector data to use for labels
    attr_values=[1, 2, 3],  # Values to extract from the fields
    stride=128,             # Overlap between patches
    discard_empty=True,     # Skip patches with no labels
    label_threshold=0.05,   # Minimum non-zero label coverage
    output_dir='./output/patches'
)

# Create the patches
tiler.create_tiles()

Using STAC Items

The library supports STAC (SpatioTemporal Asset Catalog) items, making it compatible with cloud-native geospatial workflows.

Parameters

  • input_dict: List of dictionaries with "image", "label", and "metadata" keys
  • patch_size: Tuple of (height, width) for the output patches
  • attr_field: Field name(s) in vector data to use for labeling (list of strings)
  • attr_values: Values to extract from the attribute field (list of strings or numbers)
  • stride: Spacing between patches (determines overlap); if None, uses max(patch_size)
  • discard_empty: Whether to skip patches with no labels
  • label_threshold: Minimum fraction of non-zero pixels required in a label patch
  • output_dir: Directory to save the output patches

Output Format

Patches are saved in Zarr format with the following structure:

  • images: Array of image patches [N, C, H, W]
  • labels: Array of label patches [N, H, W]
  • positions: Array of patch locations [N, 2]
  • metadata: Dictionary with additional information

A csv file is created of the zarr paths.

License

MIT License

Author

Victor Alhassan (victor.alhassan@nrcan-rncan.gc.ca)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

geotiff_tiler-0.1.2.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

geotiff_tiler-0.1.2-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file geotiff_tiler-0.1.2.tar.gz.

File metadata

  • Download URL: geotiff_tiler-0.1.2.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for geotiff_tiler-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c3ce532cbb00832999746fde9c43c5943f51bdc8bf7accfb3b7eabbaa2fe75be
MD5 bbd99468432c030bd0a94119db810e25
BLAKE2b-256 820e102439b816562fdcadccf1015a3e81a85ea706db85027397e59dc2377515

See more details on using hashes here.

File details

Details for the file geotiff_tiler-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: geotiff_tiler-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for geotiff_tiler-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 59dd754fe820d5d11f69c502e0d36f9704f0d737007e2c0592cd41ee4ddd3a57
MD5 77cf45fbf98163b2d63827b07efc7123
BLAKE2b-256 1cc711a1d655a7c8dc0d9c9bd7ca7afe4c57d0f4c3ab5a4a85f7b08400ad8ce8

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