Simple way to check if an image bitmap is blur
来源:互联网 发布:餐饮软件考试指定 编辑:程序博客网 时间:2024/05/16 06:44
I am looking for a "very" simple way to check if an image bitmap is blur. I do not need accurate and complicate algorithm which involves fft, wavelet, etc. Just a very simple idea even if it is not accurate.
I've thought to compute the average euclidian distance between pixel (x,y) and pixel (x+1,y) considering their RGB components and then using a threshold but it works very bad. Any other idea?
3 Answers
Don't calculate the average differences between adjacent pixels.
Even when a photograph is perfectly in focus, it can still contain large areas of uniform colour, like the sky for example. These will push down the average difference and mask the details you're interested in. What you really want to find is themaximum difference value.
Also, to speed things up, I wouldn't bother checking every pixel in the image. You should get reasonable results by checking along a grid of horizontal and vertical lines spaced, say, 10 pixels apart.
Here are the results of some tests with PHP's GD graphics functions using an image from Wikimedia Commons (Bokeh_Ipomea.jpg). TheSharpness
values are simply the maximum pixel difference values as a percentage of 255 (I only looked in the green channel; you should probably convert to greyscale first). The numbers underneath show how long it took to process the image.
If you want them, here are the source images I used:
- original
- slightly blurred
- blurred
Update:
There's a problem with this algorithm in that it relies on the image having a fairly high level of contrast as well as sharp focused edges. It can be improved by finding the maximum pixel difference (maxdiff), and finding the overall range of pixel values in a small area centred on this location (range). The sharpness is then calculated as follows:
sharpness = (maxdiff / (offset + range)) * (1.0 +offset / 255) * 100%
where offset is a parameter that reduces the effects of very small edges so that background noise does not affect the results significantly. (I used a value of 15.)
This produces fairly good results. Anything with a sharpness of less than 40% is probably out of focus. Here's are some examples (the locations of the maximum pixel difference and the 9×9 local search areas are also shown for reference):
(source)
(source)
(source)
(source)
The results still aren't perfect, though. Subjects that are inherently blurry will always result in a low sharpness value:
(source)
Bokeh effects can produce sharp edges from point sources of light, even when they are completely out of focus:
(source)
You commented that you want to be able to reject user-submitted photos that are out of focus. Since this technique isn't perfect, I would suggest that you instead notify the user if an image appears blurry instead of rejecting it altogether.
I suppose that, philosophically speaking, all natural images are blurry...How blurry and to which amount, is something that depends upon your application. Broadly speaking, the blurriness or sharpness of images can be measured in various ways. As a first easy attempt I would check for the energy of the image, defined as the normalised summation of the squared pixel values:
1 2E = --- Σ I, where I the image and N the number of pixels (defined for grayscale) N
First you may apply a Laplacian of Gaussian (LoG) filter to detect the "energetic" areas of the image and then check the energy. The blurry image should show considerably lower energy.
See an example in MATLAB using a typical grayscale lena image:
This is the original imageThis is the blurry image, blurred with gaussian noiseThis is the LoG image of the originalAnd this is the LoG image of the blurry one
If you just compute the energy of the two LoG images you get:
E = 1265 E = 88 or bl
which is a huge amount of difference...
Then you just have to select a threshold to judge which amount of energy is good for your application...
calculate the average L1-distance of adjacent pixels:
N1=1/(2*N_pixel) * sum( abs(p(x,y)-p(x-1,y)) + abs(p(x,y)-p(x,y-1)) )
then the average L2 distance:
N2= 1/(2*N_pixel) * sum( (p(x,y)-p(x-1,y))^2 + (p(x,y)-p(x,y-1))^2 )
then the ratio N2 / (N1*N1) is a measure of blurriness. This is for grayscale images, for color you do this for each channel separately.
- Simple way to check if an image bitmap is blur
- Is there a way to check if android WindowManager already contains a view?
- Ten Ways to Check if an Integer Is a Power Of Two in C
- Write an Efficient Method to Check if a Number is Multiple of 3
- Ten Ways to Check if an Integer Is a Power Of Two in C
- Ten Ways to Check if an Integer Is a Power Of Two in C
- Judging if an array is ascendingin a recursion way
- A simple way to read an XML file in Java
- Write an Efficient Method to Check if a Number is Multiple of 3(快速判断3的倍数)
- What is the correct way to completely remove an application?
- how to check if license is downloaded fully
- Android How to Check if the App is in Background
- Fastest way to check if a file exist using standard C++
- What is the best way to implement a heartbeat in C++ to check for socket connectivity?
- An effective way to use pattern to instead of multiple if else statements
- Simple way to identify iOS user agent in a jQuery if/then statement?
- How to judge if an iterator is used before.
- 【客户端】windows c++ 检查图像文件是否有效(Check if file is valid image)
- 局部变量问题
- Orchard相关名词
- 第八周项目1 - 建立顺序串的算法库
- MySQL 主从备份
- 【串项目1 - 建立顺序串的算法库——第8周】
- Simple way to check if an image bitmap is blur
- ACE_Proactor实现
- 熟悉linux-部署多个tomcat
- 高斯模糊的算法
- BZOJ 4300 绝世好题 递推
- C++Windows下递归遍历多级目录
- cocoapods 安装
- 第八周--项目一--建立顺序串的算法库
- 堆栈顺序存储和 free 失败原因分析