ComfyUI-RefineNode

ComfyUI-RefineNode provides a small set of model-agnostic ComfyUI nodes for local repainting, detail repair, product/logo/text refinement, and paste-back compositing.

RefineAnything targets region-specific image refinement: given an input image and a user-specified region (e.g., scribble mask or bounding box), it restores fine-grained details--text, logos, thin structures--while keeping all non-edited pixels unchanged. It supports both reference-based and reference-free refinement.

Installation

Clone this repository into your ComfyUI custom_nodes directory:

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

Restart ComfyUI after installation.

Example Workflows

The included example workflows use the Qwen Image Edit model together with the RefineAnything LoRA.

RefineAnything LoRA: limuloo1999/RefineAnything

You can try different options in the Edit Model Reference Method node, but it is best to avoid index_timestep_zero because it can introduce a noticeable color shift.

For workflows with several painted regions, insert the mask-only nodes before RefineNode Preprocess Mask:

Load Image mask -> RefineNode Mask Batch Process -> optional RefineNode Combine Nearby Masks -> RefineNode Preprocess Mask

example_workflows/Reference-based Logo Refinement.json

  • Reference-based workflow for refining logos, text, or product details with a clean reference image.
  • In reference-based mode, connect the target refinement image to image1, the reference image to image2, and the target refinement mask/spatial mask image to image3.

Reference-based Logo Refinement workflow

example_workflows/Reference-free Text Refinement.json

  • Reference-free workflow for refining local text details from the target image and mask only.

Reference-free Text Refinement workflow

Node Details

RefineNode Mask Batch Process

Prepares a MASK tensor before it is sent into RefineNode Preprocess Mask.

Inputs:

  • mask: Input mask. This can be a normal mask, a batched mask, or a ComfyUI mask list.
  • combined_mask: When disabled, each disconnected painted island is split into a separate mask in the output batch. When enabled, all incoming masks are unioned into one mask.

Outputs:

  • mask: A processed MASK batch.

Use this node when a single Load Image mask contains multiple separated painted regions and you want either one refinement job per region or one combined refinement job.

RefineNode Combine Nearby Masks

Groups close masks together without touching the image or paste-back metadata.

Inputs:

  • mask: Input mask batch or mask list. All masks must have the same spatial size.
  • max_gap: Maximum bounding-box gap, in pixels, for two masks to be grouped. The default is 32.

Outputs:

  • mask: A MASK batch where each output mask is the union of one nearby group.

Grouping is deterministic and transitive: if mask A is near B, and B is near C, A/B/C become one output mask. Distant groups remain separate.

RefineNode Preprocess Mask

Prepares the target image and optional mask before model inference, and creates the info data required for accurate paste-back.

Inputs:

  • image: The image to refine or use as a reference.
  • mask: Optional mask. If disconnected, the node uses an empty mask and does not raise an error.
  • focus_crop: When enabled, crops around the masked region to reduce unrelated image area before generation.
  • focus_crop_margin: Extra context retained around the mask crop.
  • spatial_prompt_source: Controls the spatial_mask_image output. mask keeps the original mask shape, while bbox uses the mask bounding box.

Outputs:

  • image: Processed model input image.
  • spatial_mask_image: Spatial mask image for image-editing nodes such as Qwen Image Edit Plus.
  • mask: Mask aligned with the output image.
  • info: Metadata containing the original image, crop position, mask, and paste-back coordinates. Pass this to downstream paste-back nodes.

Mask behavior:

  • RefineNode Preprocess Mask no longer decides whether masks should be split or combined.
  • A batched MASK input is treated as the exact refinement job list: one output image-list item per incoming mask, using the existing image/mask batch assignment rules.
  • Use RefineNode Mask Batch Process and RefineNode Combine Nearby Masks before this node when you need to split painted islands, combine all masks, or group nearby mask regions.

RefineNode Reference Image Process

Resizes and aligns the target image, reference image, and mask image to exactly the same size. This is useful for multi-image reference workflows and Qwen Image Edit Plus style inputs.

Inputs:

  • image1: Required. Usually the target refinement image.
  • image2: Optional. Usually the reference image.
  • image3: Optional. In reference-based mode, usually the target refinement mask or spatial_mask_image.
  • info: Optional REFINENODE_INFO from RefineNode Preprocess Mask. When connected, the node records its resize, crop, or fill transform so RefineNode Paste Back can restore the generated image to the correct original position.
  • fit_kontext_size: When enabled, uses the ComfyUI/Flux Kontext-style target size. When disabled, uses an approximately 1024 x 1024 target area rounded to multiples of 8.
  • resize_method: Shared resize method for all connected images. The default is lanczos.
  • crop_mode: crop center-crops to the target aspect ratio, disable resizes directly, and fill preserves aspect ratio then pads with black to the target size.

Outputs:

  • image1: Processed target refinement image.
  • image2: Processed reference image. If the input is disconnected, this output is a blank placeholder image.
  • image3: Processed mask image or third reference image. If the input is disconnected, this output is a blank placeholder image.
  • info: Updated paste-back metadata.

When image1 or image3 comes from a multi-mask RefineNode Preprocess Mask image list, ComfyUI processes each list item sequentially. A single connected reference image in image2 is reused for all list items.

Reference-based mode reminder:

  • Connect the target refinement image to image1.
  • Connect the reference image to image2.
  • Connect the target refinement mask/spatial mask image to image3.

RefineNode Paste Back

Composites the generated result back into the original image and returns both the final image and the actual paste mask.

Inputs:

  • generated_image: Image generated by the model.
  • info: Paste-back metadata from RefineNode Preprocess Mask or RefineNode Reference Image Process.
  • paste_back_mode: mask pastes using the original mask, while bbox pastes using the mask bounding box.
  • mask_grow: Expands the paste mask before compositing. Useful for reducing tiny uncovered edges.
  • blend_blur: Blurs and feathers the paste mask to soften seams.

Outputs:

  • image: Final pasted-back image.
  • paste_mask: Actual mask used for compositing, useful for previewing and debugging the paste area.

When generated_image and info arrive as ComfyUI lists, all generated refinement results that belong to the same original source image are pasted back sequentially into that original image. The node returns one final image and one combined paste mask per source image.

Citation

If you use this repository, please cite:

@article{zhou2026refineanything,
  title={RefineAnything: Multimodal Region-Specific Refinement for Perfect Local Details},
  author={Zhou, Dewei and Li, You and Yang, Zongxin and Yang, Yi},
  journal={arXiv preprint arXiv:2604.06870},
  year={2026}
}
S
Description
No description provided
Readme
1.4 MiB
Languages
Python 100%