RepositoryPythonTRTürkiye
egeorcun

egeorcun/lucida

Background removal that keeps what matters: glass, camouflage, text, glow and line art. BiRefNet fine-tune, MIT.

178stars
22forks
2issues
4views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: image-matting

#1 Repository of the week

1
TINIX TRENDING·Topic: camouflage

#1 Repository of the week

2
TINIX TRENDING·Topic: birefnet

#2 Repository of the week

Lucida

HF Model Live Demo License: MIT GitHub Stars

Background removal that keeps what matters: glass, camouflage, text, glow, line art and print designs.

Lucida is a BiRefNet-based image matting model fine-tuned specifically for the cases where general-purpose background removers fall apart: semi-transparent objects, camouflaged subjects, logos and typography with soft shadows, glow/VFX effects, illustrations, and print-style designs (stickers, tees). Weights are on Hugging Face: egeorcun/lucida (MIT). Try it in your browser (ZeroGPU, a few seconds per image): live demo.

Benchmark

203 images, 9 categories, MAE against ground-truth alpha (lower is better). Row leaders in bold. Full methodology in docs/benchmark.md; raw table snapshot in docs/benchmark-results.md.

category (n)lucida-v7inspyrenetideogram*rmbg-2.0birefnet-hr
camouflage (25)0.02700.05820.11790.14050.0752
transparent (25)0.03580.07250.03430.07410.0687
complex (29)0.04840.01100.10460.02410.0385
thin (36)0.03220.01660.05210.01800.0196
hair (40)0.00930.00690.01120.00450.0048
text (12)0.00910.01810.01230.01730.0207
fx (12)**0.01800.02690.01650.02680.0272
illustration (12)0.00920.02420.02150.01250.0157
design (12)***0.02350.05870.05180.04780.0544
OVERALL (203)0.02570.02950.05070.04010.0346

* ideogram = fal.ai Ideogram remove-background, a commercial API used as the quality reference.

** The fx test images and their ground truth come from the earlier (v4-era) synthetic generator; the fx recipe was reworked for v5 training, so this row is a conservative estimate for lucida-v5+.

*** Synthetic print-design/sticker images (scripts/make_design.py), generated with seed 777 — a holdout fully disjoint from the seed-42 training data.

