Skip to content

Commit 7dfa597

Browse files
committed
makes SineWave directional
1 parent 01e0826 commit 7dfa597

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

post_processing/sine_wave.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def INPUT_TYPES(s):
1111
"required": {
1212
"image": ("IMAGE",),
1313
"amplitude": ("FLOAT", {
14-
"default": 50,
14+
"default": 10,
1515
"min": 0,
1616
"max": 150,
1717
"step": 5
@@ -22,6 +22,7 @@ def INPUT_TYPES(s):
2222
"max": 20,
2323
"step": 1
2424
}),
25+
"direction": (["horizontal", "vertical"],),
2526
},
2627
}
2728

@@ -30,24 +31,29 @@ def INPUT_TYPES(s):
3031

3132
CATEGORY = "postprocessing/Effects"
3233

33-
def apply_sine_wave(self, image: torch.Tensor, amplitude: float, frequency: float):
34+
def apply_sine_wave(self, image: torch.Tensor, amplitude: float, frequency: float, direction: str):
3435
batch_size, height, width, channels = image.shape
3536
result = torch.zeros_like(image)
3637

3738
for b in range(batch_size):
3839
tensor_image = image[b]
39-
result[b] = self.sine_wave_effect(tensor_image, amplitude, frequency)
40+
result[b] = self.sine_wave_effect(tensor_image, amplitude, frequency, direction)
4041

4142
return (result,)
4243

43-
def sine_wave_effect(self, image: torch.Tensor, amplitude: float, frequency: float):
44+
def sine_wave_effect(self, image: torch.Tensor, amplitude: float, frequency: float, direction: str):
4445
height, width, _ = image.shape
4546
shifted_image = torch.zeros_like(image)
4647

4748
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)
49+
if direction == "horizontal":
50+
for i in range(height):
51+
offset = int(amplitude * np.sin(2 * torch.pi * i * frequency / height))
52+
shifted_image[i, :, channel] = torch.roll(image[i, :, channel], offset)
53+
elif direction == "vertical":
54+
for j in range(width):
55+
offset = int(amplitude * np.sin(2 * torch.pi * j * frequency / width))
56+
shifted_image[:, j, channel] = torch.roll(image[:, j, channel], offset)
5157

5258
return shifted_image
5359

post_processing_nodes.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def INPUT_TYPES(s):
11581158
"required": {
11591159
"image": ("IMAGE",),
11601160
"amplitude": ("FLOAT", {
1161-
"default": 50,
1161+
"default": 10,
11621162
"min": 0,
11631163
"max": 150,
11641164
"step": 5
@@ -1169,6 +1169,7 @@ def INPUT_TYPES(s):
11691169
"max": 20,
11701170
"step": 1
11711171
}),
1172+
"direction": (["horizontal", "vertical"],),
11721173
},
11731174
}
11741175

@@ -1177,24 +1178,29 @@ def INPUT_TYPES(s):
11771178

11781179
CATEGORY = "postprocessing/Effects"
11791180

1180-
def apply_sine_wave(self, image: torch.Tensor, amplitude: float, frequency: float):
1181+
def apply_sine_wave(self, image: torch.Tensor, amplitude: float, frequency: float, direction: str):
11811182
batch_size, height, width, channels = image.shape
11821183
result = torch.zeros_like(image)
11831184

11841185
for b in range(batch_size):
11851186
tensor_image = image[b]
1186-
result[b] = self.sine_wave_effect(tensor_image, amplitude, frequency)
1187+
result[b] = self.sine_wave_effect(tensor_image, amplitude, frequency, direction)
11871188

11881189
return (result,)
11891190

1190-
def sine_wave_effect(self, image: torch.Tensor, amplitude: float, frequency: float):
1191+
def sine_wave_effect(self, image: torch.Tensor, amplitude: float, frequency: float, direction: str):
11911192
height, width, _ = image.shape
11921193
shifted_image = torch.zeros_like(image)
11931194

11941195
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)
1196+
if direction == "horizontal":
1197+
for i in range(height):
1198+
offset = int(amplitude * np.sin(2 * torch.pi * i * frequency / height))
1199+
shifted_image[i, :, channel] = torch.roll(image[i, :, channel], offset)
1200+
elif direction == "vertical":
1201+
for j in range(width):
1202+
offset = int(amplitude * np.sin(2 * torch.pi * j * frequency / width))
1203+
shifted_image[:, j, channel] = torch.roll(image[:, j, channel], offset)
11981204

11991205
return shifted_image
12001206

0 commit comments

Comments
 (0)