Created
January 8, 2019 12:51
-
-
Save kylecorry31/56849940ca59568b17041e694f271276 to your computer and use it in GitHub Desktop.
A python script to blur images
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 cv2 | |
import sys | |
import numpy as np | |
BLUR_LOW = 20 | |
BLUR_MED = 50 | |
BLUR_HIGH = 100 | |
def adjust_gamma(image, gamma=1.0): | |
# from: https://www.pyimagesearch.com/2015/10/05/opencv-gamma-correction/ | |
invGamma = 1.0 / gamma | |
table = np.array([((i / 255.0) ** invGamma) * 255 | |
for i in np.arange(0, 256)]).astype("uint8") | |
return cv2.LUT(image, table) | |
if __name__ == '__main__': | |
# Arguments: image_filename, output_filename | |
if len(sys.argv) != 3: | |
print("Usage: python3 blur.py image_filename output_filename") | |
exit(1) | |
image_filename = sys.argv[1] | |
output_filename = sys.argv[2] | |
blur_level = BLUR_MED | |
# Read image | |
img = cv2.imread(image_filename) | |
# Apply blur to image | |
blur = cv2.GaussianBlur(img, (blur_level + 1, 0), sigmaX=blur_level, sigmaY=blur_level) | |
blur = cv2.GaussianBlur(blur, (0, blur_level + 1), sigmaX=blur_level, sigmaY=blur_level) | |
# Increase brightness | |
blur = adjust_gamma(blur, 1.5) | |
# Save image | |
cv2.imwrite(output_filename, blur) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment