add more AQnodes

This commit is contained in:
pk
2025-06-08 09:40:05 +02:00
parent e443ae17a0
commit 1655b8d475
+70 -1
View File
@@ -1,5 +1,5 @@
import torch
import cv2
class AQ_BatchAverageImage:
@classmethod
@@ -82,6 +82,75 @@ class AQ_ColorMatchImage:
t[i, :, :, c] /= blurred[i, :, :, c]
t[i, :, :, c] *= blurred_ref[i, :, :, c]
t = t - 0.1
torch.clamp(torch.lerp(images, t, factor), 0, 1)
return (t,)
# guided filter a tensor image batch in format [B x H x W x C] on H/W (spatial, per-image, per-channel)
def guided_filter_tensor(ref, images, d, s):
try:
from cv2.ximgproc import guidedFilter
except ImportError:
print("\033[33mUnable to import guidedFilter, make sure you have only opencv-contrib-python or run the import_error_install.bat script\033[m")
if d > 100:
np_img = (
torch.nn.functional.interpolate(
images.detach().clone().movedim(-1, 1),
scale_factor=0.1,
mode="bilinear",
)
.movedim(1, -1)
.cpu()
.numpy()
)
np_ref = (
torch.nn.functional.interpolate(
ref.detach().clone().movedim(-1, 1), scale_factor=0.1, mode="bilinear"
)
.movedim(1, -1)
.cpu()
.numpy()
)
for index, image in enumerate(np_img):
np_img[index] = guidedFilter(np_ref[index], image, d // 20 * 2 + 1, s)
return torch.nn.functional.interpolate(
torch.from_numpy(np_img).movedim(-1, 1),
size=(images.shape[1], images.shape[2]),
mode="bilinear",
).movedim(1, -1)
else:
np_img = images.detach().clone().cpu().numpy()
np_ref = ref.cpu().numpy()
for index, image in enumerate(np_img):
np_img[index] = guidedFilter(np_ref[index], image, d, s)
return torch.from_numpy(np_img)
# gaussian blur a tensor image batch in format [B x H x W x C] on H/W (spatial, per-image, per-channel)
def cv_blur_tensor(images, dx, dy):
if min(dx, dy) > 100:
np_img = (
torch.nn.functional.interpolate(
images.detach().clone().movedim(-1, 1),
scale_factor=0.1,
mode="bilinear",
)
.movedim(1, -1)
.cpu()
.numpy()
)
for index, image in enumerate(np_img):
np_img[index] = cv2.GaussianBlur(
image, (dx // 20 * 2 + 1, dy // 20 * 2 + 1), 0
)
return torch.nn.functional.interpolate(
torch.from_numpy(np_img).movedim(-1, 1),
size=(images.shape[1], images.shape[2]),
mode="bilinear",
).movedim(1, -1)
else:
np_img = images.detach().clone().cpu().numpy()
for index, image in enumerate(np_img):
np_img[index] = cv2.GaussianBlur(image, (dx, dy), 0)
return torch.from_numpy(np_img)