From a YOLO box to a soft alpha
The smallest detector in our vision category is 2.5 MiB; the largest matting model is 93.9 MiB. The extra weight shows up along the edge, in two or three pixels. All three demos use the same sample images.
When we built the background-removal demo, the first version fed the whole photo to RMBG. It was slow and left a rim of background colour along the edge. Cropping the person first fixed both. The three subcategories under vision follow roughly that order: locate, label every pixel, then compute an alpha with soft edges.
Detection, and what 2.5 MiB gets you
YOLOv10n is 2.5 MiB and runs in real time in a tab, so it is the one we reach for first. RT-DETR R18 is about 20.0 MiB and swaps NMS for a Transformer decoder, which holds up better in crowded frames. For phones, MediaPipe Object Detection is around 6.9 MiB and tuned for them.
The two sliders matter more than the model choice. Drop the confidence threshold and pedestrians stop disappearing in a crowd; drop the NMS IoU and one person stops wearing three boxes. Both are live in the demo.
Segmentation labels every pixel
Segmentation decides, for each pixel inside the box, foreground or background. MediaPipe Selfie at 0.2 MiB is enough for a real-time background swap. U²-Netp (4.4 MiB) and MODNet (6.3 MiB) give cleaner edges. SAM Tiny, about 13.1 MiB, works differently: give it a point or a box as a prompt and it segments the object you pointed at, with no fixed class list.
What comes out is usually a binary mask or a low-resolution probability map. Upscale it directly and the edge turns into a staircase.
Matting needs values between 0 and 1
Hair, sheer fabric and motion blur cannot be answered with foreground or not. Each pixel needs a number between 0 and 1. RMBG-1.4 is about 42.3 MiB as int8 and roughly double as fp16; BiRefNet-lite 512 is about 93.9 MiB, finer at the edges and slower to download.
The model output is not the end of it. BiRefNet emits raw logits, from about -18 to +19 in our measurements, so those go through sigmoid first; RMBG already returns a 0..1 probability. Then comes our chain: sigmoid, min-max, guided filter, levels, bilinear upscale, decontamination. The feather and thresh sliders control the guided filter and the black and white points. That last step removes the colour rim from the first paragraph. A couple of pixels of edge matter more here than a few points of IoU on a leaderboard.
| Rung | Representative model | Output | Measured size |
|---|---|---|---|
| Detection | YOLOv10n | Box + class + confidence | ~2.5 MiB |
| Detection | RT-DETR R18 | End-to-end boxes (no NMS) | ~20.0 MiB |
| Segmentation | MediaPipe Selfie | Foreground probability map | ~0.2 MiB |
| Segmentation | MODNet | Portrait matte | ~6.3 MiB |
| Segmentation | SAM Tiny | Promptable mask | ~13.1 MiB |
| Matting | RMBG-1.4 | Soft alpha | ~42.3 MiB (int8) |
| Matting | BiRefNet-lite 512 | Soft alpha (finer) | ~93.9 MiB |
Crop first
// the detector gives a box; only that crop goes to the segmenter
const crop = cropToBox(frame, box);
const mask = await segmenter(crop);
// paste the local mask back at the box's position
composeMask(mask, box, frame.width, frame.height);
// soft alpha: sigmoid → guided-filter feather → levels → decontaminateSegmenting a full 1080p frame versus a 200×300 crop of the person differs by an order of magnitude in time, and the extracted edge looks the same. This was the first optimisation we made on the demo, and it costs one detection pass.
The three demos in a row
- If you only need to know how many people are in frame and where, detection is enough
- For a background swap or blur, lightweight segmentation between 0.2 and 6 MiB will do
- Compositing onto another image, or print-grade edges, needs the soft alpha from RMBG or BiRefNet
- When the object class is not fixed and you want click-to-segment, SAM Tiny is the shape you want
All three demos use the same sample images, so the outputs are easy to compare side by side.