Strip a white background from sketches and line art
Turns the white (or near-white) paper around a drawing into transparency, in one fast pass. Adjust THRESHOLD to catch yellowed paper too, and FEATHER to soften the cut so faint pencil strokes fade smoothly into the new transparency. Works without any AI model — perfect for clean ink and lineart, where AI cut-out tools sometimes lose the thin lines.
INPUT
OUTPUT
JavaScript
// Sketch / lineart background removal — pure-Rust, no model
// sketch_cut.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: THRESHOLD:number=0.95,min=0.0,max=1.0
//!PARAM: FEATHER:number=0.05,min=0.0,max=1.0
// Built-in luminance-based alpha cut. Designed for black-on-white
// sketches and lineart, where the rmbg Tool Plugin (U²-Net) struggles
// because there is no salient "foreground blob" — just sparse ink on
// paper.
//
// THRESHOLD: pixels brighter than this in luminance ([0..1]) become
// transparent. 0.95 ≈ 242/255 catches clean paper. Lower it (0.85,
// 0.80) for off-white / yellowed paper.
//
// FEATHER: width of the soft edge ramp around the threshold, in
// luminance units. 0 = pixel-perfect binary cut. 0.05 ≈ 13/255 gives
// a smooth transition for grey pencil strokes that fade into paper.
//
// RGB is preserved — only alpha changes. Works in-place.
const img = Engine.loadImage(INPUT);
img.removeWhiteBackground({ threshold: THRESHOLD, feather: FEATHER }).autocrop();
img.save(OUTPUT);
img.free();
// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0