Changeset 16628 for trunk/psModules/src/imcombine/pmStack.c
- Timestamp:
- Feb 22, 2008, 5:01:45 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStack.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r16626 r16628 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2008-02-23 03:0 0:30$10 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2008-02-23 03:01:45 $ 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 13 13 * … … 479 479 480 480 481 #if 0482 // Examine a pixel carefully to see if it should be rejected in the stack by convolving all the input images483 // to the same seeing, and clipping there.484 static bool convolveTest(psVector *reject, // Image indices to reject for this pixel (output)485 psVector *inspect, // Images indices to inspect for this pixel (input)486 psArray *input, // The input pmStackData487 int xPix, int yPix, // Pixel coordinates of interest488 psVector *seeing, // Seeing convolution for each image489 psMaskType maskVal, // Value to mask490 float extent, // Extent of convolution (Gaussian sigmas)491 float threshold// Rejection threshold (standard deviations)492 )493 {494 assert(reject && reject->type.type == PS_TYPE_U16);495 assert(input);496 assert(seeing);497 assert(seeing->n == input->n);498 499 int num = input->n; // Number of input images500 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); // Statistics501 psVector *values = psVectorAlloc(num, PS_TYPE_F32); // Values from convolving the image502 psVector *valuesMask = psVectorAlloc(num, PS_TYPE_MASK); // Mask for convolution values503 504 for (int i = 0; i < num; i++) {505 pmStackData *data = input->data[i]; // Stacking data506 int radius = extent * seeing->data.F32[i]; // How much to convolve507 psImage *image = data->readout->image; // Image to convolve508 psImage *mask = data->readout->mask; // Image mask509 510 int xMin = PS_MAX(xPix - radius, 0);511 int xMax = PS_MIN(xPix + radius, image->numCols - 1);512 int yMin = PS_MAX(yPix - radius, 0);513 int yMax = PS_MIN(yPix + radius, image->numRows - 1);514 515 float sum = 0.0; // Sum of pixels in convolution516 float sumKernel = 0.0; // Sum of kernel517 for (int y = yMin; y <= yMax; y++) {518 int v2 = PS_SQR(y - yPix);519 for (int x = xMin; x <= xMax; x++) {520 int u2 = PS_SQR(x - xPix);521 float kernel = expf(-(u2 + v2) / seeing->data.F32[i]);522 if (!(mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal)) {523 sum += image->data.F32[y][x] * kernel;524 sumKernel += kernel;525 }526 }527 }528 529 if (sumKernel != 0.0) {530 values->data.F32[i] = sum / sumKernel;531 valuesMask->data.PS_TYPE_MASK_DATA[i] = 0;532 } else {533 // Everything's masked out; don't include this pixel in the analysis534 values->data.F32[i] = NAN;535 valuesMask->data.PS_TYPE_MASK_DATA[i] = MASK_BAD;536 }537 }538 539 // Mask the ones we're inspecting540 for (int i = 0; i < inspect->n; i++) {541 valuesMask->data.PS_TYPE_MASK_DATA[inspect->data.U16[i]] |= MASK_SUSPECT;542 }543 544 if (!psVectorStats(stats, values, NULL, valuesMask, MASK_BAD | MASK_SUSPECT)) {545 psFree(stats);546 psFree(values);547 psFree(valuesMask);548 return false;549 }550 551 // Inspect the pixels of interest552 float mean = stats->sampleMean; // Mean value553 float limit = threshold * stats->sampleStdev; // Rejection threshold554 for (int j = 0; j < inspect->n; j++) {555 int index = inspect->data.U16[j]; // Index of interest556 if (fabsf(values->data.F32[index] - mean) > limit) {557 reject->data.U16[reject->n++] = index;558 }559 }560 561 psFree(stats);562 psFree(values);563 psFree(valuesMask);564 565 return true;566 }567 #endif568 569 570 481 // Generate a "pixel map". 571 482 // … … 785 696 } 786 697 787 #if 0788 bool pmStackReject(psArray *input, psMaskType maskVal, float extent, float threshold)789 {790 bool haveWeights; // Do we have the sky weight maps?791 bool havePixels; // Do we have lists of pixels?792 int num; // Number of inputs793 int numCols, numRows; // Size of (sky) images794 if (!validateInputData(&haveWeights, &havePixels, &num, &numCols, &numRows, input)) {795 return false;796 }797 if (!havePixels) {798 psError(PS_ERR_UNEXPECTED_NULL, true, "No pixels have been flagged for possible rejection.");799 return false;800 }801 PS_ASSERT_FLOAT_LARGER_THAN(extent, 0.0, false);802 803 // Want to concatenate the list of pixels, but also want to know where each came from804 psArray *pixelMap = pixelMapGenerate(input, numCols, numRows); // Map of pixels to source805 psPixels *pixels = NULL; // Total list of pixels, with no duplicates806 for (int i = 0; i < num; i++) {807 pmStackData *data = input->data[i]; // Stacking data; contains the list of pixels808 pixels = psPixelsConcatenate(pixels, data->pixels);809 // Throw out the old in preparation for the new810 data->pixels = psPixelsRealloc(data->pixels, 0);811 }812 813 // Get the convolution widths814 psVector *seeing = psVectorAlloc(num, PS_TYPE_F32); // Seeing for each image815 const float fwhm2sigma = 1.0 / (2.0*sqrt((double)2.0*(log((double)2.0)))); // Conversion FWHM --> sigma816 float seeingMax = -INFINITY; // Maximum FWHM817 for (int i = 0; i < num; i++) {818 pmStackData *data = input->data[i]; // Stacking data819 seeing->data.F32[i] = data->seeing * fwhm2sigma;820 if (data->seeing > seeingMax) {821 seeingMax = data->seeing;822 }823 }824 (void)psBinaryOp(seeing, seeing, "*", seeing);825 (void)psBinaryOp(seeing, psScalarAlloc(PS_SQR(seeingMax), PS_TYPE_F32), "-", seeing);826 (void)psUnaryOp(seeing, seeing, "sqrt");827 828 829 psVector *reject = psVectorAllocEmpty(num, PS_TYPE_U16); // Image indices to reject for a given pixel830 831 for (int i = 0; i < pixels->n; i++) {832 int x = pixels->data[i].x; // x coordinate of interest833 int y = pixels->data[i].y; // y coordinate of interest834 psVector *inspect = pixelMapQuery(pixelMap, x, y); // Inspect these images closely835 836 // Can daisy-chain multiple tests here837 reject->n = 0;838 839 if (!convolveTest(reject, inspect, input, x, y, seeing, maskVal, extent, threshold)) {840 // Some sort of error message here; NAN and mask all the pixels841 for (int i = 0; i < num; i++) {842 pmStackData *data = input->data[i]; // Stacking data843 psPixelsAdd(data->pixels, PIXEL_LIST_BUFFER, x, y);844 }845 continue;846 }847 848 // Add the rejected pixels to the official rejection list849 for (int i = 0; i < reject->n; i++) {850 pmStackData *data = input->data[reject->data.U16[i]]; // Stacking data851 psPixelsAdd(data->pixels, PIXEL_LIST_BUFFER, x, y);852 }853 }854 psFree(reject);855 psFree(seeing);856 psFree(pixels);857 psFree(pixelMap);858 859 #ifndef PS_NO_TRACE860 if (psTraceGetLevel("psModules.imcombine") >= 5) {861 for (int i = 0; i < num; i++) {862 pmStackData *data = input->data[i]; // Stack data for this input863 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels rejected.\n", i, data->pixels->n);864 }865 }866 #endif867 868 return true;869 }870 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
