Create distort.py
Browse files- distort.py +15 -0
distort.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import cv2
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
def apply_wave_effect(pil_img):
|
6 |
+
img = np.array(pil_img)
|
7 |
+
rows, cols = img.shape[:2]
|
8 |
+
|
9 |
+
map_y, map_x = np.indices((rows, cols), dtype=np.float32)
|
10 |
+
wave = 15.0 * np.sin(map_x / 50.0) # You can adjust wave strength and frequency
|
11 |
+
map_y += wave
|
12 |
+
|
13 |
+
distorted = cv2.remap(img, map_x, map_y, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT)
|
14 |
+
|
15 |
+
return Image.fromarray(distorted)
|