4
$\begingroup$

I'm writing a script to detect blur images using OpenCV by applying Laplacian filter and calculate the std but there is a problem the std for images that contain motion blur is very close to those images which contain any other type of blur. (my propose is to find detect unsuitable images that can't detect the object on it like a dog image that contain motion blur for example)

blurry image

I used this piece of code cv2.Laplacian(image, cv2.CV_64F, ksize=3 ).std() to find the blur ratio and make a threshold for std < 40 is considered a blurry image so I want a method to can differentiate between images that contain motion blur images and other kinds of blur

$\endgroup$
2
  • $\begingroup$ oops, you just removed my edit that fixed the image: the Image url is https://i.imgur.com/cGxuLQK.jpg, not https://imgur.com/cGxuLQK like you used. $\endgroup$ Aug 2, 2018 at 11:52
  • $\begingroup$ @MarcusMüller sorry I removed it by mistake I will edit it, thank you :) $\endgroup$ Aug 2, 2018 at 11:53

2 Answers 2

1
$\begingroup$

Instead of filtering with a symmetric gaussian, which is a blurry kernel in every direction, just filter with two 1D-kernels:

One in x direction (a row vector kernel, if you will), and one in y direction (column vector).

If the "blurriness" in both directions is the same, generally blurry. If it's much higher in one direction than in the other: motion blur.

You'll have to adjust your thresholds for "blurriness" to also accomodate diagonal motion blur.

$\endgroup$
4
  • $\begingroup$ that's a good idea, Do you have any idea how can I apply this in OpenCV? $\endgroup$ Aug 2, 2018 at 12:29
  • $\begingroup$ Simply use the center column and center row of your 2D kernel! $\endgroup$ Aug 2, 2018 at 13:22
  • $\begingroup$ python/openCV implementation: def motion_blur(image, filter_length): h_v = np.ones((filter_length, 1)) / filter_length # create blurred images b_ver = cv2.filter2D(image, ddepth=-1, kernel=h_v) b_hor = cv2.filter2D(image, ddepth=-1, kernel=h_v.T) # T for transpose return b_ver, b_hor $\endgroup$ Jun 29 at 20:20
  • $\begingroup$ incidentally, this paper (pdf link) describes a handy algorithm that detects different types of blur pretty effectively $\endgroup$ Jun 29 at 20:22
2
$\begingroup$

You can use the following variance of Laplacian responses:

cv2.Laplacian(gray_image, cv2.CV_64F).var()

More details at https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/

$\endgroup$
1
  • $\begingroup$ this is just the square of the method that OP have said doesn't work well for motion blur (and I can confirm)—neither work really well for motion blur $\endgroup$ Jun 29 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.