意味着,图像的std偏差,方差和偏度

时间:2014-03-20 14:52:47

标签: c++ opencv mean variance standard-deviation

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

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; 
}

1 个答案:

答案 0 :(得分:3)

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

“换句话说,标准差σ(sigma)是方差的平方根”

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

至于偏斜:http://en.wikipedia.org/wiki/Skewness

你可以从公式中看到你需要做的是值的总和减去平均值并除以标准,所有这些都是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);
    }
}