《LearnPython-Python学习笔记》-图像清晰度评价指标(Python)

admin 2025-11-07 01:29:42 编程 来源:ZONE.CI 全球网 0 阅读模式
  • 评估方法实现
    • 1 Brenner 梯度函数
    • 2 Laplacian梯度函数
    • 3 SMD(灰度方差)
    • 4 SMD2(灰度方差乘积)
    • 5 方差函数
    • 6 能量梯度函数
    • 7 Vollath函数
    • 8 熵函数
  • 参考文献

    评估方法实现

    所有函数的具体说明都在参考文献[1]里,这里不做过多的赘述,只讨论实现。github:图像清晰度评估算法包(有示例)

    1 Brenner 梯度函数

    1. def brenner(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. shape = np.shape(img)
    7. out = 0
    8. for x in range(0, shape[0]-2):
    9. for y in range(0, shape[1]):
    10. out+=(int(img[x+2,y])-int(img[x,y]))**2
    11. return out

    2 Laplacian梯度函数

    1. def Laplacian(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. return cv2.Laplacian(img,cv2.CV_64F).var()

    3 SMD(灰度方差)

    1. def SMD(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. shape = np.shape(img)
    7. out = 0
    8. for x in range(0, shape[0]-1):
    9. for y in range(1, shape[1]):
    10. out+=math.fabs(int(img[x,y])-int(img[x,y-1]))
    11. out+=math.fabs(int(img[x,y]-int(img[x+1,y])))
    12. return out

    4 SMD2(灰度方差乘积)

    1. def SMD2(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. shape = np.shape(img)
    7. out = 0
    8. for x in range(0, shape[0]-1):
    9. for y in range(0, shape[1]-1):
    10. out+=math.fabs(int(img[x,y])-int(img[x+1,y]))*math.fabs(int(img[x,y]-int(img[x,y+1])))
    11. return out

    5 方差函数

    1. def variance(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. out = 0
    7. u = np.mean(img)
    8. shape = np.shape(img)
    9. for x in range(0,shape[0]):
    10. for y in range(0,shape[1]):
    11. out+=(img[x,y]-u)**2
    12. return out

    6 能量梯度函数

    1. def energy(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. shape = np.shape(img)
    7. out = 0
    8. for x in range(0, shape[0]-1):
    9. for y in range(0, shape[1]-1):
    10. out+=((int(img[x+1,y])-int(img[x,y]))**2)+((int(img[x,y+1]-int(img[x,y])))**2)
    11. return out

    7 Vollath函数

    1. def Vollath(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. shape = np.shape(img)
    7. u = np.mean(img)
    8. out = -shape[0]*shape[1]*(u**2)
    9. for x in range(0, shape[0]-1):
    10. for y in range(0, shape[1]):
    11. out+=int(img[x,y])*int(img[x+1,y])
    12. return out

    8 熵函数

    1. def entropy(img):
    2. '''
    3. :param img:narray 二维灰度图像
    4. :return: float 图像约清晰越大
    5. '''
    6. out = 0
    7. count = np.shape(img)[0]*np.shape(img)[1]
    8. p = np.bincount(np.array(img).flatten())
    9. for i in range(0, len(p)):
    10. if p[i]!=0:
    11. out-=p[i]*math.log(p[i]/count)/count
    12. return out

    参考文献

    [1] 图像清晰度的评价指标

    image.png

    https://blog.csdn.net/Greepex/article/details/90183018

    以太坊cppgolang区别 编程

    以太坊cppgolang区别

    以太坊是一种去中心化的开源平台,它采用智能合约技术,旨在构建和运行不受干扰的分布式应用程序。作为目前最受欢迎的区块链平台之一,以太坊提供了多种编程语言的支持,其
    progolang 编程

    progolang

    Go语言(Golang)是由Google开发的一门静态类型编程语言。作为一名专业的Golang开发者,我深知这门语言的优势和特点。在本文中,我将介绍Golang
    golangn个发送者 编程

    golangn个发送者

    Golang是一种开源的编程语言,由Google团队开发,旨在提高程序的并发性和简化软件开发过程。在Go语言中,有时需要向多个接收者发送信息。本文将介绍如何在G
    golang技能图谱 编程

    golang技能图谱

    从互联网行业的快速发展到人工智能技术的日益成熟,各种编程语言也应运而生。而在这众多的编程语言中,Golang(即Go)作为一门强大且高效的开发语言备受关注。Go
    评论:0   参与:  7