Created
June 14, 2024 15:09
-
-
Save Coderx7/1e735aaca44d91273fc45dcf7ce5b3b7 to your computer and use it in GitHub Desktop.
edgetaper implementation in numpy/opencv
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
# this is a python reimplementation of edgetaper introduced here: https://docs.opencv.org/4.x/d1/dfd/tutorial_motion_deblur_filter.html | |
def edgetaper(img, gamma=5, beta=0.2): | |
width,height = img.shape[:2] | |
dx = 2 * np.pi / width | |
dy = 2 * np.pi / height | |
# subtract dx and dy to match original function's range | |
x = np.linspace(-np.pi, np.pi-dx, width) | |
y = np.linspace(-np.pi, np.pi-dy, height) | |
w1 = 0.5 * (np.tanh((x + gamma / 2) / beta) - np.tanh((x - gamma / 2) / beta)) | |
w2 = 0.5 * (np.tanh((y + gamma / 2) / beta) - np.tanh((y - gamma / 2) / beta)) | |
w = np.dot(w2.reshape(-1, 1), w1.reshape(1, -1)) | |
if img.ndim>2: | |
w = w[:, :, np.newaxis].repeat(img.shape[2], axis=2) | |
return cv2.multiply(img.astype(np.float32), w.astype(np.float32)).clip(0,255).astype(np.uint8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment