Skip to content

william-amory/Segment_with_sam2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SegmentWithSAM2

This is a small tool and Marimo notebook to segment image with SAM2.


Usage

🔵 In command line

uv run python SegmentWithSAM2.py  [-h] -i INPUT_DIR -o OUTPUT_DIR [--mask_in_rgb] [--post_process] [--class_seg CLASS_SEG]
options:
  -h, --help            show this help message and exit
  -i INPUT_DIR, --input_dir INPUT_DIR
                        Input directory of images to segments
  -o OUTPUT_DIR, --output_dir OUTPUT_DIR
                        Output directory of segmentation
  --mask_in_rgb         segmentation masks store in rgb file
  --post_process        Add post processing after segmentation prediction (opening -> closing).
  --class_seg CLASS_SEG
                        Classes to segments (default: ['nuc', 'cyto'])

Example of usage: uv run SegmentWithSAM2.py -i ./PATCHS/GREY/ -o ./PATCHS/MASK/ --mask_in_rgb --class_seg nuclei,cytoplasm

🔵 With Marimo notebook

uv run marimo edit app_marimo_sam2.py

Or to use it as an app: uv run marimo run app_marimo_sam2.py


Installation

Important

Ensure you have UV installed (using the command: uv --version ) and the Git version control software. If not, install UV and/or Git.

Important

You need to have Segment Anything Model 2 (SAM2) installed. If not, proceed with the installation of SAM2. Or check github.com/facebookresearch/sam2 for the installation.

git clone https://github.com/facebookresearch/sam2.git && cd sam2
cd checkpoints && \
./download_ckpts.sh && \
cd ..
  1. Clone this repository :octocat:
git clone .....
  1. Install the UV environment
uv sync

2025 - 🐙

About

This is a small tool and Marimo notebook to segment image with SAM2.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages