From 049eb2b4f3af7c3fc9f6f1f8c6565a02a43b087f Mon Sep 17 00:00:00 2001 From: EllangoK Date: Fri, 9 Aug 2024 13:11:03 -0400 Subject: [PATCH] Fix Pixel Sort Default + Add Divide --- post_processing/arithmetic_blend.py | 8 +++++++- post_processing/pixel_sort.py | 2 +- post_processing_nodes.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/post_processing/arithmetic_blend.py b/post_processing/arithmetic_blend.py index 594a3ce..c71d78e 100644 --- a/post_processing/arithmetic_blend.py +++ b/post_processing/arithmetic_blend.py @@ -10,7 +10,7 @@ class ArithmeticBlend: "required": { "image1": ("IMAGE",), "image2": ("IMAGE",), - "blend_mode": (["add", "subtract", "difference"],), + "blend_mode": (["add", "subtract", "difference", "divide"],), }, } @@ -26,6 +26,8 @@ class ArithmeticBlend: blended_image = self.subtract(image1, image2) elif blend_mode == "difference": blended_image = self.difference(image1, image2) + elif blend_mode == "divide": + blended_image = self.divide(image1, image2) else: raise ValueError(f"Unsupported arithmetic blend mode: {blend_mode}") @@ -41,6 +43,10 @@ class ArithmeticBlend: def difference(self, img1, img2): return torch.abs(img1 - img2) + def divide(self, img1, img2): + img2_safe = torch.where(img1 == 0, torch.tensor(1e-10), img1) + return img1 / img2_safe + NODE_CLASS_MAPPINGS = { "ArithmeticBlend": ArithmeticBlend, } diff --git a/post_processing/pixel_sort.py b/post_processing/pixel_sort.py index 8b07c0b..8037531 100644 --- a/post_processing/pixel_sort.py +++ b/post_processing/pixel_sort.py @@ -14,7 +14,7 @@ class PixelSort: "mask": ("IMAGE",), "direction": (["horizontal", "vertical"],), "span_limit": ("INT", { - "default": None, + "default": 50, "min": 0, "max": 100, "step": 5 diff --git a/post_processing_nodes.py b/post_processing_nodes.py index bb7dbe0..cdb0cc3 100644 --- a/post_processing_nodes.py +++ b/post_processing_nodes.py @@ -17,7 +17,7 @@ class ArithmeticBlend: "required": { "image1": ("IMAGE",), "image2": ("IMAGE",), - "blend_mode": (["add", "subtract", "difference"],), + "blend_mode": (["add", "subtract", "difference", "divide"],), }, } @@ -33,6 +33,8 @@ class ArithmeticBlend: blended_image = self.subtract(image1, image2) elif blend_mode == "difference": blended_image = self.difference(image1, image2) + elif blend_mode == "divide": + blended_image = self.divide(image1, image2) else: raise ValueError(f"Unsupported arithmetic blend mode: {blend_mode}") @@ -48,6 +50,10 @@ class ArithmeticBlend: def difference(self, img1, img2): return torch.abs(img1 - img2) + def divide(self, img1, img2): + img2_safe = torch.where(img1 == 0, torch.tensor(1e-10), img1) + return img1 / img2_safe + class AsciiArt: def __init__(self): pass @@ -1051,7 +1057,7 @@ class PixelSort: "mask": ("IMAGE",), "direction": (["horizontal", "vertical"],), "span_limit": ("INT", { - "default": None, + "default": 50, "min": 0, "max": 100, "step": 5