Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GIMP nobg background remover

GIMP 3 plugin for background removal using nobg / FeyNobg, 'cause GIMP still doesn't have a good built-in background remover. Works on my machine. Might work on yours. Pull Requests are welcome :)

Features

  • Background removal (Masking)
  • Background removal (Recolor)
  • Simple subject removal (Recolor)

Examples

NASA test photo background removal (credit):

Original input
Original
Mask mode output
Mask
Recolor mode output
Recolor
Recolor with manual touch-up
Recolor + touch-up

Portrait background blur — naively blurred vs Remove Subject (Recolor) blurred:

Original blurred with foreground overlay
Original blurred + foreground
Foreground cutout from Recolor
Foreground (Recolor)
Subject-free background plate
Background (Remove Subject)
Subject-removed background blurred with foreground overlay
Background blurred + foreground

Table of contents

  1. About
  2. Examples
  3. Getting Started
  4. Usage
  5. License
  6. Acknowledgments

About

Runs nobg on the active layer and gives you a layer mask. Recolor mode also fixes foreground colors at soft edges (hair, glass, etc.) and adds a new layer instead. Everything runs locally on your machine.

I use this on Fedora with RPM GIMP and an NVIDIA GPU. Flatpak GIMP, Windows, macOS, and CPU-only setups are largely untested. The installer is cross-platform Python, but may not work depending on your specific system. PRs welcome if you get it working somewhere I haven't.

Built with

Getting Started

Prerequisites

  • GIMP 3.0+
  • Python 3.11 or 3.12
  • uv
  • Native GIMP install recommended (I use Fedora RPM, not Flatpak)

Fedora packages if import gi fails:

sudo dnf install gimp python3-gobject gtk3 gobject-introspection-devel python3-devel cairo-devel

Installation

  1. Clone and set up the venv:
 git clone https://github.com/CreativeMindstorms/GIMP-bg-remover
 cd GIMP-bg-remover
 uv venv .venv
 uv sync
  1. NVIDIA GPU (optional):
 uv sync --no-group cpu --extra cuda

Uses cu128 wheels from pyproject.toml. Change the index URL there if your driver needs a different CUDA build. Default uv sync installs CPU-only PyTorch (+cpu wheels, slower inference).

  1. Install the GIMP plugin (Linux, macOS, Windows):
 uv run --no-sync python scripts/install-gimp-plugin.py
  1. Restart GIMP.

First run downloads the FeyNobg model from Hugging Face (~1 GB). Prefetch if you want:

uv run --no-sync hf download feyninc/FeyNobg

Usage

Select a layer, then pick one of:

  • Layer > Remove Background (Mask) - matte as layer mask, pixels unchanged
  • Layer > Remove Background (Recolor) - foreground color recovery, new layer above
  • Layer > Remove Subject (Recolor) - subject-free background as opaque RGB layer (Useful for portrait background blurring)

GIMP Layer menu showing Remove Background options

Mode What it does
Mask nobg matte goes on as a layer mask. RGB stays put.
Recolor New layer with recovered colors and a refined matte in the pixels, plus a coarse nobg matte as the layer mask (see below).
Subject (Recolor) Opaque RGB layer with the subject removed and background colors recovered at soft edges. Coarse nobg matte as layer mask over the subject (see below).

Recolor: why two mattes?

Recolor builds two masks from the same photo:

  • Refined matte (in the layer pixels) - pymatting cleanup. Usually nicer on hair and soft edges.
  • Coarse matte (layer mask) - straight from nobg. Usually nicer on hard edges (tables, shoulders, crisp outlines).

The layer mask removes noise around strong edges, but may also remove detail around soft edges. Sometimes it may look better to (partly) remove the layer mask and use the pure output layer.

Paint on the layer mask to mix them: whiten where you want the refined detail to show through (hair, wispy edges). Leave it dark where you want the coarse mask to keep a clean hard edge.

Parameters

Recolor dialog: Processing size (low = fast, high = sharp). Run on CPU if you hit VRAM errors. Soft edge zone (low = better for hard edges, high = better for hair). Enable Also create background layer to add a subject-free background plate below the cutout in the same run.

Mask mode skips layers that already have a mask. Large images infer at up to 2560 px on the long edge; the mask is written at full resolution.

GIMP spawns a new plugin process every run, so the model reloads and unloads each time.

Test inference without GIMP:

uv run --no-sync python -m nobg_gimp.inference examples/base.jpg /tmp/mask.png

Force CPU:

uv run --no-sync python -m nobg_gimp.inference examples/base.jpg /tmp/mask.png --device cpu

License

GPL-3.0-or-later. Full text in LICENSE.

GIMP plugins that call GIMP's API should be GPL-compatible. Dependencies have their own licenses; see THIRD_PARTY_NOTICES.md.

Acknowledgments

About

Easy AI Background-removal plugin for GNU Image Manipulation Program (GIMP)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages