Changeset 2848
- Timestamp:
- Dec 29, 2004, 12:44:33 PM (22 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 2 edited
-
pmSubtractBias.c (modified) (8 diffs)
-
pmSubtractSky.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmSubtractBias.c
r2845 r2848 6 6 * @author George Gusciora, MHPCC 7 7 * 8 * @version $Revision: 1.2 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-12-29 2 1:18:33 $8 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-12-29 22:44:33 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 205 205 for (i=0;i<n;i++) { 206 206 x = ((float) i) * ((float) overscanVector->n) / ((float) n); 207 newVec->data.F32[i] = psSpline1DEval( x, mySpline);207 newVec->data.F32[i] = psSpline1DEval(mySpline, x); 208 208 } 209 209 } else { … … 234 234 return(in); 235 235 } 236 237 // Check for an unallowable pmFit. 236 238 if ((fit != PM_OVERSCAN_NONE) && 237 239 (fit != PM_OVERSCAN_ROWS) && … … 241 243 return(in); 242 244 } 245 // Check for an unallowable pmOverscanAxis. 243 246 if ((overScanAxis != PM_OVERSCAN_NONE) && 244 247 (overScanAxis != PM_OVERSCAN_ROWS) && … … 259 262 double statValue; 260 263 psImage *myOverscanImage = NULL; 261 psPolynomial1D *myPoly ;262 psSpline1D *mySpline ;264 psPolynomial1D *myPoly = NULL; 265 psSpline1D *mySpline = NULL; 263 266 int nBin; 264 267 // XXX: This comment isn't right? … … 308 311 } 309 312 313 // This check is redundant with above code. 314 if (!((overScanAxis == PM_OVERSCAN_ROWS) || (overScanAxis == PM_OVERSCAN_COLUMNS))) { 315 psError(PS_ERR_UNKNOWN, true, "overScanAxis is unallowable (%d)\n", overScanAxis); 316 return(in); 317 } 310 318 311 319 tmpOverscan = (psListElem *) overscans->head; … … 313 321 myOverscanImage = (psImage *) tmpOverscan->data; 314 322 315 // XXX: Is there a better way to extract a psVector from a psImage without 316 // having to copy every element in that vector? 317 // XXX: If we get here, do we know that overScanAxis == PM_OVERSCAN_ROWS 318 // or PM_OVERSCAN_COL? 319 320 if ((overScanAxis == PM_OVERSCAN_ROWS) || (overScanAxis == PM_OVERSCAN_COLUMNS)) { 321 if (overScanAxis == PM_OVERSCAN_ROWS) { 322 if (myOverscanImage->numCols != (in->image)->numCols) { 323 psLogMsg(__func__, PS_LOG_WARN, 324 "WARNING: pmSubtractBias.(): overscan image has %d columns, input image has %d columns\n", 325 myOverscanImage->numCols, in->image->numCols); 326 } 327 // We create a row vector and subtract this vector from image. 328 overscanVector = psVectorAlloc(myOverscanImage->numCols, PS_TYPE_F32); 329 for (i=0;i<overscanVector->n;i++) { 330 overscanVector->data.F32[i] = 0.0; 331 } 332 tmpRow = psVectorAlloc((in->image)->numRows, PS_TYPE_F32); 333 334 for (i=0;i<myOverscanImage->numCols;i++) { 335 for (j=0;j<myOverscanImage->numRows;j++) { 336 tmpRow->data.F32[j] = myOverscanImage->data.F32[j][i]; 337 } 338 stat = psVectorStats(stat, tmpRow, NULL, NULL, 0); 339 p_psGetStatValue(stat, &statValue); 340 overscanVector->data.F32[i] = statValue; 341 } 342 psFree(tmpRow); 323 if (overScanAxis == PM_OVERSCAN_ROWS) { 324 if (myOverscanImage->numCols != (in->image)->numCols) { 325 psLogMsg(__func__, PS_LOG_WARN, 326 "WARNING: pmSubtractBias.(): overscan image has %d columns, input image has %d columns\n", 327 myOverscanImage->numCols, in->image->numCols); 328 } 329 330 // We create a row vector and subtract this vector from image. 331 // XXX: Is there a better way to extract a psVector from a psImage without 332 // having to copy every element in that vector? 333 overscanVector = psVectorAlloc(myOverscanImage->numCols, PS_TYPE_F32); 334 for (i=0;i<overscanVector->n;i++) { 335 overscanVector->data.F32[i] = 0.0; 336 } 337 tmpRow = psVectorAlloc((in->image)->numRows, PS_TYPE_F32); 338 339 // For each column of the input image, loop through every row, 340 // collect the pixel in that row, then performed the specified 341 // statistical op on those pixels. Store this in overscanVector. 342 for (i=0;i<myOverscanImage->numCols;i++) { 343 for (j=0;j<myOverscanImage->numRows;j++) { 344 tmpRow->data.F32[j] = myOverscanImage->data.F32[j][i]; 345 } 346 stat = psVectorStats(stat, tmpRow, NULL, NULL, 0); 347 p_psGetStatValue(stat, &statValue); 348 overscanVector->data.F32[i] = statValue; 349 } 350 psFree(tmpRow); 351 352 // Scale the overscan vector to the size of the input image. 353 if (overscanVector->n != in->image->numCols) { 343 354 if ((fit == PM_FIT_POLYNOMIAL) || (fit == PM_FIT_SPLINE)) { 344 355 psVector *newVec = ScaleOverscanVector(overscanVector, 345 (in->image)->numCols,356 in->image->numCols, 346 357 fitSpec, fit); 347 358 psFree(overscanVector); 348 359 overscanVector = newVec; 349 } 350 } 351 352 if (overScanAxis == PM_OVERSCAN_COLUMNS) { 353 // We create a column vector and subtract this vector from image. 354 if (myOverscanImage->numRows != (in->image)->numRows) { 355 psLogMsg(__func__, PS_LOG_WARN, 356 "WARNING: pmSubtractBias.(): overscan image has %d rows, input image has %d rows\n", 357 myOverscanImage->numRows, in->image->numRows); 358 } 359 overscanVector = psVectorAlloc(myOverscanImage->numRows, PS_TYPE_F32); 360 for (i=0;i<overscanVector->n;i++) { 361 overscanVector->data.F32[i] = 0.0; 362 } 363 tmpCol = psVectorAlloc((in->image)->numCols, PS_TYPE_F32); 364 365 for (i=0;i<myOverscanImage->numRows;i++) { 366 for (j=0;j<myOverscanImage->numCols;j++) { 367 tmpCol->data.F32[j] = myOverscanImage->data.F32[i][j]; 368 } 369 stat = psVectorStats(stat, tmpCol, NULL, NULL, 0); 370 p_psGetStatValue(stat, &statValue); 371 overscanVector->data.F32[i] = statValue; 372 } 373 374 psFree(tmpCol); 360 } else { 361 psError(PS_ERR_UNKNOWN, true, "Don't know how to scale the overscan vector. Set fit to PM_FIT_SPLINE or PM_FIT_POLYNOMIAL.\n"); 362 psFree(overscanVector); 363 return(in); 364 } 365 } 366 } 367 368 if (overScanAxis == PM_OVERSCAN_COLUMNS) { 369 if (myOverscanImage->numRows != (in->image)->numRows) { 370 psLogMsg(__func__, PS_LOG_WARN, 371 "WARNING: pmSubtractBias.(): overscan image has %d rows, input image has %d rows\n", 372 myOverscanImage->numRows, in->image->numRows); 373 } 374 375 // We create a column vector and subtract this vector from image. 376 overscanVector = psVectorAlloc(myOverscanImage->numRows, PS_TYPE_F32); 377 for (i=0;i<overscanVector->n;i++) { 378 overscanVector->data.F32[i] = 0.0; 379 } 380 tmpCol = psVectorAlloc((in->image)->numCols, PS_TYPE_F32); 381 382 // For each row of the input image, loop through every column, 383 // collect the pixel in that row, then performed the specified 384 // statistical op on those pixels. Store this in overscanVector. 385 for (i=0;i<myOverscanImage->numRows;i++) { 386 for (j=0;j<myOverscanImage->numCols;j++) { 387 tmpCol->data.F32[j] = myOverscanImage->data.F32[i][j]; 388 } 389 stat = psVectorStats(stat, tmpCol, NULL, NULL, 0); 390 p_psGetStatValue(stat, &statValue); 391 overscanVector->data.F32[i] = statValue; 392 } 393 psFree(tmpCol); 394 395 // Scale the overscan vector to the size of the input image. 396 if (overscanVector->n != in->image->numRows) { 375 397 if ((fit == PM_FIT_POLYNOMIAL) || (fit == PM_FIT_SPLINE)) { 376 398 psVector *newVec = ScaleOverscanVector(overscanVector, 377 (in->image)->numRows,399 in->image->numRows, 378 400 fitSpec, fit); 379 401 psFree(overscanVector); 380 402 overscanVector = newVec; 381 } 382 } 383 384 // 385 // Re-bin the overscan vector (change its length). 386 // 387 if ((nBinOrig > 0) && (nBinOrig < overscanVector->n)) { 388 numBins = 1+((overscanVector->n)/nBinOrig); 389 myBin = psVectorAlloc(numBins, PS_TYPE_F32); 390 binVec = psVectorAlloc(nBinOrig, PS_TYPE_F32); 391 392 for (i=0;i<numBins;i++) { 393 for(j=0;j<nBinOrig;j++) { 394 if (overscanVector->n > ((i*nBinOrig)+j)) { 395 binVec->data.F32[j] = overscanVector->data.F32[(i*nBinOrig)+j]; 396 } else { 397 // XXX: we get here if nBinOrig does not evenly divide 398 // the overscanVector vector. This is the last bin. Should 399 // we change the binVec->n to acknowledge that? 400 binVec->n = j; 401 } 402 } 403 stat = psVectorStats(stat, binVec, NULL, NULL, 0); 404 p_psGetStatValue(stat, &statValue); 405 myBin->data.F32[i] = statValue; 406 } 407 408 // Change the effective size of overscanVector. 409 overscanVector->n = numBins; 410 for (i=0;i<numBins;i++) { 411 overscanVector->data.F32[i] = myBin->data.F32[i]; 412 } 413 psFree(binVec); 414 psFree(myBin); 415 nBin = nBinOrig; 416 } else { 417 nBin = 1; 418 } 419 420 // 421 // Fit a polynomial to the overscan vector. 422 // 423 if (!((fitSpec == NULL) || (fit == PM_FIT_NONE))) { 424 if (fit == PM_FIT_POLYNOMIAL) { 425 myPoly = (psPolynomial1D *) fitSpec; 426 myPoly = psVectorFitPolynomial1D(myPoly, NULL, overscanVector, NULL); 427 for (i=0;i<numBins;i++) { 428 overscanVector->data.F32[i] = psPolynomial1DEval(myPoly, (float) i); 429 } 430 431 } else if (fit == PM_FIT_SPLINE) { 432 mySpline = (psSpline1D *) fitSpec; 433 // XXX: The spline functions do not work if the number of 434 // data points and the number of splines are not equal. 435 } 436 } 403 } else { 404 psError(PS_ERR_UNKNOWN, true, "Don't know how to scale the overscan vector. Set fit to PM_FIT_SPLINE or PM_FIT_POLYNOMIAL.\n"); 405 psFree(overscanVector); 406 return(in); 407 } 408 } 409 } 410 411 // 412 // Re-bin the overscan vector (change its length). 413 // 414 if ((nBinOrig > 0) && (nBinOrig < overscanVector->n)) { 415 numBins = 1+((overscanVector->n)/nBinOrig); 416 myBin = psVectorAlloc(numBins, PS_TYPE_F32); 417 binVec = psVectorAlloc(nBinOrig, PS_TYPE_F32); 418 419 for (i=0;i<numBins;i++) { 420 for(j=0;j<nBinOrig;j++) { 421 if (overscanVector->n > ((i*nBinOrig)+j)) { 422 binVec->data.F32[j] = overscanVector->data.F32[(i*nBinOrig)+j]; 423 } else { 424 // XXX: we get here if nBinOrig does not evenly divide 425 // the overscanVector vector. This is the last bin. Should 426 // we change the binVec->n to acknowledge that? 427 binVec->n = j; 428 } 429 } 430 stat = psVectorStats(stat, binVec, NULL, NULL, 0); 431 p_psGetStatValue(stat, &statValue); 432 myBin->data.F32[i] = statValue; 433 } 434 435 // Change the effective size of overscanVector. 436 overscanVector->n = numBins; 437 for (i=0;i<numBins;i++) { 438 overscanVector->data.F32[i] = myBin->data.F32[i]; 439 } 440 psFree(binVec); 441 psFree(myBin); 442 nBin = nBinOrig; 443 } else { 444 nBin = 1; 445 } 446 447 // At this point the number of data points in overscanVector should be 448 // equal to the number of rows/columns (whatever is appropriate) in the 449 // image divided by numBins. 450 // 451 if (!((fitSpec == NULL) || (fit == PM_FIT_NONE))) { 452 // 453 // Fit a polynomial or spline to the overscan vector. 454 // 455 if (fit == PM_FIT_POLYNOMIAL) { 456 myPoly = (psPolynomial1D *) fitSpec; 457 myPoly = psVectorFitPolynomial1D(myPoly, NULL, overscanVector, NULL); 458 if (myPoly == NULL) { 459 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to overscan vector.\n"); 460 psFree(overscanVector); 461 return(in); 462 } 463 } else if (fit == PM_FIT_SPLINE) { 464 mySpline = (psSpline1D *) fitSpec; 465 mySpline = psVectorFitSpline1D(mySpline, NULL, overscanVector, NULL); 466 if (mySpline == NULL) { 467 psError(PS_ERR_UNKNOWN, false, "Could not fit a spline to overscan vector.\n"); 468 psFree(overscanVector); 469 return(in); 470 } 471 } 472 473 // 474 // Subtract fitted overscan vector row-wise from the image. 475 // 476 if (overScanAxis == PM_OVERSCAN_ROWS) { 477 for (i=0;i<(in->image)->numCols;i++) { 478 psF32 tmpF32 = 0.0; 479 if (fit == PM_FIT_POLYNOMIAL) { 480 tmpF32 = psPolynomial1DEval(myPoly, ((float) i) / ((float) nBin)); 481 } else if (fit == PM_FIT_SPLINE) { 482 tmpF32 = psSpline1DEval(mySpline, ((float) i) / ((float) nBin)); 483 } 484 485 for (j=0;j<(in->image)->numRows;j++) { 486 (in->image)->data.F32[j][i]-= tmpF32; 487 488 } 489 } 490 } 491 492 // 493 // Subtract fitted overscan vector column-wise from the image. 494 // 495 if (overScanAxis == PM_OVERSCAN_COLUMNS) { 496 for (i=0;i<(in->image)->numRows;i++) { 497 psF32 tmpF32 = 0.0; 498 if (fit == PM_FIT_POLYNOMIAL) { 499 tmpF32 = psPolynomial1DEval(myPoly, ((float) i) / ((float) nBin)); 500 } else if (fit == PM_FIT_SPLINE) { 501 tmpF32 = psSpline1DEval(mySpline, ((float) i) / ((float) nBin)); 502 } 503 504 for (j=0;j<(in->image)->numCols;j++) { 505 (in->image)->data.F32[i][j]-= tmpF32; 506 } 507 } 508 } 509 } else { 510 // If we get here, then no polynomials were fit to the overscan 511 // vector. We simply subtract it, taking into account binning, 512 // from the image. 437 513 438 514 // … … 457 533 } 458 534 } 459 psFree(overscanVector); 460 } 535 } 536 537 psFree(overscanVector); 538 461 539 tmpOverscan = tmpOverscan->next; 462 540 } 463 464 541 465 542 psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4, -
trunk/psModules/src/pmSubtractSky.c
r2845 r2848 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-12-29 2 1:18:33 $8 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-12-29 22:44:33 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 423 423 psTrace(".psModule.pmSubtractSky", 4, 424 424 "---- pmSubtractSky() begin ----\n"); 425 425 426 if ((fit != PM_FIT_NONE) && 426 427 (fit != PM_FIT_POLYNOMIAL) &&
Note:
See TracChangeset
for help on using the changeset viewer.
