i.sam2
Integrates SAMGeo model with text prompt for segmentation in GRASS GIS.
i.sam2 group=name output=name [checkpoint_dir=name] [text_prompt=string] [text_threshold=float] [box_threshold=float] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]
Example:
i.sam2 group=name output=name
grass.script.run_command("i.sam2", group, output, checkpoint_dir=None, text_prompt=None, text_threshold=0.24, box_threshold=0.24, overwrite=False, verbose=False, quiet=False, superquiet=False)
Example:
gs.run_command("i.sam2", group="name", output="name")
Parameters
group=name [required]
Name of input imagery group
output=name [required]
Name of output segmented raster map
checkpoint_dir=name
Path to the SAMGeo model checkpoint directory (optional if using default model)
text_prompt=string
Text prompt to guide segmentation
text_threshold=float
Text threshold for text segmentation
Default: 0.24
box_threshold=float
Box threshold for text segmentation
Default: 0.24
--overwrite
Allow output files to overwrite existing files
--help
Print usage summary
--verbose
Verbose module output
--quiet
Quiet module output
--qq
Very quiet module output
--ui
Force launching GUI dialog
group : str, required
Name of input imagery group
Used as: input, group, name
output : str, required
Name of output segmented raster map
Used as: output, raster, name
checkpoint_dir : str, optional
Path to the SAMGeo model checkpoint directory (optional if using default model)
Used as: input, dir, name
text_prompt : str, optional
Text prompt to guide segmentation
text_threshold : float, optional
Text threshold for text segmentation
Default: 0.24
box_threshold : float, optional
Box threshold for text segmentation
Default: 0.24
overwrite: bool, optional
Allow output files to overwrite existing files
Default: False
verbose: bool, optional
Verbose module output
Default: False
quiet: bool, optional
Quiet module output
Default: False
superquiet: bool, optional
Very quiet module output
Default: False
DESCRIPTION
i.sam2 allows users to segment orthoimagery based on text prompts using SamGeo.
REQUIREMENTS
pip install pillow numpy torch segment-geospatial
EXAMPLES
Segment orthoimagery using SamGeo2:
i.sam2 group=rgb_255 output=tree_mask text_prompt="trees"
NOTES
The first time use will be longer as the model needs to be downloaded. Subsequent runs will be faster. Additionally, CUDA is required for GPU acceleration. If you do not have a GPU, you can use the CPU by setting the environment variable `CUDA_VISIBLE_DEVICES` to `-1`.
REFERENCES
- Wu, Q., & Osco, L. (2023). samgeo: A Python package for segmenting geospatial data with the Segment Anything Model (SAM). Journal of Open Source Software, 8(89), 5663. https://doi.org/10.21105/joss.05663
- Osco, L. P., Wu, Q., de Lemos, E. L., Gonçalves, W. N., Ramos, A. P. M., Li, J., & Junior, J. M. (2023). The Segment Anything Model (SAM) for remote sensing applications: From zero to one shot. International Journal of Applied Earth Observation and Geoinformation, 124, 103540. https://doi.org/10.1016/j.jag.2023.103540
SEE ALSO
i.segment.gsoc for region growing and merging segmentation, i.segment.hierarchical performs a hierarchical segmentation, i.superpixels.slic for superpixel segmentation.
AUTHOR
Corey T. White (NCSU GeoForAll Lab & OpenPlains Inc.)
SOURCE CODE
Available at: i.sam2 source code
(history)
Latest change: Thursday Mar 20 21:36:57 2025 in commit 7286ecf