Created
October 10, 2022 20:43
-
-
Save melisagozet/5b004102914c86c2495f57946d0e66a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import math | |
img = cv2.imread("/content/gdrive/My Drive/cr7.jpg") | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
rows, cols = img.shape | |
##################### | |
# Vertical wave | |
img_output = np.zeros(img.shape, dtype=img.dtype) | |
for i in range(rows): | |
for j in range(cols): | |
offset_x = int(25.0 * math.sin(2 * 3.14 * i / 180)) | |
offset_y = 0 | |
if j+offset_x < rows: | |
img_output[i,j] = img[i,(j+offset_x)%cols] | |
else: | |
img_output[i,j] = 0 | |
cv2_imshow(img) | |
cv2_imshow(img_output) | |
##################### | |
# Horizontal wave | |
img_output = np.zeros(img.shape, dtype=img.dtype) | |
for i in range(rows): | |
for j in range(cols): | |
offset_x = 0 | |
offset_y = int(16.0 * math.sin(2 * 3.14 * j / 150)) | |
if i+offset_y < rows: | |
img_output[i,j] = img[(i+offset_y)%rows,j] | |
else: | |
img_output[i,j] = 0 | |
cv2_imshow(img_output) | |
##################### | |
# Both horizontal and vertical | |
img_output = np.zeros(img.shape, dtype=img.dtype) | |
for i in range(rows): | |
for j in range(cols): | |
offset_x = int(20.0 * math.sin(2 * 3.14 * i / 150)) | |
offset_y = int(20.0 * math.cos(2 * 3.14 * j / 150)) | |
if i+offset_y < rows and j+offset_x < cols: | |
img_output[i,j] = img[(i+offset_y)%rows,(j+offset_x)%cols] | |
else: | |
img_output[i,j] = 0 | |
cv2_imshow(img_output) | |
##################### | |
# Concave effect | |
img_output = np.zeros(img.shape, dtype=img.dtype) | |
for i in range(rows): | |
for j in range(cols): | |
offset_x = int(128.0 * math.sin(2 * 3.14 * i / (2*cols))) | |
offset_y = 0 | |
if j+offset_x < cols: | |
img_output[i,j] = img[i,(j+offset_x)%cols] | |
else: | |
img_output[i,j] = 0 | |
cv2_imshow(img_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment