From cc1c5da4f63033a70100cd3ef119413ebd417426 Mon Sep 17 00:00:00 2001 From: AIGCZero Date: Mon, 15 Sep 2025 13:53:09 +0800 Subject: [PATCH] Add intelligent scaling algorithm selection for Qwen image edit node - Implement automatic algorithm selection: area for downscaling, lanczos for upscaling - Improve image quality by choosing optimal scaling method based on target size - Add Chinese comments for better code documentation - Ensure 8-pixel alignment for better compatibility with diffusion models --- comfy_extras/nodes_qwen.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/comfy_extras/nodes_qwen.py b/comfy_extras/nodes_qwen.py index afba40069..c7e9fdecc 100644 --- a/comfy_extras/nodes_qwen.py +++ b/comfy_extras/nodes_qwen.py @@ -29,16 +29,19 @@ class TextEncodeQwenImageEdit: total = int(1024 * 1024) scale_by = math.sqrt(total / (samples.shape[3] * samples.shape[2])) - + # 修改缩放规则:乘数为8,向下取整 width = math.floor(samples.shape[3] * scale_by / 8) * 8 height = math.floor(samples.shape[2] * scale_by / 8) * 8 + # 根据缩放比例选择算法:缩小用area,放大用lanczos original_width = samples.shape[3] original_height = samples.shape[2] if width < original_width or height < original_height: + # 缩小图像,使用area算法保持细节 upscale_method = "area" else: + # 放大图像,使用lanczos算法获得更好质量 upscale_method = "lanczos" s = comfy.utils.common_upscale(samples, width, height, upscale_method, "disabled") @@ -54,6 +57,7 @@ class TextEncodeQwenImageEdit: if ref_latent is not None: conditioning = node_helpers.conditioning_set_values(conditioning, {"reference_latents": [ref_latent]}, append=True) + # 将ref_latent包装成ComfyUI LATENT类型要求的格式 latent_output = {"samples": ref_latent} if ref_latent is not None else None return (conditioning, output_image, latent_output)