Skip to main content

CLI tool to convert TIF files to GeoJSON with automatic mask generation using Meta AI's Segment Anything Model (SAM)

Project description

TIF to GeoJSON Converter

A CLI tool that converts TIF files to GeoJSON format with automatic mask generation.

Installation

pip install orthomasker

Usage

# Using CLI
orthomasker your_input_filename.tif your_output_filename.geojson --sam-checkpoint sam_vit_h_4b8939.pth --confidence-threshold 80 --min-area 100 --max-area 10000 --verbose

# Using Python
from orthomasker.converter import TifToGeoJsonConverter

# Set up the converter (use the path to your .pth file)
converter = TifToGeoJsonConverter(
    sam_checkpoint="sam_vit_h_4b8939.pth",
    confidence_threshold=80.0,
    min_area=100.0,      # Optional: filter by minimum area
    max_area=10000.0,    # Optional: filter by maximum area
    verbose=True,
)

# Provide your own test TIF file (upload or use a sample)
input_tif = "your_input_filename.tif"
output_geojson = "your_output_filename.geojson"

converter.convert(input_tif, output_geojson)

Options

  • --sam-checkpoint: Path to SAM model weights (default: sam_vit_h_4b8939.pth)

  • --model-type: SAM model type (vit_h, vit_l, vit_b; default: vit_h)

  • --confidence-threshold: Minimum stability score to keep a mask (0–100; default: 0, no filter)

  • --tile-size: Tile size for processing (default: 1024)

  • --overlap: Tile overlap in pixels (default: 128)

  • --class-name: Class label for output features (default: sam_object)

  • --min-area: Minimum area (in square units of TIF CRS) for output features (optional)

  • --max-area: Maximum area (in square units of TIF CRS) for output features (optional)

  • --fixed-bounds: Bounding box (minx, miny, maxx, maxy) in image CRS

  • --verbose: Enable verbose output

Development

Setup

git clone https://github.com/nickmccarty/orthomasker.git
cd orthomasker
pip install -r requirements.txt
pip install -e ".[ml,dev]"

Acknowledgments

This project leverages Meta AI’s Segment Anything Model (SAM) for automatic mask generation, which is faciliated by utilizing segment-anything-py as a dependency; many thanks to Wu, et al. for their work!

Citations

@article{kirillov2023segany,
title={Segment Anything},
author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C. and Lo, Wan-Yen and Doll{'a}r, Piotr and Girshick, Ross},
journal={arXiv:2304.02643},
year={2023}
}

License

MIT License - see LICENSE file for details.

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

orthomasker-0.3.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

orthomasker-0.3.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for orthomasker-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3cf393ac03ab4577db2fce44db1426de5c7e1df8695db9f034ca6cb14ba79efe
MD5 3e7ff8398839c2a92f57f8a22bddabac
BLAKE2b-256 bde81895174dde4fd87a931c8da580601e2c35f369567df455b834b78089df4d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for orthomasker-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f39019a4530d09a3afc78ff8fd75cda036242680b07b4231d3bf35e2f42215ce
MD5 fe9a0ce33758c78062a5b8b23e54e8b7
BLAKE2b-256 18b3ff5abe3e3751b43e7bb2d1dc137ed6e21562d53548702bffe548cf123d1c

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