Skip to content

Commit 01e0826

Browse files
committed
Adds SineWave Effect
1 parent 76be38e commit 01e0826

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Both images have the workflow attached, and are included with the repo. Feel fre
3737
- Pixelize: Applies a pixelization effect, simulating the reducing of resolution
3838
- $\color{#00A7B5}\textbf{Quantize:}$ Set and dither the amount of colors in an image from 0-256, reducing color information
3939
- Sharpen: Enhances the details in an image by applying a sharpening filter
40+
- SineWave: Runs a sine wave through the image, making it appear squiggly
4041
- $\color{#00A7B5}\textbf{Solarize:}$ Inverts image colors based on a threshold for a striking, high-contrast effect
4142
- Vignette: Applies a vignette effect, putting the corners of the image in shadow
4243

post_processing/kuwahara_blur.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import cv2
22
import numpy as np
3-
import multiprocessing as mp
43
import torch
54

65
class KuwaharaBlur:

post_processing/sine_wave.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import torch
2+
import numpy as np
3+
4+
class SineWave:
5+
def __init__(self):
6+
pass
7+
8+
@classmethod
9+
def INPUT_TYPES(s):
10+
return {
11+
"required": {
12+
"image": ("IMAGE",),
13+
"amplitude": ("FLOAT", {
14+
"default": 50,
15+
"min": 0,
16+
"max": 150,
17+
"step": 5
18+
}),
19+
"frequency": ("FLOAT", {
20+
"default": 5,
21+
"min": 0,
22+
"max": 20,
23+
"step": 1
24+
}),
25+
},
26+
}
27+
28+
RETURN_TYPES = ("IMAGE",)
29+
FUNCTION = "apply_sine_wave"
30+
31+
CATEGORY = "postprocessing/Effects"
32+
33+
def apply_sine_wave(self, image: torch.Tensor, amplitude: float, frequency: float):
34+
batch_size, height, width, channels = image.shape
35+
result = torch.zeros_like(image)
36+
37+
for b in range(batch_size):
38+
tensor_image = image[b]
39+
result[b] = self.sine_wave_effect(tensor_image, amplitude, frequency)
40+
41+
return (result,)
42+
43+
def sine_wave_effect(self, image: torch.Tensor, amplitude: float, frequency: float):
44+
height, width, _ = image.shape
45+
shifted_image = torch.zeros_like(image)
46+
47+
for channel in range(3):
48+
for i in range(height):
49+
offset = int(amplitude * np.sin(2 * torch.pi * i * frequency / height))
50+
shifted_image[i, :, channel] = torch.roll(image[i, :, channel], offset)
51+
52+
return shifted_image
53+
54+
NODE_CLASS_MAPPINGS = {
55+
"SineWave": SineWave,
56+
}

post_processing_nodes.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import cv2
44
import numpy as np
55
from PIL import Image, ImageEnhance
6-
import multiprocessing as mp
76
from PIL import Image
87

98

@@ -1149,6 +1148,56 @@ def sharpen(self, image: torch.Tensor, blur_radius: int, alpha: float):
11491148

11501149
return (result,)
11511150

1151+
class SineWave:
1152+
def __init__(self):
1153+
pass
1154+
1155+
@classmethod
1156+
def INPUT_TYPES(s):
1157+
return {
1158+
"required": {
1159+
"image": ("IMAGE",),
1160+
"amplitude": ("FLOAT", {
1161+
"default": 50,
1162+
"min": 0,
1163+
"max": 150,
1164+
"step": 5
1165+
}),
1166+
"frequency": ("FLOAT", {
1167+
"default": 5,
1168+
"min": 0,
1169+
"max": 20,
1170+
"step": 1
1171+
}),
1172+
},
1173+
}
1174+
1175+
RETURN_TYPES = ("IMAGE",)
1176+
FUNCTION = "apply_sine_wave"
1177+
1178+
CATEGORY = "postprocessing/Effects"
1179+
1180+
def apply_sine_wave(self, image: torch.Tensor, amplitude: float, frequency: float):
1181+
batch_size, height, width, channels = image.shape
1182+
result = torch.zeros_like(image)
1183+
1184+
for b in range(batch_size):
1185+
tensor_image = image[b]
1186+
result[b] = self.sine_wave_effect(tensor_image, amplitude, frequency)
1187+
1188+
return (result,)
1189+
1190+
def sine_wave_effect(self, image: torch.Tensor, amplitude: float, frequency: float):
1191+
height, width, _ = image.shape
1192+
shifted_image = torch.zeros_like(image)
1193+
1194+
for channel in range(3):
1195+
for i in range(height):
1196+
offset = int(amplitude * np.sin(2 * torch.pi * i * frequency / height))
1197+
shifted_image[i, :, channel] = torch.roll(image[i, :, channel], offset)
1198+
1199+
return shifted_image
1200+
11521201
class Solarize:
11531202
def __init__(self):
11541203
pass
@@ -1335,6 +1384,7 @@ def pixel_sort(img, mask, horizontal_sort=False, span_limit=None, sort_by='H', r
13351384
"Pixelize": Pixelize,
13361385
"Quantize": Quantize,
13371386
"Sharpen": Sharpen,
1387+
"SineWave": SineWave,
13381388
"Solarize": Solarize,
13391389
"Vignette": Vignette,
13401390
}

0 commit comments

Comments
 (0)