Nodes/☁️BizyAir Nodes/☁️BizyAir Trimap Generate
ComfyUI Node

☁️BizyAir Trimap Generate

ComfyUI Node Guide

By siliconflow·Created 2 years ago·Updated 11 months ago· 855
☁️BizyAir Trimap Generate
  • mask
  • trimap
detail_erode6
detail_dilate6

A regular segmentation mask draws a hard line: this pixel is foreground, that one isn't. That's fine for a solid object with clean edges, and structurally wrong for anything with hair, fur, or a soft transparent boundary - there's no way to say a pixel is "60% foreground" with a binary mask. Matting algorithms solve that by predicting fractional alpha instead, but they need a different kind of input to work from: a trimap, which marks three zones instead of two - definite foreground, definite background, and an "unknown" ring in between that the matting model is actually asked to resolve.

This node builds that trimap automatically from a plain mask, which is exactly the input a matting-based detail pass - like the one inside BizyAir LayerMask: SegmentAnythingUltra V2 - needs to do its job well.

How it works

It takes your existing mask and erodes it inward to define a confident "this is definitely foreground" core, then dilates it outward to define a confident "this is definitely background" boundary. The gap between the eroded and dilated versions becomes the unknown zone - the part a matting algorithm will actually spend its effort resolving, pixel by pixel, rather than the noisier original edge you started with.

Inputs and outputs

  • mask - the source mask to convert, type MASK. This should be a reasonably good approximate mask already (from SAM, background removal, or manual painting) - the trimap generator refines the edge, it doesn't fix a fundamentally wrong selection.
  • detail_erode - an integer from 1 to 255, default 6, controlling how far inward from the mask edge the "definite foreground" zone gets pulled.
  • detail_dilate - same range, also default 6, controlling how far outward the "definite background" boundary extends.

The wider you set these relative to each other, the larger the unknown zone a downstream matting algorithm has to work with - useful for subjects with a lot of fine detail at the edge (hair, fur), where you want to give the matting pass more room to resolve gradual transitions.

Output is a single trimap, typed MASK - feed it into whichever matting node in your workflow expects a trimap as input.

Installing BizyAir

Through ComfyUI Manager: search "BizyAir," install. Or clone it directly:

cd ComfyUI/custom_nodes && git clone https://github.com/siliconflow/BizyAir.git

Restart ComfyUI, or run comfy node install bizyair via Comfy-CLI. Set your API key on first use through the README's "click to login" step - like the rest of the pack, this runs on BizyAir's cloud rather than locally.

Common issues

If your final matted result still has a hard, obviously segmented edge, the unknown zone this node produced is probably too thin - bump detail_erode and detail_dilate up so there's more room between definite-foreground and definite-background for the matting algorithm to actually work with.

Conversely, if the matting pass is producing muddy or inconsistent results in areas that should be simple (a clean edge on a plain object), your zone may be too wide relative to how detailed that part of the subject actually is - try tightening both values back down.

Remember this node is only as good as the mask you feed it: if the underlying mask misses part of the subject or includes something it shouldn't, no amount of trimap tuning will fix that upstream problem. Get the base segmentation right first.

Category☁️BizyAir/segment-anything

Inputs (3)

NameTypeDefaultDescription
maskMASK
detail_erodeINT61–255
detail_dilateINT61–255

Outputs (1)

NameTypeDescription
trimapMASK