Nodes/ComfyUI-ArchAi3d-Qwen/ArchAi3D_Mask_To_Position_Guide
ComfyUI Node

ArchAi3D_Mask_To_Position_Guide

Turn a mask into a numbered map so the model knows which thing is which

By amir84ferdos·Created 11 months ago·Updated 5 months ago· 70
ArchAi3D_Mask_To_Position_Guide
  • mask
  • guide_image
  • region_count
  • bbox_list
numbering_orderleft_to_right
rectangle_colorred
rect_hex_colorFF0000
line_thickness2
number_size18
number_colorred
num_hex_colorFF0000
padding5
background_colorcustom_hex
bg_hex_color0F0F0F

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) or custom_hex with a rect_hex_color / num_hex_color field (defaults FF0000).
  • line_thickness (default 2), number_size (default 18), padding (default 5) - cosmetics around the boxes.
  • background_color - the guide's background; default is custom_hex with 0F0F0F, 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.

CategoryArchAi3d/Utils

Inputs (11)

NameTypeDefaultDescription
maskMASKInput mask with selected regions (white = selected, black = background)
numbering_orderCOMBOleft_to_rightOrder 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_colorCOMBOredColor for rectangle borders (use 'custom_hex' to define hexadecimal color code below)
rect_hex_colorSTRINGFF0000Hexadecimal color code for rectangles (e.g., 'FF0000' or '#FF0000') - only used when rectangle_color='custom_hex'
line_thicknessINT21–20Thickness of rectangle borders in pixels
number_sizeINT1812–200Font size for numbers inside rectangles
number_colorCOMBOredColor for numbers (use 'custom_hex' to define hexadecimal color code below)
num_hex_colorSTRINGFF0000Hexadecimal color code for numbers (e.g., 'FF0000' or '#FF0000') - only used when number_color='custom_hex'
paddingINT50–50Padding around detected regions in pixels
background_colorCOMBOcustom_hexBackground color for the guide image (use 'custom_hex' to define hexadecimal color code below)
bg_hex_colorSTRING0F0F0FHexadecimal color code for background (e.g., '0F0F0F' or '#0F0F0F') - only used when background_color='custom_hex'

Outputs (3)

NameTypeDescription
guide_imageIMAGEPosition guide image with numbered rectangles (use with Multi Image Text Encoder V3)
region_countINTNumber of regions detected
bbox_listSTRINGJSON list of bounding boxes for each region