Skip to content

Instantly share code, notes, and snippets.

@8q
Created June 25, 2018 15:08
Show Gist options
  • Save 8q/2d332f8258cb085a23f2925950980618 to your computer and use it in GitHub Desktop.
Save 8q/2d332f8258cb085a23f2925950980618 to your computer and use it in GitHub Desktop.
mis1yakudo
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