- Timestamp:
- Jun 8, 2011, 2:41:13 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20110406/psModules/src/imcombine/pmStack.c
r31607 r31618 22 22 #include <pslib.h> 23 23 24 #include <gsl/gsl_cdf.h> 25 24 26 #include "pmHDU.h" 25 27 #include "pmFPA.h" … … 35 37 36 38 37 # if ( 0)39 # if (1) 38 40 #define TESTING // Enable test output 39 #define TEST_X 3145 // x coordinate to examine40 #define TEST_Y 2334// y coordinate to examine41 #define TEST_X 5745 // x coordinate to examine 42 #define TEST_Y 5331 // y coordinate to examine 41 43 #define TEST_RADIUS 0.5 // Radius to examine 42 44 # endif … … 332 334 memset (nGoodBits, 0, 16*sizeof(int)); 333 335 334 // Extract the pixel and mask data 336 337 // Extract the pixel and mask data 335 338 int numGood = 0; // Number of good pixels 336 339 for (int i = 0, j = 0; i < inputs->n; i++) { … … 364 367 continue; 365 368 } 366 369 367 370 int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout 368 371 psImage *mask = data->readout->mask; // Mask of interest … … 984 987 985 988 static void KMMcalculate(const psVector *values, 986 float *Punimodal, 989 float *Punimodal,int *iter, 987 990 float *pi1, float *m1, float *s1, 988 991 float *pi2, float *m2, float *s2) { … … 1012 1015 float dL = 0; 1013 1016 float oldL = -999; 1014 int k= 0;1017 *iter = 0; 1015 1018 logL_bimodal = logL_unimodal; 1016 1019 *m1 = mU - 3 * sU; … … 1024 1027 float w1,w2; 1025 1028 1026 while (((dL > KMM_TOLERANCE)||(k < 3))&&(k < KMM_MAX_ITERATIONS)) { 1027 k++; 1029 float KMM_TOLERANCE = 1e-6; 1030 int KMM_MAX_ITERATIONS = 500; 1031 float KMM_SMALL_NUMBER = 1e-5; 1032 while (((dL > KMM_TOLERANCE)||(*iter < 3))&&(*iter < KMM_MAX_ITERATIONS)) { 1033 *iter += 1; 1028 1034 dL = fabs(logL_bimodal - oldL); 1029 1035 oldL = logL_bimodal; … … 1055 1061 *m2 += values->data.F32[i] * P2->data.F32[i]; 1056 1062 1057 w1 += P1 [i];1058 w2 += P2 [i];1063 w1 += P1->data.F32[i]; 1064 w2 += P2->data.F32[i]; 1059 1065 } 1060 1066 *m1 /= w1; … … 1095 1101 } 1096 1102 1097 static void KMMrejectUnpopular(const psVector *values, psArray *reject) { 1103 static void KMMRejectUnpopular(const psArray *inputs, int x, int y) { 1104 float KMM_MINIMUM_PVALUE = 0.05; 1098 1105 float Punimodal,pi1,m1,s1,pi2,m2,s2; 1099 KMMcalculate(values,&Punimodal, 1106 int iter; 1107 int j; 1108 1109 psVector *values = psVectorAlloc(inputs->n, PS_TYPE_F32); 1110 for (j = 0; j < inputs->n; j++) { 1111 pmStackData *data = inputs->data[j]; // Stack data of interest 1112 psImage *image = data->readout->image; // Image of interest 1113 int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout 1114 values->data.F32[j] = image->data.F32[yIn][xIn]; 1115 } 1116 1117 KMMcalculate(values,&Punimodal,&iter, 1100 1118 &pi1,&m1,&s1, 1101 1119 &pi2,&m2,&s2); 1120 // fprintf(stderr, 1121 psTrace("psModules.imcombine",3, 1122 "KMM Unpopular Test: %d,%d: Puni: %f in %d",x,y,Punimodal,iter); 1123 // CHECKPIX(x, y, " 1124 1102 1125 if (Punimodal < KMM_MINIMUM_PVALUE) { 1103 1126 int i; 1104 float g1,g2 ;1127 float g1,g2,norm; 1105 1128 float P1,P2; 1106 1129 … … 1112 1135 P2 = (pi2 * g2) / norm; 1113 1136 1137 CHECKPIX(x, y, "KMM Unpopular Rejection: %d,%d: %d %f %f:(%f %f %f ) %f:(%f %f %f) rejection? %d %d\n", 1138 x, y, i, values->data.F32[i], 1139 P1,m1,s1,pi1, 1140 P2,m2,s2,pi2, 1141 (pi1 > pi2)&&(P1 < P2), 1142 (pi1 < pi2)&&(P1 > P2)); 1114 1143 if ((pi1 > pi2)&&(P1 < P2)) { // mode 1 is more popular, but this element belongs to mode 2 1115 reject_input(reject,i);1144 combineMarkReject(inputs,x,y,i); 1116 1145 } 1117 1146 if ((pi1 < pi2)&&(P1 > P2)) { // mode 2 is more popular, but this element belongs to mode 1 1118 reject_input(reject,i);1147 combineMarkReject(inputs,x,y,i); 1119 1148 } 1120 1149 } 1121 1150 } 1151 psFree(values); 1122 1152 // else do nothing. 1123 1153 } 1124 1154 1125 static void KMMrejectBright(const psVector *values, psArray *reject) { 1126 KMMcalculate(values,&Punimodal, 1155 static void KMMRejectBright(const psArray *inputs, int x, int y) { 1156 float KMM_MINIMUM_PVALUE = 0.05; 1157 float Punimodal,pi1,m1,s1,pi2,m2,s2; 1158 int iter; 1159 int j; 1160 1161 psVector *values = psVectorAlloc(inputs->n, PS_TYPE_F32); 1162 for (j = 0; j < inputs->n; j++) { 1163 pmStackData *data = inputs->data[j]; // Stack data of interest 1164 psImage *image = data->readout->image; // Image of interest 1165 int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout 1166 values->data.F32[j] = image->data.F32[yIn][xIn]; 1167 } 1168 1169 KMMcalculate(values,&Punimodal,&iter, 1127 1170 &pi1,&m1,&s1, 1128 1171 &pi2,&m2,&s2); 1129 1172 if (Punimodal < KMM_MINIMUM_PVALUE) { 1130 1173 int i; 1131 float g1,g2 ;1174 float g1,g2,norm; 1132 1175 float P1,P2; 1133 1176 … … 1140 1183 1141 1184 if ((m1 > m2)&&(P1 > P2)) { // m1 is larger, and this element belongs to mode 1 1142 reject_input(reject,i);1185 combineMarkReject(inputs,x,y,i); 1143 1186 } 1144 1187 if ((m1 < m2)&&(P1 < P2)) { // m2 is larger, and this element belongs to mode 2 1145 reject_input(reject,i);1188 combineMarkReject(inputs,x,y,i); 1146 1189 } 1147 1190 } … … 1310 1353 } 1311 1354 1355 // Pre-reject inputs using KMM bimodality test. 1356 if (1) { 1357 /* KMMRejectUnpopular(input,x,y); */ 1358 rejection = true; 1359 } 1360 1312 1361 // Set up rejection list 1313 1362 psArray *pixelMap = NULL; // Map of pixels to source … … 1319 1368 for (int y = minInputRows; y < maxInputRows; y++) { 1320 1369 for (int x = minInputCols; x < maxInputCols; x++) { 1370 1321 1371 CHECKPIX(x, y, "Combining pixel %d,%d: %x %x %f %f %f %f %d %d %d\n", x, y, badMaskBits, blankMaskBits, iter, rej, sys, olympic, useVariance, safe, rejection); 1372 1373 // Pre-reject inputs using KMM bimodality test. 1374 if (1) { 1375 KMMRejectUnpopular(input,x,y); 1376 /* rejection = true; */ 1377 } 1378 else { 1379 KMMRejectBright(input,x,y); 1380 } 1322 1381 1323 1382 #ifdef TESTING
Note:
See TracChangeset
for help on using the changeset viewer.
