图像的均值、标准差、方差和偏度

means, std deviation, variance and skewness of image

本文关键字:方差 标准差 图像      更新时间:2023-10-16

此代码将图像拆分为较小的块,并查找这些块的平均值并将这些值写入文件。我还想计算方差和偏度。请帮助

for (int r = 0; r < img.rows; r += m)
    for (int c = 0; c < img.cols; c += n)
    {
        Mat tile = img(Range(r, min(r + m, img.rows)),
            Range(c, min(c + n, img.cols)));
        Scalar MScalar,StdScalar;  
        meanStdDev(tile,MScalar,StdScalar);
        cout<<"n Blue Channel Avg is "<<MScalar.val[0];
        cout<<"n Green Channel Avg is "<<MScalar. val[1];
        cout<<"n Red Channel Avg is "<<MScalar. val[2];     
        cout<<"nBlue channel std dev is "<<StdScalar.val[0];
        cout<<"nGreen Channel std dev is "<<StdScalar. val[1];
        cout<<"nRed Channel std dev is "<<StdScalar. val[2]<<"n";
        int m[6] = { MScalar.val[0], MScalar.val[1], MScalar.val[2], StdScalar.val[0],  StdScalar.val[1], StdScalar.val[2] };
        Mat M = Mat(1, 6, CV_32S, m);
        outdata<< M << "n";
        cout<<M<<endl; 
    }
    outdata<<endl;
 }
}
waitKey(); 
return 0; 
}

引用自:http://en.wikipedia.org/wiki/Standard_deviation

"换句话说标准差σ (sigma)是X方差的平方根"

意思是,如果你有标准偏差,你所需要做的就是std*std来得到方差。

偏度:http://en.wikipedia.org/wiki/Skewness

你可以从公式中看到,你需要做的是值减去平均值的和,然后除以std,所有这些的3次方。

色调通道的一个例子是:

float skewness;
for (int x = 0; x<channelHue.rows; x++) {
    for (int y = 0; y<channelHue.cols; y++) {
        skewness += pow(((channelHue.at<int>(x, y) - mean)/std), 3);
    }
}