Region Mask
Turn a detected box into a usable mask
- image
- region_meta
- ui_widget
- mask
- mask_list
- region
The detection nodes find the box. LF_RegionMask is what turns that box into something you can actually use - a real MASK you can pipe into an inpaint, a regional prompt, or a composite. It takes the region_meta output from LF_DetectRegions and carves a mask out of the selected region's bounding box, with padding and feathering built in so the mask doesn't look like a hard-edged rectangle slapped on the image.
This is the step people skip and then regret. A raw detection box is a rectangle; an inpaint wants a mask that covers the subject's shape and blends at the edges. That's exactly what this node exists to produce.
How it works
Required inputs: image (whose dimensions define the mask canvas) and region_meta (from any region-detection node, including LF_DetectRegions). The optional settings are the ones you'll actually tune:
region_index--1(default) uses the region flagged as selected by the detector; set an explicit index to force another one from the list.shape-rectangleorellipse, i.e. how aggressively the mask is carved inside the box. Ellipse is good for faces and round subjects; rectangle for anything you want fully covered.padding(default0.05) - fractional padding relative to region size. A little positive padding keeps masks from clipping the subject's edges.padding_px- absolute pixel padding on top of the fractional kind. Use whichever reads more naturally for your image size.feather(default0.05) - softens the mask edge so inpainting blends instead of cutting. 0 keeps a hard edge.invert- flips the mask to everything outside the region. Handy for "change the background but keep the subject."
Outputs
mask / mask_list - the carved mask tensor(s), ready for inpainting or compositing nodes. It also returns region (the metadata of the region used), so you can chain downstream nodes that want to know which box produced the mask. The compare widget previews original vs. mask.
Installing it
lf-nodes is one pack:
cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes
restart ComfyUI, or install via ComfyUI Manager ("LF Nodes"). No extra model downloads - this is pure mask math on CPU/GPU.
Common issues
- Mask clipped at the subject's edge - bump
paddingandpadding_px. Detection boxes are often a hair tight. - Hard seams after inpainting - you've left
featherat 0, or very low. A little feathering is the difference between a patch and a blend. - Empty mask -
region_indexpoints at a region that doesn't exist, or the region_meta came from a graph run that produced nothing. Re-run detection first.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Image whose dimensions define the mask canvas. | |
| region_meta | REGION_META | Region metadata dict/list produced by detection nodes. | |
| region_indexopt | INT | -1-1–256 | Index of the region to use; -1 selects the region flagged as selected. |
| shapeopt | COMBO | rectangle | Mask shape to carve inside the bounding box. |
| paddingopt | FLOAT | 0.050–1 | Padding factor relative to region size. |
| padding_pxopt | FLOAT | 0.00–1024 | Additional padding in absolute pixels. |
| featheropt | FLOAT | 0.050–1 | Feather amount; 0 keeps a hard edge. |
| invertopt | BOOLEAN | false | Invert the mask (highlight everything outside the region). |
| ui_widgetopt | LF_COMPARE | [object Object] | Optional compare widget preview (original vs mask). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask | MASK | Region mask output. |
| mask_list | MASK | Region mask output as a list. |
| region | REGION_META | Metadata of the region used to build the mask. |