-
-
Save musaprg/9bbd6cf6fac4d9f90bc97efe3d3f893a to your computer and use it in GitHub Desktop.
mis1yakudo
This file contains 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 numpy as np | |
import cv2 | |
orig = cv2.imread('src.png').astype(np.float32) | |
width, height, _ = orig.shape | |
center_x, center_y = width/4, height/2 | |
blur, iterations = 0.008, 20 | |
map_x1 = np.fromfunction(lambda y, x: x, (width, height), dtype=np.float32) | |
map_y1 = np.fromfunction(lambda y, x: y, (width, height), dtype=np.float32) | |
map_x2 = np.fromfunction(lambda y, x: (x - center_x) * blur, (width, height), dtype=np.float32) | |
map_y2 = np.fromfunction(lambda y, x: (y - center_y) * blur, (width, height), dtype=np.float32) | |
dst = np.copy(orig) | |
for i in range(iterations): | |
enlarged = cv2.remap(dst, map_x1 + map_x2, map_y1 + map_y2, cv2.INTER_LINEAR) | |
shrinked = cv2.remap(dst, map_x1 - map_x2, map_y1 - map_y2, cv2.INTER_LINEAR) | |
dst = cv2.addWeighted(enlarged, 0.5, shrinked, 0.5, 0, dst) | |
cv2.imwrite('dst.png', dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment