mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-05 19:12:41 +08:00
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
This commit is contained in:
parent
c8bfec86b3
commit
cc1c5da4f6
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user