Nodes/ComfyUI_LayerStyle_Advance/LayerMask: Object Detector Mask(Advance)
ComfyUI Node Runs on cloud

LayerMask: Object Detector Mask(Advance)

Turn a hand-painted mask into bbox data for the rest of the pipeline

By chflame163·Created 2 years ago·Updated 4 months ago· 696
LayerMask: Object Detector Mask(Advance)
  • object_mask
  • bboxes
  • preview
sort_method
bbox_select
select_index0,

Every "object detector" in LayerStyle Advance so far - Gemini, GroundingDINO+SAM, Florence2, YOLO - finds objects for you. ObjectDetectorMask is the odd one out: it doesn't detect anything. It takes a mask you already have, whether hand-painted, generated by an earlier segmentation step, or produced any other way, and converts it into BBOXES data - one box per separate white region on the mask. It's the adapter that lets a manually-created mask plug into the same bbox-consuming pipeline (BBoxJoin, DrawBBoxMask, SAM2UltraV2) as the AI detectors.

This matters more than it sounds like it should, because it means "manually paint the region I care about" and "let an AI find it" become interchangeable inputs to everything downstream - you're not locked into automated detection for every step of a pipeline.

How it works

Every enclosed white area on object_mask becomes its own separate box. If you painted two disconnected blobs, you get two boxes out; one connected blob, one box.

The inputs and outputs that matter

  • object_mask - required, the mask to convert.
  • sort_method - left_to_right, top_to_bottom, big_to_small, or confidence. Controls the order boxes come out in, which matters when a downstream node's select_index refers to them by position.
  • bbox_select - all, first, or by_index. all passes every detected region through; first keeps only the highest-priority one per sort_method; by_index lets you pick specific ones.
  • select_index (default "0,") - only relevant when bbox_select is by_index. A comma-separated list of indices (0 is the first), letting you select multiple specific regions from a mask with several disconnected blobs.

Outputs are bboxes (BBOXES) and preview (IMAGE) - the same output shape as every other detector node in the pack, which is the whole point.

Where this fits

Two common patterns: feeding a manually-painted region into SAM2UltraV2 to get a refined, edge-clean segmentation instead of using the rough painted mask directly, or combining a hand-drawn region with an AI-detected one via BBoxJoin when the automated detector missed something you can see but couldn't easily describe in a text prompt.

Installing it

ComfyUI Manager: search "ComfyUI Layer Style Advance". Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance.git

Run install_requirements.bat (or the manual pip/whl steps for a portable install) and restart. No model, no API key - this is a pure geometry conversion, same install-lightness as BBoxJoin and DrawBBoxMask.

Common issues

One connected blob comes out as multiple boxes, or vice versa. Check your mask for accidental gaps or bridges - a blob you painted as "one region" with a thin unpainted line through it will read as two separate enclosed areas, and two nearby regions that touch even at a single pixel will read as one.

bbox_select: by_index doesn't return what you expected. The index order depends on sort_method - if you're picking by_index without first checking how sort_method orders the regions, you can easily grab the wrong one. Check the preview output to confirm which region each index actually refers to before relying on it in a larger pipeline.

Tiny noise specks in the mask become unwanted extra boxes. This node doesn't filter by size - every enclosed white area counts, including small stray pixels from an imperfect paint job or a noisy upstream mask. Clean the mask (or run it through a minimum-area filter) before this node if you're seeing more boxes than you expect.

Category😺dzNodes/LayerMask

Inputs (4)

NameTypeDefaultDescription
object_maskMASK
sort_methodCOMBO4 options: left_to_right, top_to_bottom, big_to_small, confidence
bbox_selectCOMBO3 options: all, first, by_index
select_indexSTRING0,

Outputs (2)

NameTypeDescription
bboxesBBOXES
previewIMAGE