【问题标题】:means, std deviation, variance and skewness of image图像的均值、标准偏差、方差和偏度
【发布时间】:2014-04-27 12:28:25
【问题描述】:

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

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

【问题讨论】:

  • 你的问题是……?
  • 所以查找方差和偏度的公式并实施它们。方差是微不足道的,因为您已经有了标准偏差。偏度可能有点棘手。
  • 有没有内置的方差函数,类似于opencv中的mean和std dev?

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


【解决方案1】:

引用自: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);
    }
} 

【讨论】: