Transformers
Image Segmentation
Segment images for background removal and scene understanding.
Segment images into labeled regions using semantic segmentation models. Useful for background removal, scene understanding, and image editing.
For full API reference (segmentImage(), options, result types, and custom providers), see the Core Vision guide.
See it in action
Try Background Remover for a working demo.
Recommended Models
| Model | Size | Speed | Use Case |
|---|---|---|---|
briaai/RMBG-1.4 | ~176MB | ⚡⚡ | High-quality background removal (non-commercial license) |
Xenova/segformer-b0-finetuned-ade-512-512 | ~90MB | ⚡⚡ | Semantic segmentation (MIT license) |
Background Removal Example
Based on the Background Remover showcase app:
import { transformers } from '@localmode/transformers';
import { segmentImage } from '@localmode/core';
const model = transformers.segmenter('briaai/RMBG-1.4');
async function removeBackground(imageDataUrl: string) {
const { masks } = await segmentImage({
model,
image: imageDataUrl,
abortSignal: controller.signal,
});
// Find the main subject mask (e.g., 'person', 'wall', etc.)
// Apply the mask to create a transparent background
return applyMaskToImage(imageDataUrl, masks);
}Best Practices
Segmentation Tips
- License — RMBG-1.4 is non-commercial only; commercial use requires a paid license from BRIA AI. Use
segformer-b0(MIT) for commercial projects. - Purpose-built for background removal — RMBG-1.4 excels at foreground/background separation
- Multiple masks — Each segment in the image gets its own mask and label
- Combine masks — Merge related masks for background removal (e.g., combine all non-subject masks)
- Canvas processing — Use Canvas API to apply masks for transparency effects