@@ -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