Nodes/ComfyUI-RefineNode/RefineNode Preprocess Mask
ComfyUI Node

RefineNode Preprocess Mask

The node that does the actual prep work in local refinement

By 1Kynx·Created 4 months ago·Updated 26 days ago· 30
RefineNode Preprocess Mask
  • image
  • mask
  • image
  • spatial_mask_image
  • mask
  • info
focus_croptrue
focus_crop_margin64
spatial_prompt_sourcemask

The whole point of the RefineNode pack is "fix this one region, leave the other 99% of the image untouched." RefineNode Preprocess Mask is where that job actually starts. It takes your image and your painted mask, crops around the region so the model isn't wasting generation budget on irrelevant background, builds the spatial mask Qwen-Image-Edit wants to see, and - most importantly - produces the info metadata that lets the pack stitch the result back into the original pixel-perfectly.

Here's the context that makes it worth reaching for. Whole-frame edit models like Qwen-Image-Edit and Flux Kontext re-emit the entire frame, so pixels you never asked about drift on every pass (the knowledge base's own inpainting essay documents this as the standing complaint). Masked local refinement is the countermove: crop the region, generate at full resolution, paste it back. Preprocess Mask is the first half of that move, and RefineNode Paste Back is the second.

What it does

Inputs: image (required), mask (optional), plus three toggles. Outputs: image, spatial_mask_image, mask, and info - all four come out as lists so the node can serve up multiple jobs.

The three settings:

  • focus_crop (default on) - crops around the masked region before generation. This is why a 64px logo gets a 1024px generation budget instead of being lost in a huge frame.
  • focus_crop_margin (default 64) - how much context around the mask crop to keep. Bump it when the model needs to see the surrounding product to get colors and lighting right.
  • spatial_prompt_source (default mask) - whether the spatial_mask_image output keeps the original mask shape (mask) or uses the mask bounding box (bbox). Qwen-Image-Edit Plus-style nodes take this spatial image as their region signal.

info is the one you can't drop. It bundles the original image, crop position, mask, and paste-back coordinates. Feed it to Paste Back (or Merge Generated Images) and the generated result lands exactly where the region was. Nothing else in the frame moves - that's the feature.

Mask behavior, and the trap it removed

Older versions of this node decided whether to split or combine your masks for you. It doesn't anymore. A batched MASK input is treated as the exact refinement job list: one output item per incoming mask, matched to the image batch by position. Paint three islands and you get three jobs (or, feed it through RefineNode Mask Batch Process / Slice And Match Masks first and decide there). No mask connected means an empty mask and no error - it just refines the whole image, which is a handy way to test the wiring.

Installing and running it

Install via ComfyUI Manager (search "ComfyUI-RefineNode") or:

cd ComfyUI/custom_nodes
git clone https://github.com/1Kynx/ComfyUI-RefineNode.git

Restart and you're done - no requirements.txt, no extra dependencies beyond what ComfyUI ships. To actually run an end-to-end refine you'll also need the model stack from the pack's example workflows (Qwen-Image-Edit 2511 in fp8, its CLIP and VAE, and the RefineAnything LoRA from limuloo1999/RefineAnything), plus ComfyUI's Qwen-Image-Edit nodes.

Troubleshooting

  • Edits bleeding outside the mask - you're probably feeding the model the raw mask instead of the spatial_mask_image, or your mask is too tight and the model has no context. Raise focus_crop_margin.
  • Wonky paste-back - info is disconnected somewhere. It's a chain; every link from this node to Paste Back must stay wired.
  • Color shift on the result - not this node's fault. In the Edit Model Reference Method node, index_timestep_zero is known to shift colors; switch to index or another method.
CategoryRefineNode

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
focus_cropBOOLEANtrue
focus_crop_marginINT640–2048
spatial_prompt_sourceCOMBOmask2 options: mask, bbox
maskoptMASK

Outputs (4)

NameTypeDescription
imageIMAGE
spatial_mask_imageIMAGE
maskMASK
infoREFINENODE_INFO