- Timestamp:
- Feb 22, 2008, 9:18:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_080214/psModules/src/imcombine/pmStack.c
r16420 r16600 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $11 * @date $Date: 2008-02- 13 02:55:33$10 * @version $Revision: 1.16.2.1 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2008-02-22 19:18:11 $ 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 13 13 * … … 23 23 #include "pmHDU.h" 24 24 #include "pmFPA.h" 25 #include "pmReadoutStack.h" 25 26 #include "pmConceptsAverage.h" 26 27 … … 42 43 psVector *weights; // Pixel weights 43 44 psVector *sort; // Buffer for sorting (to get a robust estimator of the standard dev) 45 #if 0 46 int x0, y0; // Offset from original image to combination region 47 int nx, ny; // Number of pixels to combine 48 #endif 44 49 } combineBuffer; 45 50 … … 64 69 buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32); 65 70 buffer->sort = psVectorAlloc(numImages, PS_TYPE_F32); 71 72 #if 0 73 buffer->x0 = 0; 74 buffer->y0 = 0; 75 buffer->nx = 0; 76 buffer->ny = 0; 77 #endif 66 78 67 79 return buffer; … … 136 148 return false; 137 149 } 138 *median = num % 2 ? (sortBuffer->data.F32[num / 2] + sortBuffer->data.F32[num / 2 + 1]) / 2.0 : 139 sortBuffer->data.F32[num / 2]; 140 *stdev = 0.74 * (sortBuffer->data.F32[(int)(0.75 * num)] - sortBuffer->data.F32[(int)(0.25 * num)]); 150 *median = num % 2 ? sortBuffer->data.F32[num / 2] : 151 (sortBuffer->data.F32[num / 2] + sortBuffer->data.F32[num / 2 + 1]) / 2.0 ; 152 #if 0 153 if (num < NUM_DIRECT_STDEV) { 154 #endif 155 // If there are not many values, the direct standard deviation is better 156 double sum = 0.0; 157 for (int i = 0; i < num; i++) { 158 sum += PS_SQR(sortBuffer->data.F32[i] - *median); 159 } 160 *stdev = sqrt(sum / (float)(num - 1)); 161 #if 0 162 } else { 163 *stdev = 0.74 * (sortBuffer->data.F32[(int)(0.75 * num)] - sortBuffer->data.F32[(int)(0.25 * num)]); 164 } 165 #endif 141 166 142 167 return true; … … 186 211 187 212 // Given a stack of images, combine with optional rejection. 188 // Pixels in the stack that are rejected are marked for subsequent 213 // Pixels in the stack that are rejected are marked for subsequent inspection 189 214 static bool combinePixels(psImage *image, // Combined image, for output 190 215 psImage *mask, // Combined mask, for output … … 193 218 const psVector *weights, // Global (single value) weights for data, or NULL 194 219 const psVector *reject, // Indices of pixels to reject, or NULL 195 int x, int y, // Coordinates of interest 220 int x, int y, // Coordinates of interest; frame of output image 196 221 psMaskType maskVal, // Value to mask 197 222 psMaskType bad, // Value to give bad pixels … … 223 248 continue; 224 249 } 250 int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout 225 251 psImage *image = data->readout->image; // Image of interest 226 252 psImage *weight = data->readout->weight; // Weight map of interest 227 253 psImage *mask = data->readout->mask; // Mask of interest 228 pixelData->data.F32[i] = image->data.F32[y ][x];254 pixelData->data.F32[i] = image->data.F32[yIn][xIn]; 229 255 if (weight) { 230 pixelWeights->data.F32[i] = weight->data.F32[y ][x];231 } 232 pixelMasks->data.PS_TYPE_MASK_DATA[i] = mask->data.PS_TYPE_MASK_DATA[y ][x];256 pixelWeights->data.F32[i] = weight->data.F32[yIn][xIn]; 257 } 258 pixelMasks->data.PS_TYPE_MASK_DATA[i] = mask->data.PS_TYPE_MASK_DATA[yIn][xIn]; 233 259 if (pixelMasks->data.PS_TYPE_MASK_DATA[i] & maskVal) { 234 260 numBad++; … … 567 593 } 568 594 595 // Get the sizes 596 psArray *stack = psArrayAlloc(input->n); 597 for (int i = 0; i < stack->n; i++) { 598 pmStackData *data = input->data[i]; // Stack data 599 stack->data[i] = psMemIncrRefCounter(data->readout); 600 } 601 int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine 602 int xSize, ySize; // Size of the output image 603 if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize, 604 stack)) { 605 psError(PS_ERR_UNKNOWN, false, "Input stack is not valid."); 606 psFree(stack); 607 return false; 608 } 609 psFree(stack); 610 pmReadoutUpdateSize(combined, minInputCols, minInputRows, xSize, ySize, true, true, bad); 611 psTrace("psModules.imcombine", 1, "Combining [%d:%d,%d:%d] (%dx%d)\n", 612 minInputCols, maxInputCols, minInputRows, maxInputRows, xSize, ySize); 613 614 569 615 // Buffer for combination 570 616 combineBuffer *buffer = combineBufferAlloc(num, numIter == 0 ? PS_STAT_SAMPLE_MEAN : … … 577 623 psImage *combinedWeight = combined->weight; // Combined mask 578 624 579 psArray *pixelMap = pixelMapGenerate(input, numCols, numRows); // Map of pixels to source625 psArray *pixelMap = pixelMapGenerate(input, maxInputCols, maxInputRows); // Map of pixels to source 580 626 psPixels *pixels = NULL; // Total list of pixels, with no duplicates 581 627 for (int i = 0; i < num; i++) { … … 588 634 } 589 635 for (int i = 0; i < pixels->n; i++) { 636 // Pixel coordinates are in the frame of the original image 590 637 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest 638 if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) { 639 continue; 640 } 591 641 psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely 592 642 combinePixels(combinedImage, combinedMask, combinedWeight, input, weights, reject, x, y, … … 626 676 } 627 677 628 for (int y = 0; y < numRows; y++) {629 for (int x = 0; x < numCols; x++) {678 for (int y = minInputRows; y < maxInputRows; y++) { 679 for (int x = minInputCols; x < maxInputCols; x++) { 630 680 combinePixels(combinedImage, combinedMask, combinedWeights, input, weights, NULL, x, y, 631 681 maskVal, bad, numIter, rej, buffer);
Note:
See TracChangeset
for help on using the changeset viewer.
