- Timestamp:
- Jul 17, 2014, 12:30:45 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-ops-20130712/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/imcombine/pmStack.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-ops-20130712/psModules
- Property svn:mergeinfo deleted
-
branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.c
r35455 r37066 43 43 // #define TEST_X 972 44 44 // #define TEST_Y 3213 45 #define TEST_X 3289 46 #define TEST_Y 4810 47 #define TEST_RADIUS 0.5 // Radius to examine 45 //#define TEST_X 3289 46 //#define TEST_Y 4810 47 //#define TEST_RADIUS 0.5 // Radius to examine 48 //MEH -- streak-like junk md04s065i 49 #define TEST_X 1129 50 #define TEST_Y 4256 51 #define TEST_RADIUS 2.0 // Radius to examine 48 52 # endif 49 53 … … 108 112 109 113 // KMM functions to do bimodality rejection of pixels 110 floatgaussian(float x, float m, float s) {114 double gaussian(float x, float m, float s) { 111 115 return(pow(s * sqrt(2 * M_PI),-1) * exp(-0.5 * pow( (x - m) / s, 2))); 112 116 } … … 116 120 float *mU, float *sU, 117 121 float *pi1, float *m1, float *s1, 118 float *pi2, float *m2, float *s2) { 122 float *pi2, float *m2, float *s2, 123 int xyrdebug) { 119 124 assert(values); 120 125 assert(values->type.type == PS_TYPE_F32); … … 151 156 } 152 157 158 if (xyrdebug == 1) { 159 fprintf(stderr,"KMM uni: %d %f %d (%f %f)\n", 160 xyrdebug,logL_unimodal,discrepant_index, 161 *mU,*sU); 162 } 163 153 164 // Do EM loop 154 165 float dL = 0; … … 186 197 *pi2 = 0.5; 187 198 188 float g1,g2,norm; 199 //MEH -- need to be double to help avoid 0 in norm 200 double g1,g2,norm; 189 201 float w1,w2; 190 202 … … 203 215 /* *m2,*s2,*pi2); */ 204 216 /* } */ 217 218 if (xyrdebug == 1) { 219 fprintf(stderr,"KMM EM iter: %d %f %f %f %f (%f %f %e) (%f %f %e)\n", 220 *iter,logL_unimodal,logL_bimodal,oldL,dL, 221 *m1,*s1,*pi1, 222 *m2,*s2,*pi2); 223 } 224 205 225 // Expectation/P-stage 206 226 for (i = 0; i < values->n; i++) { // Calculate probabilities for each mode … … 208 228 g2 = gaussian(values->data.F32[i],*m2,*s2); 209 229 norm = (*pi1 * g1 + *pi2 * g2); 210 P1->data.F32[i] = (*pi1 * g1) / norm; 211 P2->data.F32[i] = (*pi2 * g2) / norm; 230 //MEH -- must protect denom from norm=0 231 if (norm > 0) { 232 P1->data.F32[i] = (*pi1 * g1) / norm; 233 P2->data.F32[i] = (*pi2 * g2) / norm; 234 } else { 235 P1->data.F32[i] = 0.0; 236 P2->data.F32[i] = 0.0; 237 } 238 239 if (xyrdebug == 1) { 240 fprintf(stderr,"KMM EM-P loop: %d %d %le %le %le\n", 241 *iter,i,norm,g1,g2); 242 } 243 212 244 } 213 245 // Maximization/M-stage … … 231 263 w1 += P1->data.F32[i]; 232 264 w2 += P2->data.F32[i]; 265 266 if (xyrdebug == 1) { 267 fprintf(stderr,"KMM EM-M loop: %d %d (%f %f %f %e) (%f %f %f %e)\n", 268 *iter,i,*m1,values->data.F32[i],w1,P1->data.F32[i],*m2,values->data.F32[i],w2,P2->data.F32[i]); 269 } 270 233 271 } 234 272 *m1 /= w1; … … 250 288 *pi2 = 0.0; 251 289 } 252 if (*s1 == 0) { // sigma may not be zero 253 *s1 = KMM_SMALL_NUMBER * *m1; 254 } 255 if (*s2 == 0) { // sigma may not be zero 256 *s2 = KMM_SMALL_NUMBER * *m2; 257 } 290 if (*s1 == 0) { // sigma may not be zero -- MEH -- nor <0 and need additive offset if m~0 291 *s1 = fabsf(KMM_SMALL_NUMBER * *m1) + KMM_SMALL_NUMBER; 292 } 293 if (*s2 == 0) { // sigma may not be zero 294 *s2 = fabsf(KMM_SMALL_NUMBER * *m2) + KMM_SMALL_NUMBER; 295 } 296 297 if (xyrdebug == 1) { 298 fprintf(stderr,"KMM EM end: %d %f %f %f %f (%f %e %e %f) (%f %e %e %f)\n", 299 *iter,logL_unimodal,logL_bimodal,oldL,dL, 300 *m1,*s1,*pi1,w1, 301 *m2,*s2,*pi2,w2); 302 } 303 258 304 } // End EM phase 259 305 … … 267 313 *Punimodal = 1.0; 268 314 } 315 316 if (xyrdebug == 1) { 317 fprintf(stderr,"KMM calc Puni: %d %f %d %f\n", 318 xyrdebug,lambda,df,*Punimodal); 319 } 320 269 321 psFree(P1); 270 322 psFree(P2); 271 323 } 272 324 273 static void KMMFindPopular(const psVector *values, float *Punimodal, float *mean, float *sigma, float *pi ) {325 static void KMMFindPopular(const psVector *values, float *Punimodal, float *mean, float *sigma, float *pi, int xyrdebug) { 274 326 float KMM_MINIMUM_PVALUE = 0.05; // Should be an option. 275 327 float mU,sU; … … 283 335 &mU,&sU, 284 336 &pi1,&m1,&s1, 285 &pi2,&m2,&s2 );337 &pi2,&m2,&s2,xyrdebug); 286 338 /* fprintf(stdout,"%g %g : %g %g %g : %g %g %g : %g %d\t", */ 287 339 /* mU,sU, */ … … 783 835 psImageMaskType goodMask, // Value for good pixels 784 836 bool safe, // Safe combination? 837 int nminpix, // Minimum number of input per pixel 785 838 float invTotalWeight // Inverse of total weight for all inputs 786 839 ) … … 802 855 CHECKPIX(x, y, "bad vs good : %x %x %x\n", maskValue, badMask, blankMask); 803 856 804 switch (num) { 857 //MEH -- hackish adding of lower limit for input per pixel 858 int numN = num; 859 if (num < nminpix) { 860 CHECKPIX(x, y, "Nmin (%d) inputs (%d) to combine, pixel %d,%d is manually set bad\n", nminpix, numN, x, y); 861 numN = 0; 862 } 863 switch (numN) { 805 864 case 0: { 806 865 // Nothing to combine: it's bad … … 898 957 psVector *pixelSuspects = buffer->suspects; // Is the pixel suspect? 899 958 psVector *pixelLimits = buffer->limits; // Is the pixel suspect? 959 //MEH -- adding a debug option for TESTING xyr position but could be better.. 960 int xyrdebug = 0; 900 961 901 962 // KMM values; … … 917 978 // This should probably be an option 918 979 if (useKMM) { 919 KMMFindPopular(pixelData,&Punimodal,&KMMmean,&KMMsigma,&KMMpi); 980 #ifdef TESTING 981 if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) { 982 xyrdebug = 1; 983 } 984 # endif 985 KMMFindPopular(pixelData,&Punimodal,&KMMmean,&KMMsigma,&KMMpi,xyrdebug); 920 986 CHECKPIX(x,y,"KMM Popularity Contest: (%d,%d) Puni: %g Mean: %f Sigma %f Pi: %f\n", 921 987 x,y,Punimodal,KMMmean,KMMsigma,KMMpi); … … 1459 1525 bool useVariance, 1460 1526 bool safe, 1527 int nminpix, 1461 1528 bool rejection) 1462 1529 { … … 1633 1700 psImageMaskType goodMask = 0; // OR of mask bits in all good input pixels 1634 1701 combineExtract(&num, &suspect, &badMask, &goodMask, buffer, combinedImage, combinedMask, combinedVariance, input, weights, exps, addVariance, reject, x, y, badMaskBits, suspectMaskBits); 1635 combinePixels(combinedImage, combinedMask, combinedVariance, exp, expnum, expweight, num, buffer, x, y, blankMaskBits, badMask, goodMask, safe, totalExpWeight);1702 combinePixels(combinedImage, combinedMask, combinedVariance, exp, expnum, expweight, num, buffer, x, y, blankMaskBits, badMask, goodMask, safe, nminpix, totalExpWeight); 1636 1703 1637 1704 if (iter > 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
