Nodes/ERPK Collection/Regional Prompt Builder
ComfyUI Node

Regional Prompt Builder

The ERPK Regional Prompt Builder

By eRepublik-Labs·Created 11 months ago·Updated 21 days ago· 1
Regional Prompt Builder
  • image
  • ref_1
  • ref_2
  • ref_3
  • ref_4
  • ref_5
  • ref_6
  • ref_7
  • ref_8
  • ref_9
  • ref_10
  • regions
  • prompt
  • bboxes
  • width
  • height
  • image
  • image_refs
  • masks
width1024
height1024
prompt
regions_data[]
removal_fillinpaint
chroma_color#00B140
desc_1
desc_2
desc_3
desc_4
desc_5
desc_6
desc_7
desc_8
desc_9
desc_10

If you've ever tried to get an instruction-edit model to put something exactly where you want it, you know the pain. You write "a hat on the man's head," and it puts the hat on the grass three meters away. The ERPK Regional Prompt Builder is the pack's answer to that: you draw boxes on a canvas, and it turns your layout into both a prompt and pixel-space bounding boxes the image nodes can use. It's the most interesting node in this whole pack, and the one with the steepest learning curve.

The reason it exists is a genuine quirk of the API image models. Gemini, OpenAI, and Grok image nodes all accept a box_2d coordinate if you pass them one - but they treat it as a weak hint and override it for physical plausibility. A hat boxed into mid-air lands on the ground. Edit models read pixels, not coordinates. So this node does two things: it writes a verbal placement for each region ("between the hippo and the man"), which edit models follow far better, and it emits real bounding boxes as a fallback for the models that do respect them.

How it works

You get a canvas editor right on the node. Drag to draw regions, each with a description, a kind (object or rendered text), and a depth order - region 1 is backmost, later regions render in front. The prompt widget holds your scene description ("a beach at sunset"), and each region's text is layered on top of it. Hit execute and the node emits one assembled prompt line per region, plus normalized coordinates, from the regions_data widget that the canvas manages for you.

The genuinely clever part is the object scan. With an image connected, the ✦ button runs Gemini detect on the scene, turns every object into an editable region, and SAM computes segmentation masks locally (weights download once, default SAM ViT-Base). That gives you masks, so you can do real compositing: move an object and the node composites it pixel-exact and inpaints the origin away with OpenCV, or lets the edit model do it (less exact, but identity and lighting carry over).

The inputs that matter

You mostly set four things:

  • width / height - the target frame in pixels (64–8192, step 8)
  • prompt - the base scene, everything drawn on the canvas is placed on top of it
  • image - optional reference image shown under the regions and passed through; sit this node inline in an image-edit chain
  • desc_1desc_10 - optional STRING sockets that override a region's description at execute time, so any text node can drive a region

removal_fill chooses how cleared areas are filled: inpaint (default) rebuilds background with OpenCV, or chroma lays a flat key color for a downstream chroma keyer. The outputs are the payload: prompt (STRING) goes to any image-generation node's prompt, bboxes (BOUNDING_BOX) wires into core SAM3 Detect / Draw BBoxes / Crop By BBoxes, and image passes your reference through unchanged. There's also masks - one mask per region in region order, ready for inpainting chains - and image_refs, which forwards per-region reference images to Gemini Image Edit.

The trap: Node vs Model moves

Each region has a move mode. Node composites the move into the image deterministically and clears the origin - exact, but the pasted object needs relighting. Model leaves the original in place and asks the edit model to relocate it via on-canvas markers (colored dots labeled A, B, C). Model keeps identity and lighting but lands approximately. If the model leaves a duplicate behind, switch that region to Node. For position-critical work, just use Node - that's the one reliable path to pixel-exact placement.

Install and setup

It ships in the ERPK Collection, so install is the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/eRepublik-Labs/comfyui-nodes-erpk.git erpk
cd erpk && pip install -r requirements.txt

Or install "ERPK Custom Nodes" from ComfyUI Manager and restart. For the object scan you'll need a Gemini API key set in ERPK Settings (right-click the canvas); the masks and cut-out features run locally on OpenCV, which ships with ComfyUI.

One gotcha worth knowing: the hand-drawn regions and the scan both land in the same region list, but only objects already in the image anchor a placement. If a box has no real surface under it, the model will move the object. Draw boxes on things that exist, and keep the base prompt simple - this node does best when it does the layout and the model does the rendering.

CategoryERPK/utils

Inputs (28)

NameTypeDefaultDescription
widthINT102464–8192Target frame width in pixels
heightINT102464–8192Target frame height in pixels
promptSTRINGScene description: subject, setting, background, and style. Elements drawn on the canvas are placed on top of this scene.
regions_dataSTRING[]Managed by the canvas editor; JSON list of normalized regions.
removal_filloptCOMBOinpaintHow cleared areas (cut-outs and moved-region origins) are filled: 'inpaint' rebuilds the background (can smear on busy scenes); 'chroma' lays a flat key color to remove with a downstream chroma keyer.
chroma_coloroptSTRING#00B140Hex chroma key color used when removal_fill is 'chroma' (default chroma green; pick blue/magenta if the scene already contains the key color).
imageoptIMAGEOptional reference image shown under the canvas regions and passed through unchanged, so the builder can sit inline in an image-edit chain.
desc_1optSTRINGOverrides region 1's description when connected (regions numbered as on the canvas).
desc_2optSTRINGOverrides region 2's description when connected (regions numbered as on the canvas).
desc_3optSTRINGOverrides region 3's description when connected (regions numbered as on the canvas).
desc_4optSTRINGOverrides region 4's description when connected (regions numbered as on the canvas).
desc_5optSTRINGOverrides region 5's description when connected (regions numbered as on the canvas).
desc_6optSTRINGOverrides region 6's description when connected (regions numbered as on the canvas).
desc_7optSTRINGOverrides region 7's description when connected (regions numbered as on the canvas).
desc_8optSTRINGOverrides region 8's description when connected (regions numbered as on the canvas).
desc_9optSTRINGOverrides region 9's description when connected (regions numbered as on the canvas).
desc_10optSTRINGOverrides region 10's description when connected (regions numbered as on the canvas).
ref_1optIMAGEReference image for region 1. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_2optIMAGEReference image for region 2. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_3optIMAGEReference image for region 3. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_4optIMAGEReference image for region 4. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_5optIMAGEReference image for region 5. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_6optIMAGEReference image for region 6. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_7optIMAGEReference image for region 7. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_8optIMAGEReference image for region 8. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_9optIMAGEReference image for region 9. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
ref_10optIMAGEReference image for region 10. With an image connected and the region set to Node, it is composited into the scene at the region's box (background auto-keyed), pixel-exact; otherwise it is forwarded on image_refs and the region's prompt line cites its image number (regions numbered as on the canvas).
regionsoptERPK_REGIONSDetected regions (JSON) appended after the canvas regions at execute time. The canvas is unchanged, and desc_N/ref_N bind canvas regions only.

Outputs (7)

NameTypeDescription
promptSTRING
bboxesBOUNDING_BOX
widthINT
heightINT
imageIMAGE
image_refsERPK_IMAGE_REFSPer-region reference images in region order; connect to an image edit node's image_refs input.
masksMASKOne mask per region in region order [N, height, width]; regions without a stored segmentation get a filled-rectangle mask.