Metadata-Version: 2.4
Name: geotiff-tiler
Version: 0.1.3
Summary: Tool for creating patches from geo-referenced and non geo-referenced image and label pairs
Author-email: Victor Alhassan <victor.alhassan@nrcan-rncan.gc.ca>
License: MIT License
        
        Copyright (c) 2025 Victor Alhassan
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/valhassan/geotiff-tiler
Keywords: geotiff,satellite imagery,remote sensing,geospatial,image tiling,earth observation,data preparation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rasterio>=1.4.0
Requires-Dist: numpy<2.0.0,>=1.20.0
Requires-Dist: colorlog>=6.7.0
Requires-Dist: geopandas>=1.0.0
Requires-Dist: fiona>=1.9.6
Requires-Dist: tqdm>=4.65.0
Requires-Dist: zarr>=3.0.0
Requires-Dist: pystac>=1.8.0
Requires-Dist: matplotlib>=3.7.0
Requires-Dist: pyyaml>=6.0.0
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: bumpver; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: pip-tools; extra == "dev"
Dynamic: license-file

# 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

```bash
pip install geotiff-tiler
```

## Quick Start

```python
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.
