Changeset 16604
- Timestamp:
- Feb 22, 2008, 9:24:42 AM (18 years ago)
- Location:
- trunk/psModules/src/imcombine
- Files:
-
- 6 edited
-
pmReadoutCombine.c (modified) (1 diff)
-
pmStack.c (modified) (12 diffs)
-
pmStackReject.c (modified) (6 diffs)
-
pmSubtraction.c (modified) (4 diffs)
-
pmSubtraction.h (modified) (2 diffs)
-
pmSubtractionMatch.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmReadoutCombine.c
r15433 r16604 113 113 } 114 114 115 pmReadoutUpdateSize(output, minInputCols, minInputRows, xSize, ySize, true); 115 pmReadoutUpdateSize(output, minInputCols, minInputRows, xSize, ySize, true, params->weights, 116 params->blank); 116 117 psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0); 117 118 118 119 psStatsOptions combineStdev = 0; // Statistics option for weights 119 120 if (params->weights) { 120 121 if (!output->weight) {122 output->weight = psImageAlloc(xSize, ySize, PS_TYPE_F32);123 }124 if (output->weight->numCols < xSize || output->weight->numRows < ySize) {125 psImage *newWeight = psImageAlloc(xSize, ySize, PS_TYPE_F32);126 psImageInit(newWeight, 0.0);127 psImageOverlaySection(newWeight, output->weight, output->col0, output->row0, "=");128 psFree(output->weight);129 output->weight = newWeight;130 }131 132 121 if (first) { 133 122 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, -
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); -
trunk/psModules/src/imcombine/pmStackReject.c
r16479 r16604 25 25 int numRegions = regions->n; // Number of regions 26 26 int numCols = 0, numRows = 0; // Size of original image 27 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0 27 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image 28 int size = 0; // Size of kernel 28 29 for (int i = 0; i < numRegions; i++) { 29 30 psRegion *region = regions->data[i]; // Region of interest … … 46 47 return NULL; 47 48 } 49 psTrace("psModules.imcombine", 1, "Rejecting [%d:%d,%d:%d]\n", minCols, numCols, minRows, numRows); 48 50 49 51 psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image … … 56 58 inRO->image = image; 57 59 for (int i = 0; i < numRegions; i++) { 58 psRegion *region = regions->data[i]; // Region of interest 59 if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernels, true)) { 60 psRegion *region = subRegions->data[i]; // Region of interest 61 if (valid && (region->x0 > valid->x1 || region->x1 < valid->x0 || 62 region->y0 > valid->y1 || region->y1 < valid->y0)) { 63 // Region is outside of our sub-image 64 continue; 65 } 66 pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest 67 if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernel, false, true)) { 60 68 psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i); 61 69 psFree(convRO); … … 94 102 // Threshold the convolved image 95 103 psPixels *bad = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); // List of pixels that should be masked 96 for (int y = 0; y < numRows; y++) {97 for (int x = 0; x < numCols; x++) {104 for (int y = size; y < convolved->numRows - size; y++) { 105 for (int x = size; x < convolved->numCols - size; x++) { 98 106 if (convolved->data.F32[y][x] > threshold) { 99 bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x, y); 107 // Pixel coordinates in "bad" correspond to the full image 108 bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x + minCols, y + minRows); 100 109 } 101 110 } … … 103 112 psFree(convolved); 104 113 105 // Now, we want to convolve the original pixels properly106 mask = psPixelsToMask(NULL, bad, psRegionSet(0, numCols, 0, numRows), 0xff);107 int size = kernels->size; // Size of kernels114 // Now, grow the mask to include everything that touches a bad pixel in the convolution 115 int x0 = minCols, y0 = minRows; // Offset for mask image 116 mask = psPixelsToMask(NULL, bad, psRegionSet(x0, numCols - 1, y0, numRows - 1), 0xff); 108 117 for (int i = 0; i < bad->n; i++) { 109 int xPix = bad->data[i].x , yPix = bad->data[i].y; // Coordinates of interest118 int xPix = bad->data[i].x - x0, yPix = bad->data[i].y - y0; // Coordinates in frame of mask image 110 119 // Convolution limits 111 120 int xMin = PS_MAX(xPix - size, 0); 112 int xMax = PS_MIN(xPix + size, numCols - 1);121 int xMax = PS_MIN(xPix + size, mask->numCols - 1); 113 122 int yMin = PS_MAX(yPix - size, 0); 114 int yMax = PS_MIN(yPix + size, numRows - 1);123 int yMax = PS_MIN(yPix + size, mask->numRows - 1); 115 124 for (int y = yMin; y <= yMax; y++) { 116 125 for (int x = xMin; x <= xMax; x++) { … … 119 128 } 120 129 } 121 122 130 bad = psPixelsFromMask(bad, mask, 0xff); 123 131 psFree(mask); 124 132 133 // Convert coordinates to frame of original image 134 for (int i = 0; i < bad->n; i++) { 135 int x = bad->data[i].x + x0; 136 int y = bad->data[i].y + y0; 137 if (x < 0 || x >= numCols || y < 0 || y >= numRows) { 138 psWarning("Bad pixel coordinate %d: %d,%d --- ignored.", 139 i, x, y); 140 continue; 141 } 142 bad->data[i].x = x; 143 bad->data[i].y = y; 144 } 145 125 146 return bad; 126 147 } -
trunk/psModules/src/imcombine/pmSubtraction.c
r16479 r16604 3 3 * @author Paul Price, IfA 4 4 * @author GLG, MHPCC 5 *6 * @version $Revision: 1.80 $ $Name: not supported by cvs2svn $7 * @date $Date: 2008-02-14 23:33:09 $8 5 * 9 6 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 645 642 bool pmSubtractionConvolve(pmReadout *out1, pmReadout *out2, const pmReadout *ro1, const pmReadout *ro2, 646 643 const psImage *subMask, psMaskType blank, const psRegion *region, 647 const pmSubtractionKernels *kernels, bool useFFT)644 const pmSubtractionKernels *kernels, bool doBG, bool useFFT) 648 645 { 649 646 PS_ASSERT_PTR_NON_NULL(out1, false); … … 707 704 } 708 705 709 psImage *image, *weight; // Image and weight map to convolve706 const pmReadout *source; // Source for image parameters 710 707 switch (kernels->mode) { 711 708 case PM_SUBTRACTION_MODE_TARGET: 712 709 case PM_SUBTRACTION_MODE_1: 713 710 case PM_SUBTRACTION_MODE_DUAL: 714 image = ro1->image; 715 weight = ro1->weight; 711 source = ro1; 716 712 break; 717 713 case PM_SUBTRACTION_MODE_2: 718 image = ro2->image; 719 weight = ro2->weight; 714 source = ro2; 720 715 break; 721 716 default: 722 717 psAbort("Unsupported subtraction mode: %x", kernels->mode); 723 718 } 724 725 int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Image dimensions 719 psImage *image = source->image, *weight = source->weight; // Image and weight map to convolve 720 int numCols = image->numCols, numRows = image->numRows; // Image dimensions 721 int x0 = source->col0, y0 = source->row0; // Image offset 726 722 727 723 psImage *convImage1 = out1->image; // Convolved image … … 815 811 // (with the stamps) that it does not vary rapidly on this scale. 816 812 polyValues = p_pmSubtractionPolynomial(polyValues, kernels->spatialOrder, xNorm, yNorm); 817 float background = p_pmSubtractionSolutionBackground(kernels, polyValues); // Background term818 813 float background = doBG ? p_pmSubtractionSolutionBackground(kernels, polyValues) : 814 0.0; // Background term 819 815 psRegion subRegion = psRegionSet(i, xSubMax, j, ySubMax); // Sub-region to convolve 820 816 -
trunk/psModules/src/imcombine/pmSubtraction.h
r15756 r16604 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $9 * @date $Date: 200 7-12-07 01:57:15$8 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2008-02-22 19:24:42 $ 10 10 * Copyright 2004-207 Institute for Astronomy, University of Hawaii 11 11 */ … … 92 92 const psRegion *region, ///< Region to convolve (or NULL) 93 93 const pmSubtractionKernels *kernels, ///< Kernel parameters 94 bool doBG, ///< Apply background term? 94 95 bool useFFT ///< Use Fast Fourier Transform for the convolution? 95 96 ); -
trunk/psModules/src/imcombine/pmSubtractionMatch.c
r16479 r16604 434 434 435 435 psTrace("psModules.imcombine", 2, "Convolving...\n"); 436 if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, maskBlank, region, kernels, useFFT)) { 436 if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, maskBlank, region, kernels, 437 true, useFFT)) { 437 438 psError(PS_ERR_UNKNOWN, false, "Unable to convolve image."); 438 439 goto MATCH_ERROR;
Note:
See TracChangeset
for help on using the changeset viewer.
