Calculating sharpness of an image

感情迁移 提交于 2020-05-23 03:29:26

问题


I found on the internet that laplacian method is quite good technique to compute the sharpness of a image. I was trying to implement it in opencv 2.4.10. How can I get the sharpness measure after applying the Laplacian function? Below is the code:

Mat src_gray, dst;
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;

GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );

/// Convert the image to grayscale
cvtColor( src, src_gray, CV_RGB2GRAY );

/// Apply Laplace function
Mat abs_dst;

Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );

//compute sharpness
??

Can someone please guide me on this?


回答1:


Possible duplicate of: Is there a way to detect if an image is blurry?

so your focus measure is:

cv::Laplacian(src_gray, dst, CV_64F);

cv::Scalar mu, sigma;
cv::meanStdDev(dst, mu, sigma);

double focusMeasure = sigma.val[0] * sigma.val[0];

Edit #1:

Okay, so a well focused image is expected to have sharper edges, so the use of image gradients are instrumental in order to determine a reliable focus measure. Given an image gradient, the focus measure have to pool the data at each point as an unique value.

The use of second derivatives is one technique for passing the high spatial frequencies, which are associated with sharp edges. As a second derivative operator we use the Laplacian operator, that can be approximate using the mask:

enter image description here

Foor pooling the data at each point, we use two methods. The first one is the sum of all the absolute values, driving to the following focus measure:

enter image description here

where L(m, n) is the convolution of the input image I(m, n) with the mask L. The second method calculates the variance of the absolute values, providing a new focus measure given by:

enter image description here

where L overline is the mean of absolute values.

Read the article

J.L. Pech-Pacheco, G. Cristobal, J. Chamorro-Martinez, J. Fernandez-Valdivia, "Diatom autofocusing in brightfield microscopy: a comparative study", 15th International Conference on Pattern Recognition, 2000. (Volume:3 )

for more information.




回答2:


This article helped me in blurring, sharpening, embossing, edge detection in my frame. Kernal Image Processing

I used the above help in android application. I will publish the link and source code of an app once I complete.

Hope this helps. Happy coding :)



来源:https://stackoverflow.com/questions/28717054/calculating-sharpness-of-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!