This Inkscape extension allows you to generate SVG paths from an image using the Segment Anything Model (SAM/SAM2).
- Segment Anything Integration: Directly use SAM models within Inkscape.
- SAM1 and SAM2 Support: Works with both SAMv1 and SAMv2 models.
- Flexible Model Formats: Supports both
.pthand.safetensorsmodel checkpoint files. - Two Segmentation Modes:
- Everything (auto): Automatically finds and segments all objects in the entire image.
- From Selection Box: Segments only the area defined by the bounding box of selected shapes.
- Path Customization:
- Path Simplification: Control the level of detail and smoothness of the generated paths.
- Minimum Path Size: Filter out and ignore small, noisy paths.
- Path Appearance: Choose between fill, stroke, or both for the final paths.
This extension requires a Python environment with specific libraries installed. It is highly recommended to use a virtual environment to avoid conflicts with other Python projects.
# Create a virtual environment
python3 -m venv sam_env
# Activate the environment
source sam_env/bin/activate
# Install required packages
pip install torch torchvision torchaudio
pip install opencv-python
pip install 'git+https://github.com/facebookresearch/segment-anything.git'
# For SAM2 support, also install:
pip install 'git+https://github.com/facebookresearch/segment-anything-2.git'- Go to the Releases page of this repository.
- Download the
inksegany.zipfile from the latest release.
- Open Inkscape.
- Go to
Edit > Preferences > System. - Find the
User extensionspath and open it in your file browser. - Extract the
inksegany.zipfile into this directory. - After extracting, your extensions directory should contain
inksegany.inx,inksegany.py, andsegany.py. - Restart Inkscape.
-
Open the Extension: Go to
Extensions > Render > Segment Anything. -
Configure Settings:
- Python Executable Path: Set the full path to the Python interpreter from the virtual environment you created (e.g.,
/path/to/your/sam_env/bin/python). - Checkpoint Path: Set the path to your downloaded SAM model checkpoint file (
.pthor.safetensors). - Adjust other settings like Segmentation Mode, Path Simplification, and Path Appearance as needed. The Help tab in the extension provides detailed explanations for each option.
- Python Executable Path: Set the full path to the Python interpreter from the virtual environment you created (e.g.,
-
Run Segmentation:
- For 'Everything' mode: Select an image in your Inkscape document and click Apply.
- For 'From Selection Box' mode: Select an image AND one or more other shapes (like a rectangle or a path) that cover the area you want to segment. Then, click Apply.
The extension will process the image and add a new layer named SAM Paths containing the generated SVG paths.
This project is licensed under the GPL-3.0 License.