Outline is a background remover with a flexible mask-processing pipeline and a built-in SVG tracing workflow.
It is written in Rust, powered by ONNX Runtime (ort) and VTracer, and works with U2-Net, BiRefNet, and other ONNX models that share a similar input/output shape.
This project is still in early development. Breaking changes may occur in future releases.
Outline supports being used as a library or via a command-line interface (CLI).
Before using, specify your ONNX model path (default: model.onnx at the project root).
use outline::{MaskProcessingOptions, Outline, TraceOptions, VtracerSvgVectorizer};
fn generate_assets() -> outline::OutlineResult<()> {
let outline = Outline::new("model.onnx")
.with_default_mask_processing(MaskProcessingOptions::default());
let session = outline.for_image("input.png")?;
let matte = session.matte();
// Declare the desired mask steps, then apply them with `processed`.
let mask = matte
.clone()
.blur_with(6.0)
.threshold_with(120)
.processed()?;
mask.save("input-mask.png")?;
let vectorizer = VtracerSvgVectorizer;
let svg = mask.trace(&vectorizer, &TraceOptions::default())?;
std::fs::write("input.svg", svg)?;
Ok(())
}VtracerSvgVectorizer is only available when the
vectorizer-vtracerfeature is enabled. You can use your own vectorizer by implementing theSvgVectorizertrait to avoid depending on VTracer directly.
Use outline <COMMAND> --help to inspect the options of each subcommand.
# Remove the background and export a foreground PNG
outline cut input.jpg -o subject.png
# Export a foreground PNG with feathered edges
outline cut input.jpg --blur -o subject-soft-alpha.png
# Export the raw matte png
outline mask input.jpg -o subject-matte.png
# Export a processed binary mask png
outline mask input.jpg --binary -o subject-mask.png
# Generate an SVG outline from the raw matte
outline trace input.jpg -o subject-raw-mask.svg
# Generate an SVG outline with sticker-style processing
outline trace input.jpg -o subject.svg \
--dilate 50.0 --fill-holes --blur 20.0Run the CLI either directly or after building the release binary:
cargo run --release -- <command> <input> [options]
# or build once and reuse
cargo build --release
./target/release/outline <command> <input> [options]Detailed CLI Reference
cut: Primary background-removal workflow. Produces a foreground PNG, optionally saves the raw matte and the processed mask, and lets you choose the alpha source.mask: Exports only the mask. It saves the raw matte by default and switches to the processed binary mask when--binaryis provided.trace: Generates an SVG outline using the same mask-processing pipeline. Exposes VTracer color modes, hierarchy selection, path precision, and other options.
-m, --model <path>: Path to the ONNX model (defaults tomodel.onnx).--intra-threads <n>: ORT intra-op thread count. Omit to let ORT decide.--input-resample-filter {nearest,triangle,catmull-rom,gaussian,lanczos3}: Resampling filter used when scaling the input down to the model resolution.--output-resample-filter {nearest,triangle,catmull-rom,gaussian,lanczos3}: Filter used to resize the matte back to the original image size.
The following switches can be used in mask, cut, and trace:
--blur [sigma]: Apply Gaussian blur before thresholding (defaults to6.0when no value is provided).--mask-threshold <0-255 | 0.0-1.0>: Threshold applied to the matte (default120) to produce a binary mask.--binary [enabled|disabled|auto]: Control thresholding in the processed pipeline (use the flag without a value to force a binary mask, or pass--binary disabledto keep soft edges; the defaultautopreserves the raw matte unless other processing steps require a hard mask).--dilate [radius]: Enable dilation after thresholding (defaults to5.0when no value is provided).--fill-holes: Fill enclosed holes before exporting/tracing.
The raw matte (soft mask) preserves the grayscale alpha predicted by the model. The processed mask (binary mask) goes through the blur/threshold/dilate/fill pipeline, producing a clean silhouette for tracing or foreground compositing.
-o, --output <path>: Foreground PNG output path (default<name>-foreground.png).--export-matte [path]: Additionally save the raw matte (default<name>-matte.png).--export-mask [path]: Save the processed mask (default<name>-mask.png); add--binaryfor hard edges.--alpha-source {raw|processed|auto}: Choose which mask becomes the PNG alpha (defaultauto).autokeeps the raw matte unless any mask-processing options are provided, in which case it uses the processed mask.
-o, --output <path>: Output path (default<name>-matte.pngor<name>-mask.pngdepending on processing flags).--mask-source {raw|processed|auto}: Choose which mask to export.auto(default) exports the raw matte unless any mask-processing options (binary/blur/dilate/fill-holes or a custom threshold) are provided, in which case it exports the processed mask.
-o, --output <path>: SVG output path (default is the input name with.svg).--mask-source {raw|processed|auto}: Choose the mask used for tracing.auto(default) exports the raw matte unless any mask-processing options are enabled, in which case it exports the processed mask.--color-mode {color,binary}: Color mode (defaultbinary).--hierarchy {stacked,cutout}: Hierarchy strategy (defaultstacked).--mode {none,polygon,spline}: Path simplification mode (defaultspline).--invert-svg: Invert foreground/background in the SVG output.
Other VTracer related options
--filter-speckle <usize>: Speckle filter size (default4).--color-precision <i32>/--layer-difference <i32>/--corner-threshold <i32>/--length-threshold <float>/--max-iterations <usize>/--splice-threshold <i32>: Fine-tune the remaining VTracer parameters (defaults:6,16,60,4.0,10,45).--path-precision <u32>: Decimal precision for path coordinates (default2).--no-path-precision: Clear the explicit path precision override and defer to VTracer's internal behaviour.
- Add detailed documentation for library API
- Expose a WASM version of library API
- Improve the CLI syntax for better usability and expressiveness
- Provide a lightweight GUI for easier use.
Distributed under the MIT License. See LICENSE for details.