Fix Pixel Sort Default + Add Divide

This commit is contained in:
EllangoK
2024-08-09 13:11:03 -04:00
parent 522817d3d3
commit 049eb2b4f3
3 changed files with 16 additions and 4 deletions
+7 -1
View File
@@ -10,7 +10,7 @@ class ArithmeticBlend:
"required": { "required": {
"image1": ("IMAGE",), "image1": ("IMAGE",),
"image2": ("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) blended_image = self.subtract(image1, image2)
elif blend_mode == "difference": elif blend_mode == "difference":
blended_image = self.difference(image1, image2) blended_image = self.difference(image1, image2)
elif blend_mode == "divide":
blended_image = self.divide(image1, image2)
else: else:
raise ValueError(f"Unsupported arithmetic blend mode: {blend_mode}") raise ValueError(f"Unsupported arithmetic blend mode: {blend_mode}")
@@ -41,6 +43,10 @@ class ArithmeticBlend:
def difference(self, img1, img2): def difference(self, img1, img2):
return torch.abs(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 = { NODE_CLASS_MAPPINGS = {
"ArithmeticBlend": ArithmeticBlend, "ArithmeticBlend": ArithmeticBlend,
} }
+1 -1
View File
@@ -14,7 +14,7 @@ class PixelSort:
"mask": ("IMAGE",), "mask": ("IMAGE",),
"direction": (["horizontal", "vertical"],), "direction": (["horizontal", "vertical"],),
"span_limit": ("INT", { "span_limit": ("INT", {
"default": None, "default": 50,
"min": 0, "min": 0,
"max": 100, "max": 100,
"step": 5 "step": 5
+8 -2
View File
@@ -17,7 +17,7 @@ class ArithmeticBlend:
"required": { "required": {
"image1": ("IMAGE",), "image1": ("IMAGE",),
"image2": ("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) blended_image = self.subtract(image1, image2)
elif blend_mode == "difference": elif blend_mode == "difference":
blended_image = self.difference(image1, image2) blended_image = self.difference(image1, image2)
elif blend_mode == "divide":
blended_image = self.divide(image1, image2)
else: else:
raise ValueError(f"Unsupported arithmetic blend mode: {blend_mode}") raise ValueError(f"Unsupported arithmetic blend mode: {blend_mode}")
@@ -48,6 +50,10 @@ class ArithmeticBlend:
def difference(self, img1, img2): def difference(self, img1, img2):
return torch.abs(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: class AsciiArt:
def __init__(self): def __init__(self):
pass pass
@@ -1051,7 +1057,7 @@ class PixelSort:
"mask": ("IMAGE",), "mask": ("IMAGE",),
"direction": (["horizontal", "vertical"],), "direction": (["horizontal", "vertical"],),
"span_limit": ("INT", { "span_limit": ("INT", {
"default": None, "default": 50,
"min": 0, "min": 0,
"max": 100, "max": 100,
"step": 5 "step": 5