基于拉普拉斯算子的模糊图像评价

一. 模糊图像评价基础知识

图像质量评价(IQA),根据参考图片(reference image),即原始图片的存在与否,可分为:

  • 全参考(full-reference)方法, 有原始图片的全部信息
  • 半参考(reduced-reference)方法, 只有原始图片的部分信息
  • 无参考(no-reference)方法,没有原始图片

模糊图片分类

  • defocus blur image 散焦模糊图像
  • motion blur image 运动模糊图像

图像模糊原因:

  • 确定性因素:包括成像系统调焦不当、目标物体相对运动等
  • 随机性因素:主要是图像在记录、传输过程中的污染,比如电子系统的高频性能不好造成图像高频分量的损失。

在频域,当一幅图像的高频部分被削弱时图像看起来会显得模糊。

在空域,图像的边界和细节部分不清晰时,图像看起来也会显得模糊。

二. 无参考图片算法实现(Python)

import cv2
import os
import time

class Laplacian :
    def __init__(self, image_dir, recursion = False) :
        self.__image_dir = image_dir
        self.__image_paths = []
        for root_dir, sub_dirs, images in os.walk(image_dir, recursion) :
            for image in images :
                self.__image_paths.append(os.path.join(root_dir, image))

    def __read_image(self, image_path) :
        # In the case of color images, the decoded images will have the channels stored in **B G R** order.
        # When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available.
        # Results may differ to the output of cvtColor()
        return cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

    def __pre_process_image(self, image_path, **kwargs) :
        image = self.__read_image(image_path)
        if kwargs.get('width') and kwargs.get('height') :
            image = cv2.resize(image, (kwargs.get('width'), kwargs.get('height')))
        return image

    def get_image_paths(self) :
        return self.__image_paths

    def blur_detect(self, image_path) :
        cv_image = self.__pre_process_image(image_path, width = 200, height = 200)
        return cv2.Laplacian(cv_image, cv2.CV_64F).var()


def test_laplacian() :
    laplacian = Laplacian('dir of images that you want to detect with laplacian', False)
    image_paths = laplacian.get_image_paths()
    for path in image_paths :
        begin = time.time() * 1000
        score = laplacian.blur_detect(path)
        end = time.time() * 1000
        print("Laplacian detection {} value is {}, cost time {} ms".format(path, int(score), end - begin))


if __name__ == "__main__" :
    test_laplacian()

代码核心是OpenCV提供的接口cv2.Laplacian

def Laplacian(src, ddepth, dst=None, ksize=None, scale=None, delta=None, borderType=None):
“”"
Laplacian(src, ddepth[, dst[, ksize[, scale[, delta[, borderType]]]]]) -> dst
. @brief Calculates the Laplacian of an image.
.
. The function calculates the Laplacian of the source image by adding up the second x and y
. derivatives calculated using the Sobel operator:
.
. \f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f]
.
. This is done when ksize > 1. When ksize == 1, the Laplacian is computed by filtering the image
. with the following \fKaTeX parse error: Undefined control sequence: \f at position 11: 3 \times 3\̲f̲ aperture:
.
. \f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f]
.
. @param src Source image.
. @param dst Destination image of the same size and the same number of channels as src .
. @param ddepth Desired depth of the destination image.
. @param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for
. details. The size must be positive and odd.
. @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is
. applied. See #getDerivKernels for details.
. @param delta Optional delta value that is added to the results prior to storing them in dst .
. @param borderType Pixel extrapolation method, see #BorderTypes
. @sa Sobel, Scharr
“”"
pass

可以在__pre_process_image中进行图像的预处理,统一图像尺寸,类似于归一化的作用。

三. 算法评价

尝试用这个算法用于人脸识别的预处理步骤,判断人脸图片是否模糊。实际测试结果来看,单用拉普拉斯算子进行卷积运算,无法很好的评价人脸是否模糊。

目前从我测试的情况看,下面两篇参考文章提到的基于二次模糊的清晰度算法(ReBlur) 比较推荐使用。

  1. 面向无参考图像的清晰度评价方法研究
  2. The Blur Effect: Perception and Estimation with a New No-Reference Perceptual Blur Metric
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值