图像清晰度检测,这是我在网上看到的检测图像清晰度的算法, 有没有知道这是根据什么公式得来的啊

这是我在网上看到的检测图像清晰度的算法, 有没有知道这是根据什么公式得来的啊

double DefRto(Mat frame)
{
    Mat gray;
    cvtColor(frame, gray, CV_BGR2GRAY);
    IplImage *img = &(IplImage(gray));
    double temp = 0;
    double DR = 0;
    int i, j;//循环变量 
    int height = img->height;
    int width = img->width;
    int step = img->widthStep / sizeof(uchar);
    uchar *data = (uchar*)img->imageData;
    double num = width*height;
    for (i = 0; i < height - 1;i++)
    {
        for (j = 0; j < width;j++)
        {
            temp += sqrt((pow((double)(data[(i + 1)*step + j] - data[i*step + j]), 2) \
            + pow((double)(data[i*step + j + 1] - data[i*step + j]), 2)));
            temp += abs(data[(i + 1)*step + j] - data[i*step + j]) + abs(data[i*step + j + 1] - data[i*step + j]);
        }
    }
    DR = temp / num;
    return DR;
}

这个很容易理解,模糊的图像,就是像素点颜色的过渡非常平滑,没有颜色急剧的变化。反之锐化的图像就是像素点颜色变化很突然。
那么怎么反映两个像素点颜色的过渡呢,
sqrt((pow((double)(data[(i + 1)*step + j] - data[i*step + j]), 2) \
+ pow((double)(data[i*step + j + 1] - data[i*step + j]), 2)));
这里算的是像素点的平方差。
abs(data[(i + 1)*step + j] - data[i*step + j]) + abs(data[i*step + j + 1] - data[i*step + j]);
这里算的是差的绝对值。
为什么算两个,前者表现的是变化速度的快慢,后者是变化的大小。用这两个指标来评价比较准确。
DR = temp / num;
求一个平均数。