From 15338bcd1158d1ce0d86b8dc803b590742dfb03e Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Sat, 24 Jun 2023 07:30:12 +0900 Subject: [PATCH] improved: add fallback_image_opt to SEGSPreview modified: README.md for SEGSPreview --- README.md | 1 + modules/impact/config.py | 2 +- modules/impact/impact_pack.py | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 09ab357..afe099f 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer * SEGSDetailer - Performs detailed work on SEGS without pasting it back onto the original image. * SEGSPaste - Pastes the results of SEGS onto the original image. * SEGSPreview - Provides a preview of SEGS. + * This option is used to preview the improved image through ```SEGSDetailer``` before merging it into the original. Prior to going through ```SEGSDetailer```, SEGS only contains mask information without image information. If fallback_image_opt is connected to the original image, SEGS without image information will generate a preview using the original image. However, if SEGS already contains image information, fallback_image_opt will be ignored. * Pipe nodes * ToDetailerPipe, FromDetailerPipe - These nodes are used to bundle multiple inputs used in the detailer, such as models and vae, ..., into a single DETAILER_PIPE or extract the elements that are bundled in the DETAILER_PIPE. diff --git a/modules/impact/config.py b/modules/impact/config.py index dcfc754..3871294 100644 --- a/modules/impact/config.py +++ b/modules/impact/config.py @@ -1,7 +1,7 @@ import configparser import os -version = "V2.13.8" +version = "V2.14" dependency_version = 1 diff --git a/modules/impact/impact_pack.py b/modules/impact/impact_pack.py index 0b6d3f6..8719496 100644 --- a/modules/impact/impact_pack.py +++ b/modules/impact/impact_pack.py @@ -243,6 +243,9 @@ class SEGSPreview: return {"required": { "segs": ("SEGS", ), }, + "optional": { + "fallback_image_opt": ("IMAGE", ), + } } RETURN_TYPES = () @@ -252,7 +255,7 @@ class SEGSPreview: OUTPUT_NODE = True - def doit(self, segs): + def doit(self, segs, fallback_image_opt): full_output_folder, filename, counter, subfolder, filename_prefix = \ folder_paths.get_save_image_path("impact_seg_preview", self.output_dir, segs[0][1], segs[0][0]) @@ -260,14 +263,22 @@ class SEGSPreview: for seg in segs[1]: if seg.cropped_image is not None: + cropped_image = seg.cropped_image + elif fallback_image_opt is not None: + # take from original image + cropped_image = crop_image(fallback_image_opt, seg.crop_region) + cropped_image = Image.fromarray(np.clip(255. * cropped_image.squeeze(), 0, 255).astype(np.uint8)) + + if cropped_image is not None: file = f"{filename}_{counter:05}_.webp" - seg.cropped_image.save(os.path.join(full_output_folder, file)) + cropped_image.save(os.path.join(full_output_folder, file)) results.append({ "filename": file, "subfolder": subfolder, "type": self.type }) - counter += 1 + + counter += 1 return {"ui": {"images": results}}