这几天在看文章的时候,看到这么一段话:
“First, we normalize the grayscale intensity in the eye region for each of the aligned facial images to zero mean and unit variance.”
意思就是第一步对眼睛的区域进行零均值单位方差。第一次知道还有这玩意。。
经过查阅matlab prestd函数就代表了这个意思:
试验一下:
>> a=[1 2 3 4] a = 1 2 3 4 >> [pn m std]=prestd(a) Warning: PRESTD is an obsolete function. > In obs_fcn at 18 In prestd at 10 Use MAPSTD instead. pn = -1.1619 -0.3873 0.3873 1.1619 m = 2.5000 std = 1.2910 >>
其中pn代表已经零均值单位方差的矩阵,m代表a的均值 std代表a的方差
转成C++代码就应该是这样:
int a = 2; int b = 2; double gray[2 * 2] = { 1,2,3,4 }; double total = 0.0; for (int i = 0; i < b; i++) { for (int j = 0; j < a; j++) { total += (double)gray[i*a + j]; } } double meanvalue = total / (a*b); //零均值单位方差 double stdp = 0.0; for (int i = 0; i < b; i++) { for (int j = 0; j < a; j++) { double temp = gray[i*a + j]; stdp += ((temp - meanvalue)*(temp - meanvalue)); } } stdp = sqrt(stdp / (a*b));
qDebug() << meanvalue << " " << stdp;
for (int i = 0; i < b; i++) { for (int j = 0; j < a; j++) { double temp = gray[i*a + j]; qDebug()<<i<<" "<<j<<" "<<(temp - meanvalue) / stdp; } }
咱们看一下结果输出:
发现在方差的值就不一样了。为什么呢,
原来方差还存在偏差的概念;
double meanvalue = total / (a*b);//有偏差为n
double meanvalue = total / (a*b-1);//无偏差的方差n-1而matlab默认是无偏差的方差,所以我们只要用无偏差替换到有偏差就和metlab相对应了。
时间: 2024-10-10 13:04:16