Changeset 17005
- Timestamp:
- Mar 17, 2008, 11:38:43 AM (18 years ago)
- Location:
- trunk/psModules/src/imcombine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r16848 r17005 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $11 * @date $Date: 2008-03- 06 21:38:39$10 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2008-03-17 21:38:43 $ 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 13 13 * … … 80 80 { 81 81 psFree(data->readout); 82 psFree(data->pixels); 82 psFree(data->reject); 83 psFree(data->inspect); 83 84 return; 84 85 } … … 172 173 } else { 173 174 *median = num % 2 ? sortBuffer->data.F32[num / 2] : 174 (sortBuffer->data.F32[num / 2 ] + sortBuffer->data.F32[num / 2 + 1]) / 2.0;175 (sortBuffer->data.F32[num / 2 - 1] + sortBuffer->data.F32[num / 2]) / 2.0; 175 176 if (stdev) { 176 177 if (num <= NUM_DIRECT_STDEV) { … … 180 181 sum += PS_SQR(sortBuffer->data.F32[i] - *median); 181 182 } 182 *stdev = sqrt(sum / ( float)(num - 1));183 *stdev = sqrt(sum / (double)(num - 1)); 183 184 } else { 184 185 // Standard deviation from the interquartile range … … 201 202 pmStackData *data = inputs->data[source]; // Stack data of interest 202 203 if (!data) { 204 psWarning("Can't find input data for source %d", source); 203 205 return; 204 206 } 205 data-> pixels = psPixelsAdd(data->pixels, PIXEL_LIST_BUFFER, x, y);207 data->inspect = psPixelsAdd(data->inspect, PIXEL_LIST_BUFFER, x, y); 206 208 return; 207 209 } … … 391 393 // Ensure the input array of pmStackData is valid, and get some details out of it 392 394 static bool validateInputData(bool *haveVariances, // Do we have variance maps in the sky images? 393 bool *have Pixels, // Do we have lists ofpixels?395 bool *haveRejects, // Do we have lists of rejected pixels? 394 396 int *num, // Number of inputs 395 397 int *numCols, int *numRows, // Size of (sky) images … … 420 422 PS_ASSERT_IMAGE_TYPE(data->readout->weight, PS_TYPE_F32, false); 421 423 } 422 *have Pixels = (data->pixels!= NULL);424 *haveRejects = (data->reject != NULL); 423 425 424 426 // Make sure the rest correspond with the first … … 433 435 return false; 434 436 } 435 if ((*havePixels && !data->pixels) || (data->pixels && !*havePixels)) { 436 psError(PS_ERR_UNEXPECTED_NULL, true, "The pixels are specified in some but not all inputs."); 437 if ((*haveRejects && !data->reject) || (data->reject && !*haveRejects)) { 438 psError(PS_ERR_UNEXPECTED_NULL, true, 439 "The rejected pixels are specified in some but not all inputs."); 437 440 return false; 438 441 } … … 473 476 continue; 474 477 } 475 assert(data-> pixels);476 psPixels *pixels = data-> pixels;// The pixels of interest478 assert(data->reject); 479 psPixels *pixels = data->reject; // The rejected pixels 477 480 for (int j = 0; j < pixels->n; j++) { 478 481 int x = pixels->data[j].x, y = pixels->data[j].y; // Coordinates of interest … … 518 521 519 522 data->readout = psMemIncrRefCounter(readout); 520 data->pixels = NULL; 523 data->reject = NULL; 524 data->inspect = NULL; 521 525 data->weight = weight; 522 526 … … 526 530 /// Stack input images 527 531 bool pmStackCombine(pmReadout *combined, psArray *input, psMaskType maskVal, psMaskType bad, 528 int kernelSize, int numIter, float rej, bool useVariance, bool safe)532 int kernelSize, int numIter, float rej, bool entire, bool useVariance, bool safe) 529 533 { 530 534 PS_ASSERT_PTR_NON_NULL(combined, false); 531 535 bool haveVariances; // Do we have the variance maps? 532 bool have Pixels; // Do we have lists ofpixels?536 bool haveRejects; // Do we have lists of rejected pixels? 533 537 int num; // Number of inputs 534 538 int numCols, numRows; // Size of (sky) images 535 if (!validateInputData(&haveVariances, &have Pixels, &num, &numCols, &numRows, input)) {539 if (!validateInputData(&haveVariances, &haveRejects, &num, &numCols, &numRows, input)) { 536 540 return false; 537 541 } … … 544 548 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false); 545 549 } 546 if (have Pixels) {550 if (haveRejects) { 547 551 // This is a subsequent combination, so expect that the image and mask already exist 548 552 PS_ASSERT_IMAGE_NON_NULL(combined->image, false); … … 557 561 } 558 562 559 // Pull out the image weightings560 ps Vector *weights = psVectorAlloc(num, PS_TYPE_F32);563 psVector *weights = psVectorAlloc(num, PS_TYPE_F32); // Relative weighting for each image 564 psArray *stack = psArrayAlloc(num); // Stack of readouts 561 565 for (int i = 0; i < num; i++) { 562 566 pmStackData *data = input->data[i]; // Stack data for this input 563 567 if (!data) { 564 568 weights->data.F32[i] = 0.0; 569 continue; 565 570 } 566 571 weights->data.F32[i] = data->weight; 567 }568 569 // Get the sizes570 psArray *stack = psArrayAlloc(input->n);571 for (int i = 0; i < stack->n; i++) {572 pmStackData *data = input->data[i]; // Stack data573 572 stack->data[i] = psMemIncrRefCounter(data->readout); 574 573 } 574 575 575 int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine 576 576 int xSize, ySize; // Size of the output image … … 598 598 combineBuffer *buffer = combineBufferAlloc(num); 599 599 600 if (havePixels) { 601 // Only combine select pixels 600 if (haveRejects) { 602 601 psImage *combinedImage = combined->image; // Combined image 603 602 psImage *combinedMask = combined->mask; // Combined mask … … 611 610 continue; 612 611 } 613 pixels = psPixelsConcatenate(pixels, data->pixels); 614 } 615 for (int i = 0; i < pixels->n; i++) { 616 // Pixel coordinates are in the frame of the original image 617 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest 618 if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) { 619 continue; 620 } 621 psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely 622 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y, 623 maskVal, bad, numIter, rej, useVariance, safe, buffer); 612 pixels = psPixelsConcatenate(pixels, data->reject); 613 } 614 615 if (entire) { 616 // Combine entire image 617 for (int y = minInputRows; y < maxInputRows; y++) { 618 for (int x = minInputCols; x < maxInputCols; x++) { 619 psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely 620 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y, 621 maskVal, bad, numIter, rej, useVariance, safe, buffer); 622 } 623 } 624 } else { 625 // Only combine previously rejected pixels 626 for (int i = 0; i < pixels->n; i++) { 627 // Pixel coordinates are in the frame of the original image 628 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest 629 if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) { 630 continue; 631 } 632 psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely 633 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y, 634 maskVal, bad, numIter, rej, useVariance, safe, buffer); 635 } 624 636 } 625 637 psFree(pixels); … … 644 656 } 645 657 646 // Generate the pixel lists in which to place the rejected pixels647 if (numIter != 0) {648 for (int i = 0; i < num; i++) {649 pmStackData *data = input->data[i]; // Stack data for this input650 if (!data) {651 continue;652 }653 data->pixels = psPixelsAllocEmpty(PIXEL_LIST_BUFFER);654 }655 }656 657 658 for (int y = minInputRows; y < maxInputRows; y++) { 658 659 for (int x = minInputCols; x < maxInputCols; x++) { … … 669 670 continue; 670 671 } 671 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data-> pixels->n);672 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->inspect->n); 672 673 } 673 674 } -
trunk/psModules/src/imcombine/pmStack.h
r16685 r17005 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $11 * @date $Date: 2008-0 2-27 21:16:57$10 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2008-03-17 21:38:43 $ 12 12 * 13 13 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 28 28 typedef struct { 29 29 pmReadout *readout; ///< Warped readout (sky cell) 30 psPixels *pixels; ///< Pixels to inspect or reject 31 float weight; ///< Weight to apply 30 psPixels *reject; ///< Pixels to reject 31 psPixels *inspect; ///< Pixels to inspect 32 float weight; ///< Relative weighting for image 32 33 } pmStackData; 33 34 … … 45 46 int numIter, ///< Number of iterations 46 47 float rej, ///< Rejection limit (standard deviations) 48 bool entire, ///< Combine entire image even if rejection lists provided? 47 49 bool useVariance, ///< Use variance values for rejection? 48 50 bool safe ///< Play safe with small numbers of input pixels (mask if N <= 2)?
Note:
See TracChangeset
for help on using the changeset viewer.
