Skip to content

Instantly share code, notes, and snippets.

@robgon-art
Created January 8, 2022 20:27
Show Gist options
  • Save robgon-art/d39731f69a355a93536e856dc2f82e01 to your computer and use it in GitHub Desktop.
Save robgon-art/d39731f69a355a93536e856dc2f82e01 to your computer and use it in GitHub Desktop.
import cv2
amount = 1.0
img = Image.open("input_image.png")
image_np = np.array(img, dtype = np.float32)
gaussian = cv2.GaussianBlur(image_np, (0, 0), 1.0)
unsharp_image = cv2.addWeighted(image_np, 2.0, gaussian, -1.0, 0)
unsharp_image = amount * unsharp_image + (1.0 - amount) * image_np
image_int = unsharp_image.round().clip(0, 255).astype(np.uint8)
image_pil = Image.fromarray(image_int)
image_pil.save("output_image.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment