module

MJ::Matte

Background matting for arbitrary images.

TIER 1 (procedural, this file): read the background colour from the image BORDERS, then flood-fill inward to remove only the connected background — so a subject that happens to share the bg colour is kept (unlike a global colour key). The flood grows along smooth colour steps (gradients, vignettes) but is capped near the seed colour so it can't run into the subject. Then the edge is softened, despilled (bg tint removed from the rim) and alpha-bled (so it survives downscaling).

Best on simple / near-uniform backgrounds. Complex photos are Tier 2 (local rembg) / Tier 3 (Runware) — this module is the free, instant first pass.

Constants

ISNET_SIZE = 1024

Class methods

isnet(src : StumpyPNG::Canvas, model_path : String, bleed : Bool = true) : StumpyPNG::Canvas

Tier 2: local neural matting via IS-Net through the ONNX Runtime shim. Resize to the model's 1024² input, normalise IS-Net style (x/255 − 0.5), run, min-max the score map, then bilinearly upsample it back to the original size as the alpha channel and alpha-bleed. Handles arbitrary / complex backgrounds a colour key can't. Requires onnxruntime-cpu + the .onnx model file.

Source
remove_bg(src : StumpyPNG::Canvas, local_tol : Float64 = 20.0, global_tol : Float64 = 70.0, feather : Int32 = 2, despill : Bool = true, bleed : Bool = true) : Result

local_tol: how large a per-step colour change still counts as background (follows gradients). global_tol: hard cap on distance from the seed colour (stops the flood entering the subject).

Source

Nested types