High Pass Settings output as DICT

This commit is contained in:
Rafał Tłuchowski
2025-01-27 22:55:25 +01:00
parent 8f82c89bd3
commit a9d28dc723
+58 -15
View File
@@ -3,10 +3,8 @@ import numpy as np
import cv2
from torch import Tensor
from core.image_processor import ImageProcessor
class HighPassFilter:
"""ComfyUI node implementing AE-style high-pass filter with dynamic histogram visualization"""
@@ -15,24 +13,56 @@ class HighPassFilter:
return {
"required": {
"image": ("IMAGE",),
"blur_radius": ("INT", {"default": 2, "min": 1, "max": 20, "step": 1}),
"blur_iterations": ("INT", {"default": 6, "min": 1, "max": 20, "step": 1}),
"blend_opacity": ("FLOAT", {"default": 0.5, "min": 0.45, "max": 0.55, "step": 0.01}),
"input_black": ("INT", {"default": 117, "min": 0, "max": 255, "step": 1}),
"input_white": ("INT", {"default": 137, "min": 0, "max": 255, "step": 1}),
"gamma": ("FLOAT", {"default": 0, "min": 0.5, "max": 2, "step": 0.01}),
"show_histogram": ("BOOLEAN", {"default": False}),
"blur_radius": ("INT", {
"default": 2,
"min": 1,
"max": 20,
"step": 1
}),
"blur_iterations": ("INT", {
"default": 6,
"min": 1,
"max": 20,
"step": 1
}),
"blend_opacity": ("FLOAT", {
"default": 0.5,
"min": 0.45,
"max": 0.55,
"step": 0.01
}),
"input_black": ("INT", {
"default": 117,
"min": 0,
"max": 255,
"step": 1
}),
"input_white": ("INT", {
"default": 137,
"min": 0,
"max": 255,
"step": 1
}),
"gamma": ("FLOAT", {
"default": 0,
"min": 0.5,
"max": 2,
"step": 0.01
}),
"show_histogram": ("BOOLEAN", {
"default": False
}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
RETURN_TYPES = ("IMAGE", "DICT")
RETURN_NAMES = ("image", "HPF Settings")
FUNCTION = "apply_hpf"
CATEGORY = "Face Processor/Filters"
CATEGORY = "Face Processor/Tools"
def apply_hpf(self, image: torch.Tensor, blur_radius: int, blur_iterations: int,
blend_opacity: float, input_black: int, input_white: int,
gamma: float, show_histogram: bool) -> tuple[Tensor]:
gamma: float, show_histogram: bool) -> tuple[Tensor, dict]:
"""Main processing function implementing the High Pass Filter"""
# Convert tensor to numpy array
np_img = image[0].numpy() * 255
@@ -55,7 +85,7 @@ class HighPassFilter:
in_black = np.clip(input_black, 0, 255)
in_white = np.clip(input_white, in_black + 1, 255)
levels = np.clip((composite.astype(np.float32) - in_black) / (in_white - in_black), 0, 1)
levels = np.power(levels, 1.0 / gamma)
levels = np.power(levels, 1.0 / gamma) if gamma > 0 else levels
result = (levels * 255).astype(np.uint8)
# Add histogram visualization if enabled
@@ -68,4 +98,17 @@ class HighPassFilter:
# Convert back to tensor format
result = torch.from_numpy(result.astype(np.float32) / 255.0).unsqueeze(0)
return (result,)
# Prepare settings dictionary
settings = {
"high_pass_filter": {
"blur_radius": blur_radius,
"blur_iterations": blur_iterations,
"blend_opacity": blend_opacity,
"input_black": input_black,
"input_white": input_white,
"gamma": gamma,
"show_histogram": show_histogram
}
}
return result, settings