Make Image Segmentation Simple and Efficient!
Interactive and automated image segmentation toolkit based on MobileSAM
Batch Processing | Interactive Operation | Ready to Use
Features • Quick Start • Usage • Showcase
This project provides three different image segmentation tools:
- 📦 Batch Processing: Process images one by one from a folder
- 🖱️ Manual Box Drawing: Draw one or multiple boxes for each image
- 🎯 Precise Control: Full control over segmentation areas
- 💾 Auto Save: Automatically save generated masks
Use Case: When you need to precisely specify segmentation areas for each image
- ⚡ Fully Automatic: No manual intervention required
- 🎛️ Multiple Modes:
- Center point mode
- Grid point mode (3×3)
- Full image box mode
- Center region box mode
- Custom relative coordinate box mode
- 🚀 High Efficiency: Suitable for large-scale batch processing
Use Case: Batch processing of images with similar composition
- 🎨 Point Mode: Segment by clicking foreground/background points
- 📐 Box Mode: Segment by drawing rectangular boxes
- 🔄 Mode Switching: Support mixed use of points and boxes
- 👀 Real-time Preview: Instant view of segmentation results
Use Case: Testing effects, single image fine segmentation
- Python 3.8+
- CUDA (Optional, for GPU acceleration)
git clone https://github.com/yo-WASSUP/Good-Segment.git
cd Good-Segmentpip install opencv-python
pip install numpy
pip install ultralyticsOr use requirements.txt:
pip install -r requirements.txt✅ Model Included: This project includes the mobile_sam.pt model file. You can use it directly after cloning, no additional download required.
💡 Model Information:
- Filename:
mobile_sam.pt- Location: Project root directory
- Source: MobileSAM - Lightweight Segment Anything Model
Manually select boxes for each image, suitable for scenarios requiring precise control.
# Basic usage
python batch_mask_interactive.py images/test
# Specify output directory
python batch_mask_interactive.py images/test -o output/masks
# Specify model path
python batch_mask_interactive.py images/test -m path/to/mobile_sam.ptControls:
- 🖱️ Drag Mouse: Draw rectangular box (multiple boxes supported)
- ⌨️ Space Key: Generate mask and move to next image
- ⌨️ S Key: Skip current image
- ⌨️ R Key: Reset boxes for current image
- ⌨️ Q Key: Quit program
Color Indicators:
- 🟣 Purple Box: Box being drawn
- 🟢 Green Box: Completed box
Fully automatic processing, suitable for batch processing similar images.
# Run the program
python batch_mask.pySelect mode according to prompts:
- Auto Mode - Center Point: Use image center point as prompt
- Auto Mode - Grid Points: Use 3×3 grid points
- Box Mode - Full Image: Use entire image as box
- Box Mode - Center 80%: Use center 80% region
- Box Mode - Custom: Enter relative coordinates (0-1)
Suitable for testing effects and fine segmentation of single images.
python interactive_mask.pyControls:
- Point Mode:
- Left Click: Add foreground point (green)
- Right Click: Add background point (red)
- Box Mode:
- Drag: Draw rectangular box (purple)
- General Operations:
- Space Key: Generate mask
- M Key: Switch between point/box mode
- R Key: Reset all points and boxes
- Q Key: Quit program
💡 Tip: You can use points and boxes together for more precise segmentation!
Good-Segment/
├── batch_mask_interactive.py # Interactive batch segmentation tool
├── batch_mask.py # Auto batch segmentation tool
├── interactive_mask.py # Single image interactive segmentation tool
├── mobile_sam.pt # MobileSAM model file (included)
├── requirements.txt # Python dependencies
├── docs/ # Documentation and examples
│ └── examples/ # Showcase images
├── images/ # Input image directory (example)
│ └── test/ # Test images
├── output/ # Output directory (auto-created)
│ └── masks/ # Generated masks
├── .gitignore # Git ignore file
└── README.md # Project documentation
All tools generate masks in the following format:
- Format: PNG image
- Type: Single-channel binary image
- Values:
- White (255): Foreground/Object
- Black (0): Background
| Tool | Use Case | Advantages | Disadvantages |
|---|---|---|---|
| Interactive Batch | Medium quantity of images requiring precise segmentation | Precise control, multi-box support | Requires manual operation |
| Auto Batch | Large quantity of similar composition images | Fast, fully automatic | May need parameter adjustment |
| Single Image Interactive | Testing effects, single image fine segmentation | High flexibility, point+box support | Only processes one image |
- Model File: Project includes
mobile_sam.ptmodel file, ready to use after cloning - Image Format: Supports jpg, jpeg, png, bmp, tiff, webp formats
- Memory Usage: Pay attention to memory usage when processing large images or batches
- Output Overwrite: Files with the same name will be overwritten
Q: Unable to load model?
A: Ensure mobile_sam.pt is in the correct path. You can use the -m parameter to specify the path.
Q: Generated mask is inaccurate?
A: Try:
- Interactive Batch: Draw multiple boxes or adjust box positions
- Auto Batch: Switch to different processing modes
- Single Image Interactive: Use point+box mixed mode
Q: Processing speed is slow?
A:
- Use GPU: Install CUDA version of PyTorch
- Reduce image size
- Use simple configuration in auto batch mode
This project is based on MobileSAM and Ultralytics. Please comply with the corresponding open source licenses.
If this project helps you, welcome to give it a Star ⭐️!
For questions or suggestions, feel free to submit an Issue or Pull Request.
Good-Segment - Make Image Segmentation Simpler ✨
Made with ❤️ by [Spike Don]


