Changeset 16604 for trunk/psModules/src/imcombine/pmStack.c
- Timestamp:
- Feb 22, 2008, 9:24:42 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStack.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r16479 r16604 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $11 * @date $Date: 2008-02-14 23:33:09 $12 10 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 13 11 * … … 23 21 #include "pmHDU.h" 24 22 #include "pmFPA.h" 23 #include "pmReadoutStack.h" 25 24 #include "pmConceptsAverage.h" 26 25 … … 42 41 psVector *weights; // Pixel weights 43 42 psVector *sort; // Buffer for sorting (to get a robust estimator of the standard dev) 43 #if 0 44 int x0, y0; // Offset from original image to combination region 45 int nx, ny; // Number of pixels to combine 46 #endif 44 47 } combineBuffer; 45 48 … … 64 67 buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32); 65 68 buffer->sort = psVectorAlloc(numImages, PS_TYPE_F32); 69 70 #if 0 71 buffer->x0 = 0; 72 buffer->y0 = 0; 73 buffer->nx = 0; 74 buffer->ny = 0; 75 #endif 66 76 67 77 return buffer; … … 136 146 return false; 137 147 } 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)]); 148 *median = num % 2 ? sortBuffer->data.F32[num / 2] : 149 (sortBuffer->data.F32[num / 2] + sortBuffer->data.F32[num / 2 + 1]) / 2.0 ; 150 #if 0 151 if (num < NUM_DIRECT_STDEV) { 152 #endif 153 // If there are not many values, the direct standard deviation is better 154 double sum = 0.0; 155 for (int i = 0; i < num; i++) { 156 sum += PS_SQR(sortBuffer->data.F32[i] - *median); 157 } 158 *stdev = sqrt(sum / (float)(num - 1)); 159 #if 0 160 } else { 161 *stdev = 0.74 * (sortBuffer->data.F32[(int)(0.75 * num)] - sortBuffer->data.F32[(int)(0.25 * num)]); 162 } 163 #endif 141 164 142 165 return true; … … 186 209 187 210 // Given a stack of images, combine with optional rejection. 188 // Pixels in the stack that are rejected are marked for subsequent 211 // Pixels in the stack that are rejected are marked for subsequent inspection 189 212 static bool combinePixels(psImage *image, // Combined image, for output 190 213 psImage *mask, // Combined mask, for output … … 193 216 const psVector *weights, // Global (single value) weights for data, or NULL 194 217 const psVector *reject, // Indices of pixels to reject, or NULL 195 int x, int y, // Coordinates of interest 218 int x, int y, // Coordinates of interest; frame of output image 196 219 psMaskType maskVal, // Value to mask 197 220 psMaskType bad, // Value to give bad pixels … … 223 246 continue; 224 247 } 248 int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout 225 249 psImage *image = data->readout->image; // Image of interest 226 250 psImage *weight = data->readout->weight; // Weight map of interest 227 251 psImage *mask = data->readout->mask; // Mask of interest 228 pixelData->data.F32[i] = image->data.F32[y ][x];252 pixelData->data.F32[i] = image->data.F32[yIn][xIn]; 229 253 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];254 pixelWeights->data.F32[i] = weight->data.F32[yIn][xIn]; 255 } 256 pixelMasks->data.PS_TYPE_MASK_DATA[i] = mask->data.PS_TYPE_MASK_DATA[yIn][xIn]; 233 257 if (pixelMasks->data.PS_TYPE_MASK_DATA[i] & maskVal) { 234 258 numBad++; … … 563 587 } 564 588 589 // Get the sizes 590 psArray *stack = psArrayAlloc(input->n); 591 for (int i = 0; i < stack->n; i++) { 592 pmStackData *data = input->data[i]; // Stack data 593 stack->data[i] = psMemIncrRefCounter(data->readout); 594 } 595 int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine 596 int xSize, ySize; // Size of the output image 597 if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize, 598 stack)) { 599 psError(PS_ERR_UNKNOWN, false, "Input stack is not valid."); 600 psFree(stack); 601 return false; 602 } 603 psFree(stack); 604 pmReadoutUpdateSize(combined, minInputCols, minInputRows, xSize, ySize, true, true, bad); 605 psTrace("psModules.imcombine", 1, "Combining [%d:%d,%d:%d] (%dx%d)\n", 606 minInputCols, maxInputCols, minInputRows, maxInputRows, xSize, ySize); 607 608 565 609 // Buffer for combination 566 610 combineBuffer *buffer = combineBufferAlloc(num, numIter == 0 ? PS_STAT_SAMPLE_MEAN : … … 573 617 psImage *combinedWeight = combined->weight; // Combined mask 574 618 575 psArray *pixelMap = pixelMapGenerate(input, numCols, numRows); // Map of pixels to source619 psArray *pixelMap = pixelMapGenerate(input, maxInputCols, maxInputRows); // Map of pixels to source 576 620 psPixels *pixels = NULL; // Total list of pixels, with no duplicates 577 621 for (int i = 0; i < num; i++) { … … 584 628 } 585 629 for (int i = 0; i < pixels->n; i++) { 630 // Pixel coordinates are in the frame of the original image 586 631 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest 632 if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) { 633 continue; 634 } 587 635 psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely 588 636 combinePixels(combinedImage, combinedMask, combinedWeight, input, weights, reject, x, y, … … 622 670 } 623 671 624 for (int y = 0; y < numRows; y++) {625 for (int x = 0; x < numCols; x++) {672 for (int y = minInputRows; y < maxInputRows; y++) { 673 for (int x = minInputCols; x < maxInputCols; x++) { 626 674 combinePixels(combinedImage, combinedMask, combinedWeights, input, weights, NULL, x, y, 627 675 maskVal, bad, numIter, rej, buffer);
Note:
See TracChangeset
for help on using the changeset viewer.
