python 简单的实现NRSS 无参考图片质量检测

NRSS 算法流程python 简单的实现NRSS 无参考图片质量检测_第1张图片

实现过程中的说明

在实现过程中发现如果步长设置的小,算法运行的特别慢,达不到性能要求啊,于是用等分图片试了试。直接参考程序吧。

code

#encoding=utf-8

import cv2
import numpy as np
from skimage.measure import compare_ssim





def gauseBlur(img):
    img_Guassian = cv2.GaussianBlur(img,(7,7),0)
    return img_Guassian

def loadImage(filepath):
    img = cv2.imread(filepath, 0)  ## 读入灰度图
    return img


def showImage(img):
    cv2.imshow('image', img)
    cv2.waitKey(0)


def saveImage(path, img):
    cv2.imwrite(path, img)

def sobel(img):
    x = cv2.Sobel(img, cv2.CV_16S, 1, 0)
    y = cv2.Sobel(img, cv2.CV_16S, 0, 1)

    absX = cv2.convertScaleAbs(x)  # 转回uint8
    absY = cv2.convertScaleAbs(y)

    dst = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)

    return dst

def getBlock(G,Gr):
    (h, w) = G.shape
    G_blk_list = []
    Gr_blk_list = []
    sp = 6
    for i in range(sp):
        for j in range(sp):
            G_blk = G[int((i / sp) * h):int(((i + 1) / sp) * h), int((j / sp) * w):int(((j + 1) / sp) * w)]
            Gr_blk = Gr[int((i / sp) * h):int(((i + 1) / sp) * h), int((j / sp) * w):int(((j + 1) / sp) * w)]
            G_blk_list.append(G_blk)
            Gr_blk_list.append(Gr_blk)

    sum = 0
    for i in range(sp*sp):
        mssim = compare_ssim(G_blk_list[i], Gr_blk_list[i])
        sum = mssim + sum

    nrss = 1-sum/(sp*sp*1.0)
    print(nrss)




def NRSS(path):
    image = loadImage(path)
    #高斯滤波
    Ir = gauseBlur(image)
    G = sobel(image)
    Gr = sobel(Ir)

    blocksize = 8
    ## 获取块信息
    getBlock(G, Gr)

if __name__ == "__main__":
    filepath = "F:\\testpic\\new\\blurtest\\clear\\3.jpg"
    NRSS(filepath)

你可能感兴趣的:(机器学习,python,工作记录)