A CLI tool and Python library for extracting vector features from geospatial raster (TIF) files using the Segment Anything Model (SAM), and exporting them as GeoJSON.
Project description
Raster Feature Extractor
A CLI tool and Python library for extracting vector features from geospatial raster (TIF) files using the Segment Anything Model (SAM), and exporting them as GeoJSON.
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 RasterFeatureExtractor
# Set up the extractor (use the path to your .pth file)
extractor = RasterFeatureExtractor(
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"
extractor.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 -
--merge: Merge overlapping polygons in output (optional) -
--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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orthomasker-0.7.0.tar.gz.
File metadata
- Download URL: orthomasker-0.7.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa1beb5ed6fef357a926d2232deecc21d9bb5496f81fcb658de269d68e5f44d3
|
|
| MD5 |
a52014621fb712d5c79d87c806a9a0fd
|
|
| BLAKE2b-256 |
afe596ae625969b48639e6a71d51de9fe4d0620c576674a052570c12906a4d40
|
File details
Details for the file orthomasker-0.7.0-py3-none-any.whl.
File metadata
- Download URL: orthomasker-0.7.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27a96f1369879524e9cc86aa6953e81add9ee13206bd6cb6af4b788ba7e5abab
|
|
| MD5 |
5a6889235ad435d6133593abfc25549c
|
|
| BLAKE2b-256 |
2dc72daa465c79fc0ad532f972fa20e7873cbe35068f04e9999ce75beae9ecd2
|