Portrait Relight
Upload your target image and a reference lighting image. Relights your target image.
简介
The 'Portrait Relight' workflow in ComfyUI is designed to enhance your images by altering their lighting based on a reference image. This workflow utilizes the Qwen-Image-Edit model to intelligently adjust the lighting of a target image, making it appear as if it was lit under the conditions of the reference image.
The process involves several key nodes, including the LoadImage node for importing images, and the SaveImage node for exporting the final result. The workflow is particularly useful for photographers and digital artists looking to achieve consistent lighting across different images or to experiment with creative lighting effects without the need for physical lighting equipment.
你需要提供
- 正在读取工作流
在 ComfyUI 中运行。 此工作流无法在本页面运行。你可以在 Comfy Cloud 中打开(已预先加载所需内容),或下载后在自己的 ComfyUI 中使用。
在 Cloud 中试用查看工作流内部
节点图的只读预览。在 Comfy Cloud 中打开或下载后即可编辑节点。
Loading the graph
Open full-size workflow preview- 作者
- Rob
需要自定义节点
- 正在读取工作流
通过代码使用此工作流
尽可能根据工作流图和输入自动生成代码,否则显示已保存的示例。运行代码可能产生费用,请先核对凭据和端点。
What you need
- Runs on
- Comfy Cloud
- 密钥
- COMFY_API_KEY
需要付费的 Cloud 方案和额度。
# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"5": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI-light_migration",
"images": [
"1:76",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "input_2-relight.png"
},
"_meta": {
"title": "Load Lighting Image"
}
},
"7": {
"class_type": "LoadImage",
"inputs": {
"image": "input_1-relight.png"
},
"_meta": {
"title": "Load Subject Image"
}
},
"1:101": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Light-Migration.safetensors",
"model": [
"1:89",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"1:102": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"1:38",
0
],
"image1": [
"1:104",
0
],
"image2": [
"1:105",
0
],
"prompt": "",
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"1:103": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"1:38",
0
],
"image1": [
"1:104",
0
],
"image2": [
"1:105",
0
],
"prompt": "参考色调,移除图1原有的光照并参考图2的光照和色调对图1重新照明",
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"1:104": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"7",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "lanczos"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"1:105": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"6",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "nearest-exact"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"1:108": {
"class_type": "RepeatLatentBatch",
"inputs": {
"amount": 1,
"samples": [
"1:88",
0
]
},
"_meta": {
"title": "Repeat Latent Batch"
}
},
"1:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"1:108",
0
],
"model": [
"1:75",
0
],
"negative": [
"1:103",
0
],
"positive": [
"1:102",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 260787325020957,
"steps": 8
},
"_meta": {
"title": "KSampler"
}
},
"1:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"1:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"1:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"1:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"1:101",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"1:75": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"1:66",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"1:76": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"1:3",
0
],
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"1:88": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"1:104",
0
],
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"1:89": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-8steps-V1.0-bf16.safetensors",
"model": [
"1:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)常见问答
Portrait images with clear lighting and shadow details tend to work best, as the model can effectively adjust these elements to match the reference lighting.
Yes, while optimized for portraits, the workflow can be applied to any image where lighting adjustments are desired.
No special hardware is required, but a GPU will significantly speed up the processing time, especially for high-resolution images.
You can append additional image edit prompt instructions in the workflow to maintain specific details, such as edges, during the relighting process.