图片模糊,清晰图,过曝光检测相关算法
https://blog.csdn.net/wuan584974722/article/details/51435876
此实例通过使用Halcon实现5种清晰度算法函数:
1. 方差算法函数;
2. 拉普拉斯能量函数;
3. 能量梯度函数;
4. Brenner函数;
5. Tenegrad函数;
https://www.cnblogs.com/arkenstone/p/7900978.html
https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/
https://www.semanticscholar.org/paper/Analysis-of-focus-measure-operators-for-Pertuz-Puig/8c675bf5b542b98bf81dcf70bd869ab52ab8aae9?p2df
https://blog.csdn.net/dcrmg/article/details/53543341 (清晰度/相机聚焦度:1,求边缘,越清晰边缘越多;傅里叶变换后,越清晰,高频率部分越多)
https://gitee.com/bug_me_not/blur-detection/tree/master
常用方法代码示例:
https://stackoverflow.com/questions/7765810/is-there-a-way-to-detect-if-an-image-is-blurry
// OpenCV port of 'LAPM' algorithm (Nayar89) double modifiedLaplacian(const cv::Mat& src) { cv::Mat M = (Mat_<double>(3, 1) << -1, 2, -1); cv::Mat G = cv::getGaussianKernel(3, -1, CV_64F); cv::Mat Lx; cv::sepFilter2D(src, Lx, CV_64F, M, G); cv::Mat Ly; cv::sepFilter2D(src, Ly, CV_64F, G, M); cv::Mat FM = cv::abs(Lx) + cv::abs(Ly); double focusMeasure = cv::mean(FM).val[0]; return focusMeasure; } // OpenCV port of 'LAPV' algorithm (Pech2000) double varianceOfLaplacian(const cv::Mat& src) { cv::Mat lap; cv::Laplacian(src, lap, CV_64F); cv::Scalar mu, sigma; cv::meanStdDev(lap, mu, sigma); double focusMeasure = sigma.val[0]*sigma.val[0]; return focusMeasure; } // OpenCV port of 'TENG' algorithm (Krotkov86) double tenengrad(const cv::Mat& src, int ksize) { cv::Mat Gx, Gy; cv::Sobel(src, Gx, CV_64F, 1, 0, ksize); cv::Sobel(src, Gy, CV_64F, 0, 1, ksize); cv::Mat FM = Gx.mul(Gx) + Gy.mul(Gy); double focusMeasure = cv::mean(FM).val[0]; return focusMeasure; } // OpenCV port of 'GLVN' algorithm (Santos97) double normalizedGraylevelVariance(const cv::Mat& src) { cv::Scalar mu, sigma; cv::meanStdDev(src, mu, sigma); double focusMeasure = (sigma.val[0]*sigma.val[0]) / mu.val[0]; return focusMeasure; }
python代码示例:
import numpy import cv2 import os def evaluate(img_col): numpy.seterr(all='ignore') assert isinstance(img_col, numpy.ndarray), 'img_col must be a numpy array' assert img_col.ndim == 3, 'img_col must be a color image ({0} dimensions currently)'.format(img_col.ndim) img_gry = cv2.cvtColor(img_col, cv2.COLOR_RGB2GRAY) rows, cols = img_gry.shape crow, ccol = int(rows/2), int(cols/2) f = numpy.fft.fft2(img_gry) fshift = numpy.fft.fftshift(f) fshift[crow-75:crow+75, ccol-75:ccol+75] = 0 f_ishift = numpy.fft.ifftshift(fshift) img_fft = numpy.fft.ifft2(f_ishift) img_fft = 20*numpy.log(numpy.abs(img_fft)) result = numpy.mean(img_fft) return img_fft, result if __name__ == "__main__": src = r"F:\tmp2" for file in os.listdir(src): if file.endswith(".jpg"): img_file = os.path.join(src, file) img = cv2.imread(img_file) # 拉普拉斯方法,阈值默认为100 img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # img_gray = cv2.GaussianBlur(img_gray, ksize=(3, 3), sigmaX=0) # blur_score = cv2.Laplacian(img_gray, ddepth=cv2.CV_64F).var() blur_score = cv2.Laplacian(img_gray, ddepth=cv2.CV_64F) print(blur_score.var(), numpy.max(blur_score)) # 傅里叶方法, 阈值默认为10 _, ret = evaluate(img) print("fft", ret) cv2.namedWindow("img", cv2.WINDOW_NORMAL) cv2.resizeWindow("img", 960, 540) cv2.imshow("img", img) cv2.waitKey(0) cv2.destroyAllWindows()
曝光过度检测
https://blog.csdn.net/qq249356520/article/details/78864244
https://blog.csdn.net/u010029439/article/details/103081762
https://blog.csdn.net/kingroc/article/details/97640529