void get_seghues_feature_test(){ int nr=30,nc=30; int*seglable=NEWA(int,nr*nc); image_hsv* imagehsv=image_hsv_new(nr,nc); int lablenum=5; int i=0; int j=0; float arclen[5]={0,36,180,18,54}; fSegment_hues feat; for(i=0;i<nr;++i){ for(j=0;j<nc;++j){ if(j<10) seglable[i*nc+j]=i/10+1; else seglable[i*nc+j]=i/10+1+3; if(seglable[i*nc+j]>5) seglable[i*nc+j]=3; } } for(i=0;i<nr;++i){ for(j=0;j<nc;++j){ if(i<10&&j<20){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0); } else if(i<10&&j<30){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+18.0; } if(i>=10&&i<20&&j<3){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0); } else if(i>=10&&i<20&&j<6){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+18.0; } else if(i>=10&&i<20&&j<10){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+36.0; } else if(i>=10&&i<20&&j<15){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0); } else if(i>=10&&i<20&&j<20){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+18.0; } else if(i>=10&&i<20&&j<25){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+36.0; } else if(i>=10&&i<20&&j<30){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+54.0; } if(i>=20&&i<30&&j<20){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+j*18.0; } else if(i>=20&&i<30&&j<30){ imagehsv->h[i*nc+j]=18.0*rand()/(RAND_MAX+1.0)+19*18.0; } if(i%10<5){ imagehsv->s[i*nc+j]=0.2*rand()/(RAND_MAX+1.0); imagehsv->v[i*nc+j]=0.2*rand()/(RAND_MAX+1.0); } else{ imagehsv->s[i*nc+j]=0.2*rand()/(RAND_MAX+1.0)+0.2; imagehsv->v[i*nc+j]=0.2*rand()/(RAND_MAX+1.0)+0.1; } } } feat=get_seghues_feature(seglable,imagehsv,nr,nc,lablenum); CU_ASSERT_EQUAL(feat.fhues1,1); CU_ASSERT_EQUAL(feat.fhues2, 20); CU_ASSERT_EQUAL(feat.fhues3, 20); CU_ASSERT_EQUAL(feat.fhues4, 19); CU_ASSERT_EQUAL(feat.fhues5, 180); CU_ASSERT_DOUBLE_EQUAL(feat.fhues6,get_stdev(arclen,5),0.00001); free(seglable); image_hsv_delete(imagehsv); }
void calc_forcing_stats(int Nrecs, atmos_data_struct *atmos, const int NR) { /********************************************************************** calc_forcing_stats.c Keith Cherkauer November 16, 2000 This routine finds the maximum, minimum and mean values for each data type. Results are output to stdout for inclusion in screen or log file output. These statistics are meant only to help the user identify possible problems in their input forcing data and are not an exhaustive study of that data. **********************************************************************/ double *values = (double *) calloc ( Nrecs, sizeof(double) ); printf("Variable\tMean\tStd. Dev.\tSum\tMaximum\tMinimum\n"); /** Air Temperature **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].air_temp[NR]; printf("air temp (C):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Density **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].density[NR]; printf("Density (kg/m^3):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Longwave **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].longwave[NR]; printf("Longwave (W/m^2):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Precipitation **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].prec[NR]; printf("Precip (mm):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Pressure **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].pressure[NR]; printf("Pressure (Pa):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Shortwave **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].shortwave[NR]; printf("Shortwave (W/m^2):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Vapor Pressure **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].vp[NR]; printf("vp (Pa):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Vapor Pressure Deficit **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].vpd[NR]; printf("vpd (Pa):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); /** Wind Speed **/ for (int rec = 0; rec < Nrecs; rec ++ ) values[rec] = atmos[rec].wind[NR]; printf("wind speed (m/s):\t%f\t%f\t%f\t%f\t%f\n", get_mean(values, Nrecs, INVALID), get_stdev(values, Nrecs, get_mean(values, Nrecs, INVALID), INVALID), get_sum(values, Nrecs, INVALID), get_max(values, Nrecs, INVALID), get_min(values, Nrecs, INVALID) ); fflush(stdout); free(values); }