Adds HSV Threshold Mask
actually update examples as well
This commit is contained in:
@@ -21,14 +21,15 @@ Both images have the workflow attached, and are included with the repo. Feel fre
|
||||
- ArithmeticBlend: Blends two images using arithmetic operations like addition, subtraction, and difference.
|
||||
- Blend: Blends two images together with a variety of different modes
|
||||
- Blur: Applies a Gaussian blur to the input image, softening the details
|
||||
- CannyEdgeDetection: Applies Canny edge detection to the input image
|
||||
- CannyEdgeMask: Creates a mask using canny edge detection
|
||||
- Chromatic Aberration: Shifts the color channels in an image, creating a glitch aesthetic
|
||||
- $\color{#00A7B5}\textbf{ColorCorrect:}$ Adjusts the color balance, temperature, hue, brightness, contrast, saturation, and gamma of an image
|
||||
- $\color{#00A7B5}\textbf{ColorTint:}$ Applies a customizable tint to the input image, with various color modes such as sepia, RGB, CMY and several composite colors
|
||||
- Dissolve: Creates a grainy blend of two images using random pixels based on a dissolve factor.
|
||||
- DodgeAndBurn: Adjusts image brightness using dodge and burn effects based on a mask and intensity.
|
||||
- FilmGrain: Adds a film grain effect to the image, along with options to control the temperature, and vignetting
|
||||
- FilmGrain: Adds a film grain effect to the image, along with options to control the temperature, and vignetting.
|
||||
- Glow: Applies a blur with a specified radius and then blends it with the original image. Creates a nice glowing effect.
|
||||
- HSVThresholdMask: Creates a mask by thresholding HSV (hue, saturation, and value) channels
|
||||
- $\color{#00A7B5}\textbf{KuwaharaBlur:}$ Applies an edge preserving blur, creating a more realistic blur than Gaussian.
|
||||
- Parabolize: Applies a color transformation effect using a parabolic formula
|
||||
- PencilSketch: Converts an image into a hand-drawn pencil sketch style.
|
||||
|
||||
+2
-1
@@ -3,12 +3,13 @@ from pathlib import Path
|
||||
import argparse
|
||||
|
||||
ignore_dirs = ["old"]
|
||||
ignore_files = ["__init__.py", "combine_files.py", "test.py"]
|
||||
|
||||
def get_python_files(path, recursive=False, args=None):
|
||||
search_pattern = "**/*.py" if recursive else "*.py"
|
||||
|
||||
def should_include(file):
|
||||
if file.is_file() and not file.name.startswith("combine") and not args.output in str(file) and not file.name.startswith("__init__"):
|
||||
if file.is_file() and not args.output in str(file) and not file.name in ignore_files:
|
||||
for ignore_dir in ignore_dirs:
|
||||
if ignore_dir in str(file.parent):
|
||||
return False
|
||||
|
||||
+464
-422
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 436 KiB After Width: | Height: | Size: 370 KiB |
@@ -3,7 +3,7 @@ import numpy as np
|
||||
import torch
|
||||
|
||||
|
||||
class CannyEdgeDetection:
|
||||
class CannyEdgeMask:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@@ -46,5 +46,5 @@ class CannyEdgeDetection:
|
||||
return (result,)
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"CannyEdgeDetection": CannyEdgeDetection
|
||||
"CannyEdgeMask": CannyEdgeMask
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import cv2
|
||||
import torch
|
||||
import numpy as np
|
||||
|
||||
class HSVThresholdMask:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"image": ("IMAGE",),
|
||||
"low_threshold": ("FLOAT", {
|
||||
"default": 0.2,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.1
|
||||
}),
|
||||
"high_threshold": ("FLOAT", {
|
||||
"default": 0.7,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.1
|
||||
}),
|
||||
"hsv_channel": (["hue", "saturation", "value"],),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "hsv_threshold"
|
||||
|
||||
CATEGORY = "postprocessing/Masks"
|
||||
|
||||
def hsv_threshold(self, image: torch.Tensor, low_threshold: float, high_threshold: float, hsv_channel: str):
|
||||
batch_size, height, width, _ = image.shape
|
||||
result = torch.zeros(batch_size, height, width)
|
||||
|
||||
if hsv_channel == "hue":
|
||||
channel = 0
|
||||
low_threshold, high_threshold = int(low_threshold * 180), int(high_threshold * 180)
|
||||
elif hsv_channel == "saturation":
|
||||
channel = 1
|
||||
low_threshold, high_threshold = int(low_threshold * 255), int(high_threshold * 255)
|
||||
elif hsv_channel == "value":
|
||||
channel = 2
|
||||
low_threshold, high_threshold = int(low_threshold * 255), int(high_threshold * 255)
|
||||
|
||||
for b in range(batch_size):
|
||||
tensor_image = (image[b].numpy().copy() * 255).astype(np.uint8)
|
||||
hsv_image = cv2.cvtColor(tensor_image, cv2.COLOR_RGB2HSV)
|
||||
|
||||
mask = cv2.inRange(hsv_image[:, :, channel], low_threshold, high_threshold)
|
||||
tensor = torch.from_numpy(mask).float() / 255.
|
||||
result[b] = tensor
|
||||
|
||||
return (result,)
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"HSVThresholdMask": HSVThresholdMask,
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class Blur:
|
||||
|
||||
return (blurred,)
|
||||
|
||||
class CannyEdgeDetection:
|
||||
class CannyEdgeMask:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@@ -717,6 +717,60 @@ class Glow:
|
||||
def add_glow(self, img, blurred_img, intensity):
|
||||
return img + blurred_img * intensity
|
||||
|
||||
class HSVThresholdMask:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"image": ("IMAGE",),
|
||||
"low_threshold": ("FLOAT", {
|
||||
"default": 0.2,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.1
|
||||
}),
|
||||
"high_threshold": ("FLOAT", {
|
||||
"default": 0.7,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.1
|
||||
}),
|
||||
"hsv_channel": (["hue", "saturation", "value"],),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "hsv_threshold"
|
||||
|
||||
CATEGORY = "postprocessing/Masks"
|
||||
|
||||
def hsv_threshold(self, image: torch.Tensor, low_threshold: float, high_threshold: float, hsv_channel: str):
|
||||
batch_size, height, width, _ = image.shape
|
||||
result = torch.zeros(batch_size, height, width)
|
||||
|
||||
if hsv_channel == "hue":
|
||||
channel = 0
|
||||
low_threshold, high_threshold = int(low_threshold * 180), int(high_threshold * 180)
|
||||
elif hsv_channel == "saturation":
|
||||
channel = 1
|
||||
low_threshold, high_threshold = int(low_threshold * 255), int(high_threshold * 255)
|
||||
elif hsv_channel == "value":
|
||||
channel = 2
|
||||
low_threshold, high_threshold = int(low_threshold * 255), int(high_threshold * 255)
|
||||
|
||||
for b in range(batch_size):
|
||||
tensor_image = (image[b].numpy().copy() * 255).astype(np.uint8)
|
||||
hsv_image = cv2.cvtColor(tensor_image, cv2.COLOR_RGB2HSV)
|
||||
|
||||
mask = cv2.inRange(hsv_image[:, :, channel], low_threshold, high_threshold)
|
||||
tensor = torch.from_numpy(mask).float() / 255.
|
||||
result[b] = tensor
|
||||
|
||||
return (result,)
|
||||
|
||||
class KuwaharaBlur:
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -1265,7 +1319,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ArithmeticBlend": ArithmeticBlend,
|
||||
"Blend": Blend,
|
||||
"Blur": Blur,
|
||||
"CannyEdgeDetection": CannyEdgeDetection,
|
||||
"CannyEdgeMask": CannyEdgeMask,
|
||||
"ChromaticAberration": ChromaticAberration,
|
||||
"ColorCorrect": ColorCorrect,
|
||||
"ColorTint": ColorTint,
|
||||
@@ -1273,6 +1327,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"DodgeAndBurn": DodgeAndBurn,
|
||||
"FilmGrain": FilmGrain,
|
||||
"Glow": Glow,
|
||||
"HSVThresholdMask": HSVThresholdMask,
|
||||
"KuwaharaBlur": KuwaharaBlur,
|
||||
"Parabolize": Parabolize,
|
||||
"PencilSketch": PencilSketch,
|
||||
|
||||
Reference in New Issue
Block a user