ArchAi3D_Mask_To_Position_Guide
Turn a mask into a numbered map so the model knows which thing is which
- mask
- guide_image
- region_count
- bbox_list
Qwen-VL models genuinely struggle with "the second object from the left." Point them at a scene and ask them to modify one of several similar items and they'll pick wrong about half the time. The workaround that this pack commits to is position guides: a reference image where each region you care about is wrapped in a numbered rectangle, so the model can say "region 2" with confidence. ArchAi3D_Mask_To_Position_Guide builds that guide image from a mask, automatically.
How it works
You feed it a mask - white where regions are, black elsewhere (from a segmentation node, a hand-painted mask, whatever). The node detects the connected regions, draws a numbered rectangle around each one, and renders a clean guide image. The clever part is the control you get over how the numbers map to the image, because that determines how you write the prompt:
numbering_order-left_to_right,right_to_left,top_to_bottom,bottom_to_top. Region 1 is wherever this says first, so if you number left-to-right you must write "region 1 = the leftmost thing" in your prompt.rectangle_color/number_color- pick from the presets (red, blue, green, yellow, magenta, cyan, white, black) orcustom_hexwith arect_hex_color/num_hex_colorfield (defaultsFF0000).line_thickness(default 2),number_size(default 18),padding(default 5) - cosmetics around the boxes.background_color- the guide's background; default iscustom_hexwith0F0F0F, a dark backdrop that makes the colored boxes pop.
Outputs:
guide_image- the numbered guide, meant to be fed to the pack's Multi Image Text Encoder V3 alongside the regional text.region_count- how many regions were detected (a good sanity check that your mask parsed the way you thought).bbox_list- the bounding boxes as a JSON string, if you need the geometry downstream.
The workflow it feeds
Typical chain: segment or paint regions → Mask to Position Guide → build region text with ArchAi3D_Extract_Region_Text ("region 1: 'repaint the wall', region 2: 'swap the flooring'") → encode guide + text together → Qwen edit. The guide gives the model spatial anchors; the numbered text gives it the instructions per anchor. It's the pack's answer to the regional-prompting problem the KB documents - and notably it replaces pixel coordinates with numbered regions, which is exactly the thing Qwen-VL actually responds to.
Install and notes
cd ComfyUI/custom_nodes
git clone https://github.com/amir84ferdos/ComfyUI-ArchAi3d-Qwen.git
cd ComfyUI-ArchAi3d-Qwen && pip install -r requirements.txt
The node uses OpenCV (cv2) for region detection, which is in the Metric3D dependency group - if you installed only the pack's core deps, pip install opencv-python covers it. ComfyUI Manager → search "ArchAi3d Qwen" works too. Keep the numbering order consistent between the guide and your text, and remember: free personal, paid commercial, like everything in the pack.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | Input mask with selected regions (white = selected, black = background) | |
| numbering_order | COMBO | left_to_right | Order for numbering regions: - left_to_right: Numbers increase from left to right (→) - right_to_left: Numbers increase from right to left (←) - top_to_bottom: Numbers increase from top to bottom (↓) - bottom_to_top: Numbers increase from bottom to top (↑) |
| rectangle_color | COMBO | red | Color for rectangle borders (use 'custom_hex' to define hexadecimal color code below) |
| rect_hex_color | STRING | FF0000 | Hexadecimal color code for rectangles (e.g., 'FF0000' or '#FF0000') - only used when rectangle_color='custom_hex' |
| line_thickness | INT | 21–20 | Thickness of rectangle borders in pixels |
| number_size | INT | 1812–200 | Font size for numbers inside rectangles |
| number_color | COMBO | red | Color for numbers (use 'custom_hex' to define hexadecimal color code below) |
| num_hex_color | STRING | FF0000 | Hexadecimal color code for numbers (e.g., 'FF0000' or '#FF0000') - only used when number_color='custom_hex' |
| padding | INT | 50–50 | Padding around detected regions in pixels |
| background_color | COMBO | custom_hex | Background color for the guide image (use 'custom_hex' to define hexadecimal color code below) |
| bg_hex_color | STRING | 0F0F0F | Hexadecimal color code for background (e.g., '0F0F0F' or '#0F0F0F') - only used when background_color='custom_hex' |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| guide_image | IMAGE | Position guide image with numbered rectangles (use with Multi Image Text Encoder V3) |
| region_count | INT | Number of regions detected |
| bbox_list | STRING | JSON list of bounding boxes for each region |