SAMwise is a professional desktop application designed for precise segmentation of biological images, with a particular focus on organoid and cell datasets. The software provides a streamlined environment that combines manual drawing tools, threshold-based segmentation, and integration with the Segment Anything Model (SAM) for semi-automated annotation.
The application is built to support the complete workflow of image annotation in research settings. It allows users to organise images by experiments and dates, manage labelled and unlabelled datasets, and track progress throughout the annotation process. Segmentation can be performed using manual brush tools, automatic thresholding, or AI-assisted methods such as marker-guided SAM and fully automated SAM predictions.
By uniting these complementary approaches in a single interface, SAMwise reduces the time and variability associated with biological image annotation, while maintaining full user control and transparency. It is intended to provide both flexibility for expert annotators and efficiency for large-scale studies.
- Multi-experiment support: Organize images by experiment and date folders
- Smart folder navigation: Switch between labeled and unlabeled image pools
- Batch operations: Crop multiple images by their masks simultaneously
- Progress tracking: Visual indicators for annotation completion status
- Manual drawing: Brush tool with adjustable size and opacity
- Threshold segmentation: Automatic mask generation based on intensity thresholds
- SAM integration: Semi-automated segmentation using Meta's Segment Anything Model
- Auto SAM: Intelligent automatic mask generation for the largest object in images
- Marker-based SAM: Precise segmentation with user-placed markers
- Intuitive workflow: Streamlined interface designed for efficient annotation
- Real-time preview: Immediate visual feedback for all operations
- Modular design: Clean separation of tools and controls
- Professional logging: Comprehensive error tracking and debugging
- Python 3.8 or higher
- CUDA-compatible GPU (recommended for SAM functionality)
Install the required packages using pip:
pip install -r requirements.txtThe application uses Meta's Segment Anything Model (SAM). To enable SAM functionality:
- Download a SAM checkpoint file from the official repository
- Place the checkpoint file in the
Models/folder within the root directory - Ensure the filename matches the expected checkpoint name in the configuration (default is "sam_vit_h_4b8939.pth")
Note: SAM is licensed under Apache 2.0, which permits both research and commercial use with proper attribution.
python src/main.py- Select Experiment: Choose from available experiments in the dropdown
- Choose Folders: Select which date folders to process from the experiment
- Load Images: Click "Get Random Image" to start annotation
- Create Masks: Use the available tools to segment organoids:
- Brush: Manual drawing with adjustable parameters
- Marker + SAM: Place markers for SAM-based segmentation
- Auto SAM: Automatic segmentation of the largest object
- Threshold: Intensity-based automatic segmentation
- Save Work: Save masks and move to the next image
The application expects the following directory structure:
project_root/
├── Data/
│ └── Experiment X/
│ └── YYYYMMDD/
│ ├── 1.png
│ ├── 2.png
│ └── ...
├── Labels/ (Automatically created)
│ └── Experiment X/
│ └── YYYYMMDD/
│ ├── 1.png (masks)
│ ├── 2.png
│ └── ...
├── Cropped/ (Automatically created)
│ └── Experiment X/
│ └── YYYYMMDD/
│ ├── 1.png (cropped images)
│ ├── 2.png
│ └── ...
├── Models/
│ └── sam_vit_h_4b8939.pth (SAM checkpoint)
└── logs/
└── organoid_segmentation_YYYYMMDD.log
- Main Window: Central UI coordination and workflow management
- Drawing Canvas: Image display, drawing tools, and user interactions
- Service Layer: Business logic separation for images, experiments, and models
- Event System: Decoupled communication between components
- ExperimentService: Manages experiment detection and folder organization
- ImageManager: Handles image pools, navigation, and mask operations
- ModelService: SAM model loading, initialization, and prediction
- AutoSamService: Automatic mask generation using image analysis
- ExperimentManager: Experiment selection and configuration
- FolderManager: Folder selection and view mode switching
- DrawingTools: Tool selection and parameter controls
- ImageControls: Navigation, saving, and batch operations
- ImageInfo: Display current image information
- PNG, JPG, JPEG, BMP, TIFF, TIF
- Automatic format detection and conversion
- Lazy SAM loading: Models are loaded on-demand to improve startup time
- Smart pool management: Image lists are refreshed intelligently to maintain accuracy
- Efficient rendering: Optimized canvas operations for smooth interaction
- Memory management: On-demand model cleanup with GPU memory optimization
- Professional logging system: Rotating log files with configurable levels
- User-friendly error messages: Clear feedback for common issues
- Robust file I/O: Comprehensive error checking and recovery
- Debug capabilities: Detailed logging for troubleshooting
SAMwise/
├── .gitignore # Git ignore patterns
├── README.md # Project documentation
├── requirements.txt # Python dependencies
├── Models/ # SAM model checkpoints
├── logs/ # Application logs
├── Data/ # Raw experiment images
├── Labels/ # Segmentation masks
├── Cropped/ # Processed images
└── src/ # Source code
├── main.py # Application entry point
├── core/ # Core architecture
│ ├── __init__.py
│ ├── base.py # Base classes and enums
│ └── events.py # Event system implementation
├── models/ # Data models
│ ├── __init__.py
│ └── experiment.py # Experiment data structures
├── services/ # Business logic layer
│ ├── __init__.py
│ ├── experiment_service.py # Experiment management
│ ├── image_manager.py # Image operations
│ ├── model_service.py # SAM model integration
│ └── auto_sam_service.py # Automatic segmentation
├── ui/ # User interface
│ ├── __init__.py
│ ├── main_window.py # Main application window
│ ├── drawing_canvas.py # Canvas for image display/drawing
│ ├── placeholder_image.py # Placeholder image generation
│ └── components/ # Reusable UI components
│ ├── __init__.py
│ ├── drawing_tools.py # Drawing tool controls
│ ├── experiment_manager.py # Experiment selection
│ ├── folder_manager.py # Folder selection
│ ├── image_controls.py # Image navigation/controls
│ └── image_info.py # Image information display
└── utils/ # Utility functions
├── __init__.py
├── image_processing.py # Image manipulation helpers
└── logging_config.py # Logging configuration
- Model-View-Controller (MVC): Clear separation between data, UI, and logic
- Observer Pattern: Event-driven communication between components
- Service Layer Pattern: Business logic encapsulation
- Singleton Pattern: Centralized event bus and configuration
- Business Logic: Implement in appropriate service classes
- UI Components: Create following established component patterns
- Communication: Use the event system for decoupled messaging
- Error Handling: Add comprehensive logging and user feedback
- Testing: Include unit tests for critical functionality
- Professional logging: Structured logging with rotating files
- Error handling: Comprehensive exception management
- Documentation: Clear docstrings and inline comments
- Modularity: Clean separation of concerns
- Type hints: Enhanced code clarity and IDE support
This project is open source and available under the MIT License.
- Segment Anything Model (SAM): Licensed under Apache 2.0 by Meta Platforms, Inc.
- PySide6: Licensed under LGPL
- OpenCV: Licensed under Apache 2.0
- NumPy: Licensed under BSD
- scikit-image: Licensed under BSD
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
- Clone the repository
- Install dependencies:
pip install -r requirements.txt - Download SAM model checkpoint
- Run the application:
python src/main.py
If you use SAMwise in your research, please cite:
@software{SAMwise2025,
title={SAMwise},
author={Sammy Shorthouse and Aya Elghajiji and Qiang Liu and James Armstrong},
year={2025},
url={https://github.com/SammySho/SAMwise}
}- Meta AI for the Segment Anything Model
- The Qt Company for PySide6
- The scientific Python community for the excellent libraries that make this application possible
- ChatGPT (OpenAI) for creating the application logo
