Files
MdONeilsl b6a2d1dd79 Add MD Color Mod nodes, operators, and web UI
Introduce a complete GIMP/GEGL-inspired color module for ComfyUI. Adds: node declarations (nodes/*) and matching operator implementations (py/*) for many color/image operations (balance, temperature, hue/chroma, hue/saturation, saturation, exposure, levels, invert, auto adjustments, maps, posterize, desaturate, tone mapping, component extract/mix, etc.). Includes support libs (py/libs: color, process, blur), layer compositing (layers_blending), VRAM‑aware chunking, mask handling and alpha preservation. Adds web UI extension and widgets (web/*), package metadata, dynamic __init__.py loader, README update and .gitignore tweaks.
2026-07-06 08:17:05 -04:00

34 lines
670 B
Python

import torch
import torch.nn.functional as F
def gaussian_blur_2d(x, radius: float):
if radius <= 0:
return x
sigma = radius * 0.5
k = int(max(3, radius * 2 + 1))
if k % 2 == 0:
k += 1
device = x.device
coords = torch.arange(k, device=device) - k // 2
g = torch.exp(-(coords ** 2) / (2 * sigma ** 2))
g = g / g.sum()
# reshape for separable conv
g_h = g.view(1, 1, 1, k)
g_v = g.view(1, 1, k, 1)
x = x.unsqueeze(1) # [B,1,H,W]
# IMPORTANT: symmetric SAME padding
pad = k // 2
x = F.conv2d(x, g_h, padding=(0, pad))
x = F.conv2d(x, g_v, padding=(pad, 0))
return x.squeeze(1)