From 16b1edc983e27469bff1afd79e23418b5e4ce176 Mon Sep 17 00:00:00 2001 From: chflame Date: Sat, 8 Jun 2024 15:49:18 +0800 Subject: [PATCH] fix ImageScaleRestoreV2 node add total_pixel method --- README.MD | 4 ++-- README_CN.MD | 3 ++- py/image_scale_restore_v2.py | 12 ++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.MD b/README.MD index 5c3ef25..acf37a6 100644 --- a/README.MD +++ b/README.MD @@ -80,7 +80,7 @@ When this error has occurred, please check the network environment. ## Update **If the dependency package error after updating, please reinstall the relevant dependency packages.
- +* [ImageScaleRestoreV2](#ImageScaleRestoreV2) node add the ```total_pixel``` method to scale images. * Commit [MediapipeFacialSegment](#MediapipeFacialSegment) node,Used to segment facial features, including left and right eyebrows, eyes, lips, and teeth. * Commit [BatchSelector](#BatchSelector) node,Used to retrieve specified images or masks from batch images or masks. * LayerUtility creates new subdirectories such as SystemIO, Data, and Prompt. Some nodes are classified into subdirectories. @@ -594,7 +594,7 @@ The V2 upgraded version of ImageScaleRestore. Node options: ![image](image/image_scale_restore_v2_node.jpg) The following changes have been made based on ImageScaleRestore: -* scale_by: Allow scaling by specified dimensions for longest, shortest, width, or height. +* scale_by: Allow scaling by specified dimensions for long, short, width, height, or total pixels. When this option is set to by_scale, use the scale value, and for other options, use the scale_by_length value. * scale_by_length: The value here is used as ```scale_by``` to specify the length of the edge. ### ImageMaskScaleAs diff --git a/README_CN.MD b/README_CN.MD index e36dbf8..63f0d8b 100644 --- a/README_CN.MD +++ b/README_CN.MD @@ -80,6 +80,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git ## 更新说明 **如果本插件更新后出现依赖包错误,请重新安装相关依赖包。 +* [ImageScaleRestoreV2](#ImageScaleRestoreV2)节点增加TotalPixel方法缩放图片。 * 添加 [MediapipeFacialSegment](#MediapipeFacialSegment) 节点, 用于分割面部五官,包括左右眉、眼睛、嘴唇和牙齿。 * 添加 [BatchSelector](#BatchSelector) 节点, 用于从批量图片或遮罩中获取指定的图片或遮罩。 * LayerUtility大类新建子目录SystemIO, Data, Prompt。一部分节点被分类到子目录。 @@ -587,7 +588,7 @@ ImageScaleRestore的V2升级版。 节点选项说明: ![image](image/image_scale_restore_v2_node.jpg) 在ImageScaleRestore基础上做了如下改变: -* scale_by: 允许按长边、短边、宽度或高度指定尺寸缩放。 +* scale_by: 允许按长边、短边、宽度、高度或总像素指定尺寸缩放。此处选项设为by_scale时使用scale值,其他选项时使用scale_by_lengtt值。 * scale_by_length: 这里的数值作为scale_by指定边的长度。 diff --git a/py/image_scale_restore_v2.py b/py/image_scale_restore_v2.py index 05bab3c..43e43ed 100644 --- a/py/image_scale_restore_v2.py +++ b/py/image_scale_restore_v2.py @@ -1,3 +1,5 @@ +import math + from .imagefunc import * NODE_NAME = 'ImageScaleRestore V2' @@ -10,14 +12,14 @@ class ImageScaleRestoreV2: @classmethod def INPUT_TYPES(self): method_mode = ['lanczos', 'bicubic', 'hamming', 'bilinear', 'box', 'nearest'] - scale_by_list = ['by_scale', 'longest', 'shortest', 'width', 'height'] + scale_by_list = ['by_scale', 'longest', 'shortest', 'width', 'height', 'total_pixel(kilo pixel)'] return { "required": { "image": ("IMAGE", ), # "scale": ("FLOAT", {"default": 1, "min": 0.01, "max": 100, "step": 0.01}), "method": (method_mode,), "scale_by": (scale_by_list,), # 是否按长边缩放 - "scale_by_length": ("INT", {"default": 1024, "min": 4, "max": 999999, "step": 1}), + "scale_by_length": ("INT", {"default": 1024, "min": 4, "max": 99999999, "step": 1}), }, "optional": { "mask": ("MASK",), # @@ -81,6 +83,12 @@ class ImageScaleRestoreV2: if scale_by == 'height': target_height = scale_by_length target_width = int(target_height * orig_width / orig_height) + if scale_by == 'total_pixel(kilo pixel)': + r = orig_width / orig_height + target_width = math.sqrt(r * scale_by_length * 1000) + target_height = target_width / r + target_width = int(target_width) + target_height = int(target_height) if target_width < 4: target_width = 4 if target_height < 4: