45 float* var = (
float *) p->
FOM();
52 for ( i=0; i<n; i++ ) ws += weight[i];
54 double dof = ws*(1 - 1.0L/n);
55 double hdof = 0.5*dof;
58 for ( i=0; i<datasize; i++ ) avg_var += var[i];
62 cout <<
"Student's t test:" << endl;
63 cout <<
"Number: " << n << endl;
64 cout <<
"Average variance: " << avg_var << endl;
65 cout <<
"Degrees of freedom: " << dof << endl << endl;
70 for ( i=0; i<datasize; i++ ) {
72 if ( d < avg_var ) d = avg_var;
74 pt->
set(i, (*p)[i]/d);
75 siglev[i] =
betai(hdof, 0.5, dof/(dof + (*pt)[i]*(*pt)[i]));
117 float* var1 = p1->
FOM();
118 float* var2 = p2->
FOM();
123 cout << endl <<
"Student's t-test, assuming same variance in sets 1 and 2" << endl;
124 cout <<
"Set 1 contains " << set1 <<
" images" << endl;
125 cout <<
"Set 2 contains " << set2 <<
" images" << endl;
129 for ( i=0, j=0, ws1=0; i<set1; i++, j++ ) ws1 += weight[j];
130 for ( i=0, ws2=0; i<set2; i++, j++ ) ws2 += weight[j];
132 double inv_weight_sum = (1.0L / ws1) + (1.0L / ws2);
134 double dof1 = ws1*(1.0L - 1.0L/set1);
135 double dof2 = ws2*(1.0L - 1.0L/set2);
136 double dof = dof1 + dof2;
137 double hdof = 0.5*dof;
141 long zero_count1 = 0, zero_count2 = 0;
142 for ( i=0; i<datasize; i++ ) {
143 Vn1 = var1[i] * dof1;
144 Vn2 = var2[i] * dof2;
145 SD = sqrt( ( (Vn1 + Vn2) / dof ) * inv_weight_sum );
147 pt->
set(i, ( (*p1)[i] - (*p2)[i] ) / SD);
148 if ( (*pt)[i] == 0 ) zero_count2++;
149 sig[i] =
betai(hdof, 0.5L, dof/(dof + (*pt)[i]*(*pt)[i]) );
158 cout << zero_count1 <<
" pixels had a zero value for the standard error of the differences of the means, and t was set to zero." << endl;
159 cout << zero_count2 <<
" pixels had standard deviation > 0 and t = 0." << endl;
160 cout << datasize <<
" = total pixels in image" << endl;
200 float* var1 = p1->
FOM();
201 float* var2 = p2->
FOM();
206 cout << endl <<
"Student's t-test, assuming unequal variance in sets 1 and 2" << endl;
207 cout <<
"Set 1 contains " << set1 <<
" images" << endl;
208 cout <<
"Set 2 contains " << set2 <<
" images" << endl;
212 for ( i=0, j=0, ws1=0; i<set1; i++, j++ ) ws1 += weight[j];
213 for ( i=0, ws2=0; i<set2; i++, j++ ) ws2 += weight[j];
215 double dof1 = ws1*(1.0L - 1.0L/set1);
216 double dof2 = ws2*(1.0L - 1.0L/set2);
220 long zero_count1 = 0, zero_count2 = 0;
221 for ( i=0; i<datasize; i++ ) {
222 if ( var1[i] > 0 || var2[i] > 0 ) {
225 pt->
set(i, ( (*p1)[i] - (*p2)[i] ) / sqrt(Vn1 + Vn2));
226 if ( (*pt)[i] == 0 ) zero_count2++;
227 dof = (Vn1 + Vn2)*(Vn1 + Vn2) / (Vn1*Vn1/dof1 + Vn2*Vn2/dof2);
228 sig[i] =
betai(0.5L*dof, 0.5L, dof/(dof + (*pt)[i]*(*pt)[i]) );
237 cout << zero_count1 <<
" pixels had zero variance and t was set to zero." << endl;
238 cout << zero_count2 <<
" pixels had variance not equal to 0 and t = 0." << endl;
239 cout << datasize <<
" = total pixels in image" << endl;
275 float* var1 = (
float *) p1->
FOM();
276 float* var2 = (
float *) p2->
FOM();
281 cout << endl <<
"F-test" << endl;
282 cout <<
"Set 1 contains " << set1 <<
" images" << endl;
283 cout <<
"Set 2 contains " << set2 <<
" images" << endl;
287 for ( i=0, j=0, ws1=0; i<set1; i++, j++ ) ws1 += weight[j];
288 for ( i=0, ws2=0; i<set2; i++, j++ ) ws2 += weight[j];
290 double dof1 = ws1*(1.0L - 1.0L/set1);
291 double dof2 = ws2*(1.0L - 1.0L/set2);
294 for ( i=0; i<datasize; i++ ) {
300 if ( var1[i] > var2[i] ) {
301 pf->
set(i, var1[i] / var2[i]);
305 pf->
set(i, var2[i] / var1[i]);
309 sig[i] = 2*
betai(0.5L*df2, 0.5L*df1, df2/(df2 + df1*(*pf)[i]) );
310 if ( sig[i] > 1 ) sig[i] = 2 - sig[i];
314 cout << j <<
" pixels in set 1 or set 2 had zero variance, and the F-values were set to zero." << endl;
315 cout << datasize <<
" = total pixels in image" << endl;
Header file for image class.
Header file for general utilities.
Bimage * img_students_t_test(int n, Bimage *p, float *weight)
Applies the Student's t-test to one set of images.
Vector3< size_t > size() const
General image parameter class.
float * FOM_initialize()
Allocates and initializes the FOM block.
Bimage * img_f_test(int set1, int set2, Bimage *p1, Bimage *p2, float *weight)
Applies the F-test to two sets of images.
double betai(double a, double b, double x)
Calculates the incomplete beta function Ix(a,b).
void origin(double x, double y, double z)
void set(size_t j, double v)
Sets a single value at the given index.
Bimage * img_students_t_test_equal(int set1, int set2, Bimage *p1, Bimage *p2, float *weight)
Applies the Student's t-test to two sets of images, assumes the two distributions have approximately ...
void origin(double ox, double oy, double oz)
Header file for general utilities.
Bimage * img_students_t_test_unequal(int set1, int set2, Bimage *p1, Bimage *p2, float *weight)
Applies the Student's t-test to two sets of images, assumes the two distributions have unequal varian...