#!/usr/bin/env python # coding: utf-8 # ![](cat-crisp.webp) # # # Blurry # # Kevin Walchko # # --- # ``` # In[2]: # reload library get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') # In[3]: import numpy as np import cv2 from matplotlib import pyplot as plt np.set_printoptions(precision=3) np.set_printoptions(suppress=True) # In[4]: def blurry(image, threshold=100.0): """ Given an image and threshold, returns if image is blurry and its value Args: image: opencv grayscale image threshold: blur threshold value, below this value an image is considered to be blurry Return: blurry: True/False value: numeric value of blurriness Reference: https://pyimagesearch.com/2015/09/07/blur-detection-with-opencv/ """ val = cv2.Laplacian(image, cv2.CV_64F).var() val = int(val) if val < threshold: return True, val return False, val # In[5]: cat = cv2.imread("cat-blurry.webp",0) plt.imshow(cat, cmap="gray") plt.axis("off") plt.title(f"Blurry: {blurry(cat, 300)}"); # In[6]: cat = cv2.imread("cat-crisp.webp",0) plt.imshow(cat, cmap="gray") plt.axis("off") plt.title(f"Blurry: {blurry(cat, 300)}"); # In[ ]: # In[ ]: # In[ ]: # In[ ]: