The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Detect image blurriness

To detect image blurriness, you can use the Laplacian Variance method. It’s a simple and effective way to measure the sharpness of an image. Here’s a Python example using OpenCV:

Python Code to Detect Image Blurriness

python
import cv2 def is_blurry(image_path, threshold=100.0): image = cv2.imread(image_path) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) laplacian_var = cv2.Laplacian(gray, cv2.CV_64F).var() print(f"Laplacian Variance: {laplacian_var}") if laplacian_var < threshold: print("Image is blurry.") return True else: print("Image is sharp.") return False # Example usage is_blurry("your_image.jpg")

Explanation

  • Laplacian detects edges. A sharper image has more edges, leading to a higher variance.

  • If the variance is low, the image has fewer edges → it’s likely blurry.

  • You can tune the threshold based on your image dataset (commonly between 50–150).

Let me know if you want a version using PIL, TensorFlow, or if you want to upload and check an image here.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About