IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14632


Ignore:
Timestamp:
Aug 23, 2007, 10:38:47 AM (19 years ago)
Author:
Paul Price
Message:

Moving pmSubtractionDeconvolveMask out of subtraction files, renaming pmStackReject, and putting it in its own file. It's used for stacking, not subtraction, even though it uses the subtraction functions. Added the forward convolution, so that all pixels that should be rejected are rejected (not just those that are bad in the original image, but all those that it contributes to in the convolved image.

Location:
trunk/psModules/src/imcombine
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/Makefile.am

    r14580 r14632  
    77        pmReadoutCombine.c      \
    88        pmStack.c               \
     9        pmStackReject.c         \
    910        pmSubtraction.c         \
    1011        pmSubtractionKernels.c  \
     
    1516        pmReadoutCombine.h      \
    1617        pmStack.h               \
     18        pmStackReject.h         \
    1719        pmSubtraction.h         \
    1820        pmSubtractionKernels.h  \
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r14624 r14632  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-08-23 02:00:29 $
     6 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-08-23 20:38:47 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    10231023
    10241024
    1025 psPixels *pmSubtractionDeconvolveMask(const psPixels *in, float threshold, const psArray *regions,
    1026                                       const psArray *solutions, const pmSubtractionKernels *kernels)
    1027 {
    1028     PS_ASSERT_PIXELS_NON_NULL(in, NULL);
    1029     PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(threshold, 0.0, NULL);
    1030     PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(threshold, 1.0, NULL);
    1031     PS_ASSERT_ARRAY_NON_NULL(regions, NULL);
    1032     PS_ASSERT_ARRAY_NON_NULL(solutions, NULL);
    1033     PS_ASSERT_ARRAYS_SIZE_EQUAL(regions, solutions, NULL);
    1034     PS_ASSERT_PTR_NON_NULL(kernels, NULL);
    1035 
    1036     // Get the original image size
    1037     int numRegions = regions->n;        // Number of regions
    1038     int numCols = 0, numRows = 0;       // Size of original image
    1039     int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0
    1040     for (int i = 0; i < numRegions; i++) {
    1041         psRegion *region = regions->data[i]; // Region of interest
    1042         if (region->x0 < minCols) {
    1043             minCols = region->x0;
    1044         }
    1045         if (region->y0 < minRows) {
    1046             minRows = region->y0;
    1047         }
    1048         if (region->x1 > numCols) {
    1049             numCols = region->x1;
    1050         }
    1051         if (region->y1 > numRows) {
    1052             numRows = region->y1;
    1053         }
    1054     }
    1055     if (minCols != 0 || minRows != 0) {
    1056         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    1057                 "Some error with image regions --- minimum coordinate is not 0,0");
    1058         return NULL;
    1059     }
    1060 
    1061     psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image
    1062     psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve
    1063     psFree(mask);
    1064 
    1065     // Convolve the image with the kernel --- we're basically applying a matched filter and then thresholding
    1066     psImage *convolved = NULL;          // Convolved image
    1067     psPixels *out = NULL;               // List of pixels that should be masked
    1068     for (int i = 0; i < numRegions; i++) {
    1069         psRegion *region = regions->data[i]; // Region of interest
    1070         psVector *solution = solutions->data[i]; // Solution of interest
    1071         if (!pmSubtractionConvolve(&convolved, NULL, NULL, image, NULL, NULL, 0, region, solution, kernels)) {
    1072             psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i);
    1073             psFree(convolved);
    1074             psFree(image);
    1075             return NULL;
    1076         }
    1077 
    1078         // Need to adjust the thresholding level for the normalisation of the kernel --- the application of
    1079         // the kernel may scale the unit level that we've inserted.
    1080 
    1081         // Image of the kernel at the centre of the region
    1082         float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - numCols/2.0) / (float)numCols;
    1083         float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - numRows/2.0) / (float)numRows;
    1084         psImage *kernel = pmSubtractionKernelImage(solution, kernels, xNorm, yNorm);
    1085         if (!kernel) {
    1086             psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image.");
    1087             psFree(convolved);
    1088             psFree(image);
    1089             return NULL;
    1090         }
    1091         float sum = 0.0;
    1092         for (int y = 0; y < kernel->numRows; y++) {
    1093             for (int x = 0; x < kernel->numCols; x++) {
    1094                 sum += kernel->data.F32[y][x];
    1095             }
    1096         }
    1097         psFree(kernel);
    1098 
    1099         psImage *subConv = psImageSubset(convolved, *region); // Sub-image of convolved image
    1100         psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32));
    1101     }
    1102     psFree(image);
    1103 
    1104     // Threshold the convolved image
    1105     for (int y = 0; y < numRows; y++) {
    1106         for (int x = 0; x < numCols; x++) {
    1107             if (convolved->data.F32[y][x] > threshold) {
    1108                 out = psPixelsAdd(out, PIXEL_LIST_BUFFER, x, y);
    1109             }
    1110         }
    1111     }
    1112     psFree(convolved);
    1113 
    1114     return out;
    1115 }
  • trunk/psModules/src/imcombine/pmSubtraction.h

    r14602 r14632  
    66 * @author GLG, MHPCC
    77 *
    8  * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-08-22 02:56:53 $
     8 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-08-23 20:38:47 $
    1010 * Copyright 2004-207 Institute for Astronomy, University of Hawaii
    1111 */
     
    9191    );
    9292
    93 /// Given a list of pixels from the convolved image, find the corresponding (smaller subset of) pixels in the
    94 /// original image
    95 ///
    96 /// We apply a matched filter to the corresponding mask image, and threshold to find the original pixels
    97 psPixels *pmSubtractionDeconvolveMask(const psPixels *in, ///< List of pixels in the convolved image
    98                                       float threshold, ///< Threshold on convolved image, 0..1
    99                                       const psArray *regions, ///< Array of image regions for image
    100                                       const psArray *solutions, ///< Array of solution vectors for image
    101                                       const pmSubtractionKernels *kernels ///< Kernel parameters
    102     );
    103 
    10493/// @}
    10594#endif
Note: See TracChangeset for help on using the changeset viewer.