What Lucida wins, honestly:

  • Overall: the lowest average error of every model measured — 0.0257 vs InSPyReNet 0.0295 — the first Lucida release to lead the whole table, specialists and commercial reference included.
  • Print design: 0.0235, more than 2x better than every competitor (best open RMBG-2.0 0.0478, commercial Ideogram 0.0518). This category exists because a Reddit user reported the failure (issue #2) — community feedback, fixed in v7.
  • Camouflage: more than 2x better than the best open competitor (0.0270 vs InSPyReNet 0.0582) and 4.4x better than the commercial reference.
  • Text/logos: clearly ahead of the commercial reference (0.0091 vs 0.0123) and of all open models.
  • Illustration: ahead of every model measured, including the commercial reference (0.0092 vs RMBG-2.0 0.0125, Ideogram 0.0215).
  • Transparency: best of the open models by a wide margin (0.0358 vs the next-best open 0.0687).

And what it loses, just as honestly:

  • Ideogram still leads transparency (0.0343 vs our 0.0358). The gap is down to 0.0015; not zero.
  • InSPyReNet is the specialist for complex scenes and thin structures (0.0110 / 0.0166 vs our 0.0484 / 0.0322). Complex improved 28% over v6, but the gap stands.
  • RMBG-2.0 leads hair (0.0045 vs our 0.0093), though absolute errors there are small for everyone.
  • Ideogram edges out fx (0.0165 vs our 0.0180).

If your workload is mostly multi-object product shots or wiry/perforated structures, InSPyReNet or RMBG-2.0 may serve you better. For everything else — transparency, camouflage, typography, glow effects, illustrations, print designs — and on the overall average, Lucida is the strongest option we measured.

Examples

Original | Lucida v7 (RGBA on a dark checkerboard) | competitor. MAE per image shown in the labels.

Camouflage — body paint blended into magnolia petals; Lucida finds the subject, the runner-up keeps the whole image:

Camouflage comparison: Lucida vs InSPyReNet

Transparency — glass demijohns; the interior stays semi-transparent instead of turning into an opaque blob:

Transparency comparison: Lucida vs Ideogram

Text / logo — lettering with a soft drop shadow over a noisy background; the shadow survives as partial alpha:

Text comparison: Lucida vs Ideogram

Illustration — anime rider having a meal; clean line-art edges where general-purpose models blur or halo:

Illustration comparison: Lucida vs RMBG-2.0

Print design — smoke edges and distressed display text; the category born from a community bug report:

Print design comparison: Lucida vs competitor

Model

Weights: huggingface.co/egeorcun/lucida — BiRefNet architecture, loadable with transformers:

import torch
from PIL import Image
from torchvision import transforms
from transformers import AutoModelForImageSegmentation

model = AutoModelForImageSegmentation.from_pretrained("egeorcun/lucida", trust_remote_code=True)
model.eval()

# 1024x1024 input is the recommended (and trained) resolution.
preprocess = transforms.Compose([
    transforms.Resize((1024, 1024)),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])

image = Image.open("input.jpg").convert("RGB")
with torch.no_grad():
    alpha = model(preprocess(image).unsqueeze(0))[-1].sigmoid().cpu()[0, 0]

alpha_img = transforms.ToPILImage()(alpha).resize(image.size)
rgba = image.copy()
rgba.putalpha(alpha_img)
rgba.save("output.png")

Install & usage

Requires Python >= 3.12. With uv:

git clone https://github.com/egeorcun/lucida
cd lucida
uv sync

(Plain pip works too: pip install -e .)

CLI

uv run bgr remove input.jpg -o output.png --model lucida-v7
  • --model picks any entry from bgr/registry.py (lucida-v7, rmbg-2.0 (default), birefnet-hr, inspyrenet, ...). The lucida-v7 entry loads a local checkpoint from data/checkpoints/epoch_7.pth — download it from the Hugging Face repo and place it there.
  • --refine enables the edge-refinement pass; --no-decontaminate disables color decontamination of the RGBA output.

HTTP service (FastAPI)

uv run uvicorn serving.app:app --port 8756
curl -F "file=@input.jpg" "http://localhost:8756/remove?model=lucida-v7" -o output.png

Query parameters: model (default rmbg-2.0), refine (bool), decontaminate (bool, default true). GET /health lists the available models.

ComfyUI

Lucida is distributed in ComfyUI's official model collection, Comfy-Org/BiRefNet. Download lucida.safetensors from there and place it in ComfyUI/models/background_removal/.

Docker

See docs/docker.md.

How it was trained

Lucida is a fine-tune of BiRefNet_HR (MIT), starting from 52,882 image/alpha pairs across 9 categories (transparent, camouflage, complex, thin, hair, text, fx, illustration, general — a tenth, design, was added for v7), trained on a single A100 40GB at 1024x1024, batch 2 x gradient-accumulation 4 (effective batch 8), bf16, using the official BiRefNet Matting task losses (BCE + MAE + SSIM). Seven epochs — but not seven passes of the same recipe; each epoch was benchmarked on the held-out test set (191 images through v6, 203 once the design category landed) and the data or the category sampling was re-calibrated before the next one:

  • v1 — transparency + camouflage focus. A WeightedRandomSampler pinned those two categories at 20% each of every epoch. Camouflage improved immediately, but everything else starved: complex/thin/hair collapsed.
  • v2-v3 — rebalance + real backgrounds. Explicit shares for all categories, plus original-background (non-composited) training samples. Complex recovered from 0.156 to 0.075 MAE, hair to 0.0067, transparency kept improving.
  • v4 — three new capabilities. Synthetic text/logo renders and procedural glow/VFX data (scripts/make_textfx.py) plus ToonOut illustrations, together 26% of the epoch. Text (0.0119) and illustration (0.0129) immediately reached commercial-reference level — but transparency and hair paid for the reallocated share, and the aggressive fx glow data introduced "ghosting" (partial alpha on solid objects).
  • v5 — ghosting fix + consolidation. The fx generator was reworked (narrow halo band, short streaks, particles concentrated near the object), its share cut, and transparency/hair shares restored. Epoch-5 sampler shares: transparent .22, complex .19, camouflage .12, thin .12, hair .12, text .07, illustration .07, fx .05, general .04.
  • v6 — community bug fixes (issue #1). Two reported failure modes, fixed with derivative training copies (scripts/make_v6_copies.py): edge-crops that cut 20-60% of the subject bounding box (~9k copies, so subjects touching the frame stop getting erased) and mixed-opacity augments of transparent pairs (up to 4k copies, so solid parts of transparent objects stop going semi-transparent).
  • v7 — the design category (issue #2). A Reddit user reported print-design/sticker images — halftone subjects, distressed display text, smoke and glow melting into white — being erased or ghosted. A new synthetic generator (scripts/make_design.py, ~6k pairs) and an 8% sampler share fixed it: design MAE went from 0.0479 (v6) to 0.0235, ahead of every competitor. Complex (0.0670 -> 0.0484) and fx (0.0313 -> 0.0180) also improved over v6. Final epoch-7 sampler shares: transparent .22, complex .19, thin .12, camouflage .10, hair .10, design .08, text .06, illustration .06, fx .05, general .02.

The full decision log lives in training/train_colab_lib.py (sampler preset docstrings) and docs/reports/.

Datasets & licensing

Training data mixes sources with different licenses. The model weights are released under MIT, following the established practice of the field (BiRefNet itself was trained on largely research-only academic sets and releases MIT weights) — but a data license is not a weight license, and whether training-data restrictions propagate to weights is legally unsettled. The table below is the honest inventory; commercial users should make their own assessment, particularly regarding the research-only sources.

SourceCategoryLicenseCommercial use
DIS5Kthin / complexDIS5K Terms of UseResearch-only
CAMOcamouflageCC-BY-NC-SA 4.0Research-only
COD10Kcamouflageacademic releaseResearch-only
P3M-10khairP3M-10k Release AgreementResearch-only (faces blurred for privacy)
Transparent-460transparentnot statedTreated as research-only
HIM2Kgeneralnot statedTreated as research-only
AM-2kgeneralMIT (via release agreement)Yes
BG-20kbackgroundsMIT (via release agreement)Yes
ToonOutillustrationCC-BY 4.0Yes, with attribution
Synthetic text/fx (this repo)text / fxMIT (scripts/make_textfx.py)Yes
Synthetic design (this repo)designMIT generator (scripts/make_design.py); foregrounds drawn from the sources aboveinherits foreground-source licensing

Limitations

  • Transparency: the commercial reference (Ideogram) still leads, 0.0343 vs 0.0358 MAE.
  • Complex scenes and thin structures: InSPyReNet's specialist advantage stands (0.0110/0.0166 vs our 0.0484/0.0322); RMBG-2.0 leads hair.
  • Semantic coherence: subject selection on scenes with partially visible people or ambiguous multi-object layouts is not perfect — occasional dropped or extra parts.
  • fx measurement: the fx benchmark row is conservative for v5+ (test GT from the older generator, see the table footnote).

License & citation

Code and weights: MIT.

Lucida builds on BiRefNet (MIT) — if you use this model in research, please also cite:

@article{zheng2024birefnet,
  title   = {Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author  = {Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
  journal = {CAAI Artificial Intelligence Research},
  volume  = {3},
  pages   = {9150038},
  year    = {2024}
}

Illustration training and test data come from the ToonOut dataset by Joël Seytre (joelseytre/toonout, CC-BY 4.0).

Similar Projects

Discover other similar projects and AI models.

Modelimage-segmentation
egeorcun/lucida

Lucida — general-purpose background removal with soft-alpha mastery Lucida is a BiRefNet-based background-removal / image-matting model fine-tuned to excel where most open models fail: camouflaged objects, transparent materials (glass), text & logos...

♥0
13.6k
Aug 5, 2026
Modelimage-segmentation
ZhengPeng7/BiRefNet

Bilateral Reference for High-Resolution Dichotomous Image Segmentation Peng Zheng 1,4,5,6,  Dehong Gao 2,  Deng-Ping Fan 1,  Li Liu 3,  Jorma Laaksonen 4,  Wanli Ouyang 5,  Nicu Sebe 6 1 Nankai University&ens...

♥0
952.2k
Feb 4, 2026
Modelimage-segmentation
briaai/RMBG-3.0

BRIA Background Removal v3.0 Model Card 🏆 1 in background removal in our head-to-head benchmark against Photoroom, remove.bg (Canva), Ideogram, BiRefNet and RMBG-2.0, on 234 hard images at full resolution. Background removal, reimagined as image ed...

♥0
736
Nov 17, 2026
RepositoryPython
ultralytics/yolov5

Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.

58.3k
Nov 23, 2026
RepositoryPython
ZhengPeng7/BiRefNet

[CAAI AIR'24] Bilateral Reference for High-Resolution Dichotomous Image Segmentation

4.5k
Oct 25, 2026
RepositoryPython
d2l-ai/d2l-zh

《动手学深度学习》:面向中文读者、能运行、可讨论。中英文版被70多个国家的500多所大学用于教学。

82.9k
Jul 30, 2024
RepositoryPython
rohitg00/ai-engineering-from-scratch

Learn AI Engineering! Learn it. Build it. Ship it for others.

81.4k
Nov 30, 2026
Modelimage-segmentation
briaai/RMBG-1.4

BRIA Background Removal v1.4 Model Card RMBG v1.4 is our state-of-the-art background removal model, designed to effectively separate foreground from background in a range of categories and image types. This model has been trained on a carefully sele...

♥0
208.7k
Nov 16, 2026
Modelimage-segmentation
briaai/RMBG-2.0

BRIA Background Removal v2.0 Model Card ✨ Discover FIBO on Hugging Face 💜 Bria AI&nbsp&nbsp | &nbsp&nbsp🤗 Hugging Face &nbsp&nbsp | &nbsp&nbsp 📑 Blog &nbsp&nbsp 🖥️ Demo&nbsp&nbsp| &nbsp&nbsp Github&nbsp&nbsp RMBG v2.0 is our new state-of-the-art...

♥0
376.7k
Nov 16, 2026