KI-gestützte Hintergrundentfernung — Motiv freistellen
Schneidet bei beliebigen Fotos den Hintergrund weg und lässt nur das Motiv stehen — Porträts, Produkte, Tiere. Läuft mit einem KI-Modell direkt auf dem Gerät, keine Cloud-Anfragen, kein Upload, keine Kosten pro Bild. THRESHOLD justiert in Grenzfällen die Vordergrund-Erkennung (z.B. feine Haare vor ähnlich gefärbtem Hintergrund).
INPUT
OUTPUT
JavaScript
// Tool plugin demo — alpha-cut background removal via U²-Net
// tool_rmbg.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: THRESHOLD:number=0.0,min=0.0,max=1.0
// Demonstrates a Rust-based Tool Plugin with bundled neural-net
// weights. The 'rmbg' tool ships a small U²-Net ONNX model
// (~4.4 MB, Apache-2.0) and runs entirely in pure Rust via tract
//
// THRESHOLD pushes pixels below it in the raw mask to fully
// transparent. Leave at 0 for soft edges; raise to 0.4–0.5 for a
// cleaner cut-out at the cost of some hair / detail.
//
// First run takes a few seconds — the model is loaded from disk per
// invocation. Subsequent runs are equally slow (the engine spawns
// the binary fresh each time), but inference itself is ~5–10 s on
// a typical CPU for a 1000×1000 input.
const img = Engine.loadImage(INPUT);
const cut = Engine.tool('rmbg').apply(img, {
threshold: THRESHOLD,
});
cut.autocrop({ tolerance: 0.05, padding: 1 });
cut.save(OUTPUT);
img.free();
cut.free();
// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0