Regional Prompt Builder
The ERPK 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
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 itimage- optional reference image shown under the regions and passed through; sit this node inline in an image-edit chaindesc_1…desc_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.
Inputs (28)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 102464–8192 | Target frame width in pixels |
| height | INT | 102464–8192 | Target frame height in pixels |
| prompt | STRING | Scene description: subject, setting, background, and style. Elements drawn on the canvas are placed on top of this scene. | |
| regions_data | STRING | [] | Managed by the canvas editor; JSON list of normalized regions. |
| removal_fillopt | COMBO | inpaint | How 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_coloropt | STRING | #00B140 | Hex chroma key color used when removal_fill is 'chroma' (default chroma green; pick blue/magenta if the scene already contains the key color). |
| imageopt | IMAGE | Optional reference image shown under the canvas regions and passed through unchanged, so the builder can sit inline in an image-edit chain. | |
| desc_1opt | STRING | Overrides region 1's description when connected (regions numbered as on the canvas). | |
| desc_2opt | STRING | Overrides region 2's description when connected (regions numbered as on the canvas). | |
| desc_3opt | STRING | Overrides region 3's description when connected (regions numbered as on the canvas). | |
| desc_4opt | STRING | Overrides region 4's description when connected (regions numbered as on the canvas). | |
| desc_5opt | STRING | Overrides region 5's description when connected (regions numbered as on the canvas). | |
| desc_6opt | STRING | Overrides region 6's description when connected (regions numbered as on the canvas). | |
| desc_7opt | STRING | Overrides region 7's description when connected (regions numbered as on the canvas). | |
| desc_8opt | STRING | Overrides region 8's description when connected (regions numbered as on the canvas). | |
| desc_9opt | STRING | Overrides region 9's description when connected (regions numbered as on the canvas). | |
| desc_10opt | STRING | Overrides region 10's description when connected (regions numbered as on the canvas). | |
| ref_1opt | IMAGE | Reference 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_2opt | IMAGE | Reference 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_3opt | IMAGE | Reference 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_4opt | IMAGE | Reference 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_5opt | IMAGE | Reference 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_6opt | IMAGE | Reference 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_7opt | IMAGE | Reference 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_8opt | IMAGE | Reference 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_9opt | IMAGE | Reference 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_10opt | IMAGE | Reference 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). | |
| regionsopt | ERPK_REGIONS | Detected 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)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |
| bboxes | BOUNDING_BOX | — |
| width | INT | — |
| height | INT | — |
| image | IMAGE | — |
| image_refs | ERPK_IMAGE_REFS | Per-region reference images in region order; connect to an image edit node's image_refs input. |
| masks | MASK | One mask per region in region order [N, height, width]; regions without a stored segmentation get a filled-rectangle mask. |