Skip to content

Shriinivas/inksegany

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inkscape Segment Anything

This Inkscape extension allows you to generate SVG paths from an image using the Segment Anything Model (SAM/SAM2).

Features

  • 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 .pth and .safetensors model 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.

Installation

1. Install Python Dependencies

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'

2. Download the Extension

  1. Go to the Releases page of this repository.
  2. Download the inksegany.zip file from the latest release.

3. Install the Extension in Inkscape

  1. Open Inkscape.
  2. Go to Edit > Preferences > System.
  3. Find the User extensions path and open it in your file browser.
  4. Extract the inksegany.zip file into this directory.
  5. After extracting, your extensions directory should contain inksegany.inx, inksegany.py, and segany.py.
  6. Restart Inkscape.

Usage

  1. Open the Extension: Go to Extensions > Render > Segment Anything.

  2. 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 (.pth or .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.
  3. 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.

License

This project is licensed under the GPL-3.0 License.

About

Inkscape extension for integration with Meta Segment Anything

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors