Changeset 2810 for trunk/psModules/src/pmSubtractSky.c
- Timestamp:
- Dec 23, 2004, 10:27:51 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/pmSubtractSky.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmSubtractSky.c
r2777 r2810 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-12-2 1 20:41:29$8 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-12-23 20:27:51 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 39 39 40 40 /****************************************************************************** 41 getHighestPriorityStatOption(statOptions): this routine takes as in put a41 getHighestPriorityStatOption(statOptions): this routine takes as input a 42 42 psStats->options with multiple options set and returns one with a single 43 43 option set according to the precedence set in the SDRS. … … 45 45 psU64 getHighestPriorityStatOption(psU64 statOptions) 46 46 { 47 switch (statOptions) { 48 case PS_STAT_SAMPLE_MEAN: 47 if (statOptions & PS_STAT_SAMPLE_MEAN) { 49 48 return(PS_STAT_SAMPLE_MEAN); 50 case PS_STAT_SAMPLE_MEDIAN:49 } else if (statOptions & PS_STAT_SAMPLE_MEDIAN) { 51 50 return(PS_STAT_SAMPLE_MEDIAN); 52 case PS_STAT_CLIPPED_MEAN:51 } else if (statOptions & PS_STAT_CLIPPED_MEAN) { 53 52 return(PS_STAT_CLIPPED_MEAN); 54 case PS_STAT_ROBUST_MEAN:53 } else if (statOptions & PS_STAT_ROBUST_MEAN) { 55 54 return(PS_STAT_ROBUST_MEAN); 56 case PS_STAT_ROBUST_MEDIAN:55 } else if (statOptions & PS_STAT_ROBUST_MEDIAN) { 57 56 return(PS_STAT_ROBUST_MEDIAN); 58 case PS_STAT_ROBUST_MODE:57 } else if (statOptions & PS_STAT_ROBUST_MODE) { 59 58 return(PS_STAT_ROBUST_MODE); 60 59 } 61 // psError(XXX);60 psError(PS_ERR_UNKNOWN, true, "Unallowable option requested for statistically binning image pixels.\n"); 62 61 return(-1); 63 62 } … … 129 128 /****************************************************************************** 130 129 CalculatePolyTerms(xOrder, yOrder): this routine will calculate the number of 131 coefficients (or terms) in a polynomial of order (xOrder, yOrder).130 coefficients (or terms) in a 2-D polynomial of order (xOrder, yOrder). 132 131 *****************************************************************************/ 133 132 psS32 CalculatePolyTerms(psS32 xOrder, psS32 yOrder) … … 187 186 } 188 187 189 // XXX: Get rid of this.190 for (i=0; i < localPolyTerms ; i++) {191 psTrace(".psModule.pmSubtractSky.buildPolyTerms", 6,192 "x^%d * y^%d\n", polyTerms[i][0], polyTerms[i][1]);188 if (psTraceGetLevel(".psModule.pmSubtractSky.buildPolyTerms") >= 10) { 189 for (i=0; i < localPolyTerms ; i++) { 190 printf("x^%d * y^%d\n", polyTerms[i][0], polyTerms[i][1]); 191 } 193 192 } 194 193 … … 198 197 /****************************************************************************** 199 198 This procedure calculates various combinations of powers of x and y and stores 200 them in the data structure sums[][]. After it completes:199 them in the data structure p_psPolySums[][]. After it completes: 201 200 202 sums[i][j] == x^i * y^j201 p_psPolySums[i][j] == x^i * y^j 203 202 204 XXX: Use a psImage for the sums data structure?205 XXX: Check for non-NULL sums argument?206 XXX: Check for positive x- and yOrder.207 XXX : Use variable size arrays for polynomial sums.203 XXX: Use a psImage for the p_psPolySums data structure? 204 XXX: Check for positive x- and y-Order. 205 XXX: Use variable size arrays for p_psPolySums[][]. 206 XXX" Must initialize p_psPolySums[][]? 208 207 *****************************************************************************/ 209 208 #define PS_MAX_POLYNOMIAL_ORDER 20 209 psF64 p_psPolySums[PS_MAX_POLYNOMIAL_ORDER+1][PS_MAX_POLYNOMIAL_ORDER+1]; 210 210 void buildSums(psF64 x, 211 211 psF64 y, 212 psF64 sums[PS_MAX_POLYNOMIAL_ORDER][PS_MAX_POLYNOMIAL_ORDER],213 212 psS32 xOrder, 214 213 psS32 yOrder) … … 224 223 ySum = xSum; 225 224 for(j=0;j<=yOrder;j++) { 226 sums[i][j] = ySum;225 p_psPolySums[i][j] = ySum; 227 226 ySum*= y; 228 227 } … … 232 231 233 232 /****************************************************************************** 234 ImageFitPolynomial(myPoly, binnedImage, maskImage): this private routine takes233 ImageFitPolynomial(myPoly, dataImage, maskImage): this private routine takes 235 234 an input image along with a mask and fits a polynomial to it. The degree of 236 235 the polynomial is specified by input parameter myPoly, and need not be … … 242 241 *****************************************************************************/ 243 242 psPolynomial2D *ImageFitPolynomial(psPolynomial2D *myPoly, 244 psImage * binnedImage,243 psImage *dataImage, 245 244 psImage *maskImage) 246 245 { … … 249 248 PS_POLY_CHECK_NULL(myPoly, NULL); 250 249 PS_POLY_CHECK_TYPE(myPoly, PS_POLYNOMIAL_ORD, NULL); 251 PS_IMAGE_CHECK_NULL( binnedImage, NULL);252 PS_IMAGE_CHECK_EMPTY( binnedImage, NULL);253 PS_IMAGE_CHECK_TYPE( binnedImage, PS_TYPE_F32, NULL);250 PS_IMAGE_CHECK_NULL(dataImage, NULL); 251 PS_IMAGE_CHECK_EMPTY(dataImage, NULL); 252 PS_IMAGE_CHECK_TYPE(dataImage, PS_TYPE_F32, NULL); 254 253 PS_IMAGE_CHECK_NULL(maskImage, NULL); 255 254 PS_IMAGE_CHECK_EMPTY(maskImage, NULL); 256 255 PS_IMAGE_CHECK_TYPE(maskImage, PS_TYPE_U8, NULL); 257 PS_IMAGE_CHECK_SIZE_EQUAL( binnedImage, maskImage, NULL);256 PS_IMAGE_CHECK_SIZE_EQUAL(dataImage, maskImage, NULL); 258 257 psS32 oldPolyX = -1; 259 258 psS32 oldPolyY = -1; … … 264 263 // polynomial if there are not enough rows/columns in the input image. 265 264 266 if (myPoly->nX > binnedImage->numRows) {265 if (myPoly->nX > dataImage->numRows) { 267 266 psLogMsg(__func__, PS_LOG_WARN, 268 267 "WARNING: ImageFitPolynomial(): Reducing polynomial complexity in x-dimension.\n"); 269 268 oldPolyX = myPoly->nX; 270 myPoly->nX = binnedImage->numRows;271 } 272 if (myPoly->nY > binnedImage->numCols) {269 myPoly->nX = dataImage->numRows; 270 } 271 if (myPoly->nY > dataImage->numCols) { 273 272 psLogMsg(__func__, PS_LOG_WARN, 274 273 "WARNING: ImageFitPolynomial(): Reducing polynomial complexity in y-dimension.\n"); 275 274 oldPolyY = myPoly->nY; 276 myPoly->nY = binnedImage->numCols;275 myPoly->nY = dataImage->numCols; 277 276 } 278 277 psS32 i; … … 282 281 psS32 aRow; 283 282 psS32 aCol; 284 // XXX: Document this.The myPoly->nX and ->nY terms are actually 1 larger283 // The myPoly->nX and ->nY terms are actually 1 larger 285 284 // than the order of the polynomial. 286 285 psS32 **polyTerms = buildPolyTerms(myPoly->nX-1, myPoly->nY-1); 286 // We determine how many coefficients will be in the polynomial that we 287 // are fitting to this image. 287 288 psS32 localPolyTerms = CalculatePolyTerms(myPoly->nX-1, myPoly->nY-1); 288 psF64 sums[PS_MAX_POLYNOMIAL_ORDER][PS_MAX_POLYNOMIAL_ORDER];289 289 psImage *A = psImageAlloc(localPolyTerms, localPolyTerms, PS_TYPE_F64); 290 290 psImage *Aout = psImageAlloc(localPolyTerms, localPolyTerms, PS_TYPE_F64); … … 295 295 // Initialize A matrix and B vector. 296 296 // 297 for(i=0;i<A->numRows;i++) { 298 for(j=0;j<A->numCols;j++) { 299 A->data.F64[i][j] = 0.0; 300 } 301 } 302 for(i=0;i<B->n;i++) { 303 B->data.F64[i] = 0.0; 304 } 305 297 PS_IMAGE_SET_F64(A, 0.0); 298 PS_VECTOR_SET_F64(B, 0.0); 306 299 307 300 // 308 301 // We build the A matrix and B vector. 309 302 // 310 for (x=0;x< binnedImage->numRows;x++) {311 for (y=0;y< binnedImage->numCols;y++) {303 for (x=0;x<dataImage->numRows;x++) { 304 for (y=0;y<dataImage->numCols;y++) { 312 305 if (maskImage->data.U8[x][y] == 0) { 313 buildSums((psF64) x, (psF64) y, sums,myPoly->nX-1, myPoly->nY-1);306 buildSums((psF64) x, (psF64) y, myPoly->nX-1, myPoly->nY-1); 314 307 315 308 /************************************************************ 309 This code dervies from equation (7) of the pilot ADD. However, 310 it is not exactly the same in that the order of the polynomial 311 may be different in X And Y. 312 316 313 Equation (7) from the pilot ADD describes 16 linear equations. 317 314 The i-th equation is simply the partial derivative of the … … 325 322 for (aCol=0;aCol<localPolyTerms;aCol++) { 326 323 A->data.F64[aRow][aCol]+= 327 ( sums[ polyTerms[aCol][0] ][ polyTerms[aCol][1] ] *328 sums[ polyTerms[aRow][0] ][ polyTerms[aRow][1] ]);324 (p_psPolySums[ polyTerms[aCol][0] ][ polyTerms[aCol][1] ] * 325 p_psPolySums[ polyTerms[aRow][0] ][ polyTerms[aRow][1] ]); 329 326 } 330 327 } 331 328 // Build the B[] vector, which is the right-hand side of (7). 332 329 for (i=0;i<localPolyTerms;i++) { 333 B->data.F64[i]+= binnedImage->data.F32[x][y] *334 sums[ polyTerms[i][0] ][ polyTerms[i][1] ];330 B->data.F64[i]+= dataImage->data.F32[x][y] * 331 p_psPolySums[ polyTerms[i][0] ][ polyTerms[i][1] ]; 335 332 } 336 333 } … … 338 335 } 339 336 340 // XXX: Put this loop inside a psTrace conditional, somehow.341 for (aRow=0;aRow<localPolyTerms;aRow++) {342 for (aCol=0;aCol<localPolyTerms;aCol++) {343 psTrace(".psModule.pmSubtractSky.ImageFitPolynomial", 8,344 "A[%d][%d] is %f\n", aRow, aCol,A->data.F64[aRow][aCol]);345 }346 }347 // XXX: Put this loop inside a psTrace conditional, somehow. 348 for (i=0;i<=localPolyTerms;i++) {349 psTrace(".psModule.pmSubtractSky.ImageFitPolynomial", 6,350 "B[%d] is %f\n", i, B->data.F64[i]);337 if (psTraceGetLevel(".psModule.pmSubtractSky.ImageFitPolynomial") >= 8) { 338 for (aRow=0;aRow<localPolyTerms;aRow++) { 339 for (aCol=0;aCol<localPolyTerms;aCol++) { 340 printf("A[%d][%d] is %f\n", aRow, aCol, 341 A->data.F64[aRow][aCol]); 342 } 343 } 344 345 for (i=0;i<=localPolyTerms;i++) { 346 printf("B[%d] is %f\n", i, B->data.F64[i]); 347 } 351 348 } 352 349 353 350 // 354 351 // Solve the matrix equations for the polynomial coefficients C. 352 // XXX: How do we know if these matrix operations were successful? 355 353 // 356 354 Aout = psMatrixLUD(Aout, outPerm, A); 355 PS_IMAGE_CHECK_NULL(Aout, NULL); 356 PS_IMAGE_CHECK_EMPTY(Aout, NULL); 357 357 psVector *C = psVectorAlloc(localPolyTerms, PS_TYPE_F64); 358 358 psMatrixLUSolve(C, Aout, B, outPerm); … … 382 382 // 383 383 // We restore the original size of the polynomial and set remaining 384 // coefficients to 0.0 .384 // coefficients to 0.0, if necessary. 385 385 // 386 386 if (oldPolyX != -1) { … … 424 424 psTrace(".psModule.pmSubtractSky", 4, 425 425 "---- pmSubtractSky() begin ----\n"); 426 psStatsOptions statOptions = 0; 426 427 427 428 // Return the original input readout if the fit specs are poorly defined. … … 439 440 // Determine which statistic to use when binning pixels, if any. 440 441 // 441 psStatsOptions statOptions = stats->options; 442 if (1 < p_psDetermineNumBits(statOptions)) { 443 //XXX psWarning(PS_ERR_UNKNOWN,true, "Multiple statistical options have been requested.\n"); 444 statOptions = getHighestPriorityStatOption(statOptions); 445 // XXX: Don't modify input parameter. 446 oldStatOptions = stats->options; 447 stats->options = statOptions; 448 } 449 if (0 >= p_psDetermineNumBits(statOptions)) { 450 psLogMsg(__func__, PS_LOG_WARN, 451 "WARNING: pmSubtractSky(): no stats->options was requested\n"); 452 return(in); 442 if (stats != NULL) { 443 statOptions = stats->options; 444 if (1 < p_psDetermineNumBits(statOptions)) { 445 psLogMsg(__func__, PS_LOG_WARN, "WARNING: Multiple statistical options have been requested.\n"); 446 statOptions = getHighestPriorityStatOption(statOptions); 447 448 // Save old input "stats" parameter. 449 oldStatOptions = stats->options; 450 stats->options = statOptions; 451 } 452 if (0 == p_psDetermineNumBits(statOptions)) { 453 psLogMsg(__func__, PS_LOG_WARN, 454 "WARNING: pmSubtractSky(): no stats->options was requested\n"); 455 } 453 456 } 454 457 … … 456 459 // Generate required warning messages. 457 460 // 458 if (0 == p_psDetermineNumBits(statOptions)) {459 psLogMsg(__func__, PS_LOG_WARN,460 "WARNING: pmSubtractSky(): no stats->options was requested\n");461 }462 461 if (binFactor <= 0) { 463 462 psLogMsg(__func__, PS_LOG_WARN, … … 558 557 } 559 558 } else { 560 //XXX: error 559 // We shouldn't get here since we check this above. 560 psError(PS_ERR_UNKNOWN, true, "Unallowable fit type."); 561 561 } 562 562
Note:
See TracChangeset
for help on using the changeset viewer.
