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.

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 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.

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.

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.

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%