LayerMask: Object Detector Mask(Advance)
Turn a hand-painted mask into bbox data for the rest of the pipeline
- object_mask
- bboxes
- preview
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, orconfidence. Controls the order boxes come out in, which matters when a downstream node'sselect_indexrefers to them by position.bbox_select-all,first, orby_index.allpasses every detected region through;firstkeeps only the highest-priority one persort_method;by_indexlets you pick specific ones.select_index(default"0,") - only relevant whenbbox_selectisby_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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| object_mask | MASK | — | |
| sort_method | COMBO | 4 options: left_to_right, top_to_bottom, big_to_small, confidence | |
| bbox_select | COMBO | 3 options: all, first, by_index | |
| select_index | STRING | 0, | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| bboxes | BBOXES | — |
| preview | IMAGE | — |