理论

Brenner梯度函数是最简单的梯度评价函数,它只是简单的计算相邻两个像素灰度差的平方,该函数定义如下:
Brenner 梯度函数 - 图1
其中:Brenner 梯度函数 - 图2 表示图像f对应像素点Brenner 梯度函数 - 图3的灰度值,Brenner 梯度函数 - 图4为图像清晰度计算结果。
https://blog.csdn.net/Real_Myth/article/details/50827940

算法

  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

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

  1. ###########################################
  2. def ImageToMatrix(dir,name):
  3. # 读取图片
  4. im = Image.open(dir+name)
  5. # 显示图片
  6. #im.show()
  7. width,height = im.size
  8. im = im.convert("L")
  9. data = im.getdata()
  10. data = np.matrix(data,dtype='float')/255.0
  11. new_data = np.reshape(data,(height,width))
  12. return new_data
  13. def Brenner(img):
  14. x, y = img.shape
  15. D = 0
  16. for i in range(x-2):
  17. for j in range(y-2):
  18. D += (img[i+2, j] - img[i, j])**2
  19. return D
  20. def TestBrener():
  21. dir = "D:/document/ZKBH/bug/face/"
  22. imgList = getAllImg(dir)
  23. for i in range(len(imgList)):
  24. frame = ImageToMatrix(dir , imgList[i])
  25. score = Brenner(frame)
  26. print(str(imgList[i]) + " is " + str(score))
  27. ###########################################
  28. def ImageToMatrix(dir,name):
  29. # 读取图片
  30. im = Image.open(dir+name)
  31. # 显示图片
  32. #im.show()
  33. width,height = im.size
  34. im = im.convert("L")
  35. data = im.getdata()
  36. data = np.matrix(data,dtype='float')/255.0
  37. new_data = np.reshape(data,(height,width))
  38. return new_data
  39. def Brenner(img):
  40. x, y = img.shape
  41. D = 0
  42. for i in range(x-2):
  43. for j in range(y-2):
  44. D += (img[i+2, j] - img[i, j])**2
  45. return D
  46. def TestBrener():
  47. dir = "D:/document/ZKBH/bug/face/"
  48. imgList = getAllImg(dir)
  49. for i in range(len(imgList)):
  50. frame = ImageToMatrix(dir , imgList[i])
  51. score = Brenner(frame)
  52. print(str(imgList[i]) + " is " + str(score))
  53. ################################

https://www.cnblogs.com/greentomlee/p/9379471.html

  1. ## 2. Brenner 梯度函数
  2. Brenner梯度函数是最简单的梯度评价函数,它只是简单的计算相邻两个像素灰度差的平方,该函数定义如下:
  3. ![](https://ws1.sinaimg.cn/large/cdd040eely1g46bosf58xj20890123yn.jpg)
  4. 其中:f(x,y) 表示图像f对应像素点(x,y)的灰度值,D(f)为图像清晰度计算结果(下同)。
  5. **代码:**
  6. ```

def Brenner(img): x, y = img.shape D = 0 for i in range(x-2): for j in range(y-2): D += (img[i+2, j] - img[i, j])**2 return D ``` https://gist.github.com/JuneoXIE/d595028586eec752f4352444fc062c44