gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:31:53 25 4
gpt4 key购买 nike

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

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

从公式中可以看出,您需要做的是将值减去均值的总和除以标准差,所有这些都是 3 的次方。

色调 channel 的一个例子是:

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

关于c++ - 图像的均值、标准差、方差和偏度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22536725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com