Python - Detect blank images with shifting gradient

Viewed 47

I'm working on a project which requires me to detect blank images. What I've tried until now is converting the image to grayscale and finding its standard deviation and considering the image to be empty if the standard deviation is very low:

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
mean, std = cv2.meanStdDev(gray)

This works pretty well for completely blank images with a single colour, but when I try this solution on images with shifting gradients like these it fails, as the returned standard deviation is quite high: failed

All these images were taken from mobile phone camera, while covering the lens/flash area. Basically my goal is to detect any blank images(with no meaningful content) uploaded by the user, clicked using their mobile camera.

Original images can be found here

Any idea fellow stackers how can this be acheived in python? P.S. I'm not constrained to using any specific library. Solutions using any libraries are welcome

1 Answers

You are calculating the statistics (mean and standard deviation) based on the raw pixel values (intensities). You should rather calculate the same using the gradient information.

In the following I used the Laplacian operator on a collection of images and obtained their respective statistics:

laplacian = cv2.Laplacian(img, cv2.CV_64F)
mean, std_dev = cv2.meanStdDev(laplacian)
print(mean, std_dev)

Results:

The following are the results for 7 images:

The first 4 are results for the images you shared in the link. The last 3 are results for random images of people.

[[0.00200908]] [[5.31579802]]
[[0.0418591]] [[8.73851055]]
[[-0.0018069]] [[5.98184714]]
[[0.00585382]] [[13.22255413]]
[[0.02172097]] [[81.46064779]]
[[-0.0261699]] [[68.17072845]]
[[0.03771607]] [[53.9026758]]

Conclusion:

The standard deviation of the images containing random people are much higher than the gradient images shared by you. You can use this observation as leverage.

Related