IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 9, 2006, 4:59:23 PM (20 years ago)
Author:
magnier
Message:

complete re-work of API: now only performs set external mask

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmMaskBadPixels.c

    r7283 r7479  
    55 *  match the value to mask.
    66 *
    7  *  Given an input image, in, a bad pixel mask, a corresponding value in the bad pixel mask to mask in the
    8  * input image, maskVal, a saturation level, and a growing radius, pmMaskBadPixels shall mask in the input
    9  * image those pixels in the bad pixel mask that match the value to mask. Note that the input image, in, is
    10  * modified in-place. All pixels in the mask which satisfy the maskVal shall have their corresponding pixels
    11  * masked in the input image, in. All pixels which satisfy the growVal shall have their corresponding
    12  * pixels, along with all pixels within the grow radius masked. Pixels which have flux greater than sat shall
    13  * also be masked, but not grown. Note that the input image, in, and the mask need not be the same size, since
    14  * the input image may already have been trimmed (following overscan subtraction), but the function shall use
    15  * the offsets in the image (in->x0 and in->y0) to determine the appropriate offsets to obtain the correct
    16  * pixel on the mask. In the event that the mask image is too small (i.e., pixels on the input image refer to
     7 *  Apply the supplied bad pixel mask readout (mask) to the given science readout (input).
     8 *  The science readout must already have a supplied mask element (use eg. pmReadoutSetMask)
     9 *  The supplied mask image must be of MASK type
     10 
     11 *  If maskVal is non-zero, all pixels in the mask have any of the same bits sets as maskVal
     12 *  shall have the corresponding bits raised.
     13 
     14 *  If maskVal is zero, any zero pixels in the mask be OR-ed with PM_MASK_BAD
     15 
     16 * Note that the input image and the mask need not be the same size, since the input image may
     17 * already have been trimmed (following overscan subtraction).  The function assumes the pixels
     18 * originate from the same detector and uses the values of col0,row0 in both the input and the
     19 * mask to match corresponding pixels.
     20 
     21 * In the event that the mask image is too small (i.e., pixels on the input image refer to
    1722 * pixels outside the range of the mask image), the function shall generate an error.
    1823 
    1924 *  @author Ross Harman, MHPCC
     25 *  @author Eugene Magnier, IfA
    2026 *
    21  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2006-06-02 02:16:05 $
     27 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     28 *  @date $Date: 2006-06-10 02:59:23 $
    2329 *
    24  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     30 *  Copyright 2004 IfA, University of Hawaii
    2531 */
    2632
     
    3743#include "pmMaskBadPixelsErrors.h"
    3844
    39 bool pmMaskBadPixels(pmReadout *in, const psImage *mask, unsigned int maskVal, float sat,
    40                      unsigned int growVal, int grow)
     45// apply an externally-supplied mask image to the current science image
     46// this function
     47bool pmMaskBadPixels(pmReadout *input, pmReadout *mask, psMaskType maskVal)
    4148{
    42     int i = 0;
    43     int j = 0;
    44     int jj = 0;
    45     int ii = 0;
    46     int rRound = 0;
    47     int rowMin = 0;
    48     int rowMax = 0;
    49     int colMin = 0;
    50     int colMax = 0;
    51     int totOffCol = 0;
    52     int totOffRow = 0;
    53     float r = 0.0f;
    54     psElemType inType;
    55     psElemType maskType;
    56     psImage *inImage = NULL;
    57     psImage *inMask = NULL;
    5849
     50    int xI;
     51    int xJ;
    5952
    60     // Check for nulls
    61     if (in == NULL) {
    62         return true;   // Readout may not have data in it
    63     } else if(mask==NULL) {
    64         psError( PS_ERR_BAD_PARAMETER_NULL, true,
    65                  PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE);
     53    PS_ASSERT_PTR_NON_NULL(input, false);
     54    PS_ASSERT_PTR_NON_NULL(input->mask, false);
     55    PS_ASSERT_IMAGE_TYPE(input->mask, PS_TYPE_MASK, NULL);
     56
     57    PS_ASSERT_PTR_NON_NULL(mask, false);
     58    PS_ASSERT_PTR_NON_NULL(mask->mask, false);
     59    PS_ASSERT_IMAGE_TYPE(mask->mask, PS_TYPE_MASK, NULL);
     60
     61    psImage *inMask = input->mask;
     62    psImage *exMask = mask->mask;
     63
     64    int rowMax = inMask->row0 + inMask->numRows;
     65    int colMax = inMask->col0 + inMask->numCols;
     66
     67    if (exMask->row0 > inMask->row0) {
     68        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
     69                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
     70                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
    6671        return false;
    6772    }
    68 
    69     inImage = in->image;
    70     if (inImage == NULL) {
    71         psError( PS_ERR_BAD_PARAMETER_NULL, true,
    72                  PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE);
    73         return false;
    74     } else if(in->mask == NULL) {
    75         in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
    76         memset(in->mask->data.V[0], 0, inImage->numCols*inImage->numRows*PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
    77     }
    78     inMask = in->mask;
    79 
    80     // Check input image and its mask are not larger than mask
    81     if(inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) {
     73    if (exMask->col0 > inMask->col0) {
    8274        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    8375                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
    84                  inImage->numRows, inImage->numCols, mask->numRows, mask->numCols);
     76                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
    8577        return false;
    86     } else if(inMask->numRows>mask->numRows || inMask->numCols>mask->numCols) {
     78    }
     79    if (exMask->row0 + exMask->numRows < rowMax) {
    8780        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    88                  PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE,
    89                  inMask->numRows, inMask->numCols, mask->numRows, mask->numCols);
     81                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
     82                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
     83        return false;
     84    }
     85    if (exMask->col0 + exMask->numCols < colMax) {
     86        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
     87                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
     88                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
    9089        return false;
    9190    }
    9291
    9392    // Determine total offset based on image offset with chip offset
    94     totOffCol = inImage->col0; // + in->col0;
    95     totOffRow = inImage->row0; // + in->row0;
     93    // XXX if we choose to correct for the readout location, apply input->col0,row0 here
     94    int offCol = inMask->col0 - exMask->col0;
     95    int offRow = inMask->row0 - exMask->row0;
    9696
    97     // Check that offsets are within image limits
    98     if(totOffRow>=mask->numRows || totOffCol>=mask->numCols) {
    99         psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    100                  PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE,
    101                  totOffRow, totOffCol, mask->numRows, mask->numCols);
    102         return false;
    103     } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
    104         psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    105                  PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE,
    106                  totOffRow, totOffCol, inImage->numRows, inImage->numCols);
    107         return false;
    108     } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
    109         psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    110                  PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE_MASK,
    111                  totOffRow, totOffCol, inMask->numRows, inMask->numCols);
    112         return false;
     97    // masks are both of type PS_TYPE_MASK
     98    psMaskType **exVal = exMask->data.U8;
     99    psMaskType **inVal = inMask->data.U8;
     100
     101    // apply exMask values
     102    if (maskVal) {
     103        // set raised pixels in exMask which are selected by maskVal
     104        for (int j = 0; j < inMask->numRows; j++) {
     105            xJ = j - offRow;
     106            for (int i = 0; i < inMask->numCols; i++) {
     107                xI = i - offCol;
     108                inVal[j][i] |= (maskVal & exVal[xJ][xI]);
     109            }
     110        }
     111    } else {
     112        // set raised pixels in exMask which are selected by maskVal
     113        for (int j = 0; j < inMask->numRows; j++) {
     114            xJ = j - offRow;
     115            for (int i = 0; i < inMask->numCols; i++) {
     116                xI = i - offCol;
     117                if (exVal[xJ][xI] == 0) {
     118                    inVal[j][i] |= PM_MASK_BAD;
     119                }
     120            }
     121        }
    113122    }
    114123
    115     // Check for incorrect types
    116     inType = inImage->type.type;
    117     maskType = mask->type.type;
    118     if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
    119         psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    120                  PS_ERRORTEXT_pmMaskBadPixels_TYPE_INPUT_IMAGE,
    121                  inType);
    122         return false;
    123     } else if(maskType!=PS_TYPE_MASK) {
    124         psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    125                  PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE,
    126                  maskType);
    127         return false;
    128     }
    129 
    130     // Macro for all PS types
    131     #define PM_BAD_PIXELS(TYPE)                                                                              \
    132 case PS_TYPE_##TYPE:                                                                                         \
    133     for(j=totOffRow; j<inImage->numRows; j++) {                                                              \
    134         for(i=totOffCol; i<inImage->numCols; i++) {                                                          \
    135             \
    136             /* Pixels with flux greater than sat shall be masked */                                          \
    137             if(inImage->data.TYPE[j][i] > sat) {                                                             \
    138                 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT;                                         \
    139             }                                                                                                \
    140             \
    141             /* Pixels which satisfy maskVal shall be masked */                                               \
    142             inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal);            \
    143             \
    144             /* Pixels which satisfy growVal and within the grow radius shall be masked */                    \
    145             if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) {                                               \
    146                 rowMin = PS_MAX(j-grow, 0);                                                                  \
    147                 rowMax = PS_MIN(j+grow+1, inImage->numRows);                                                 \
    148                 colMin = PS_MAX(i-grow, 0);                                                                  \
    149                 colMax = PS_MIN(i+grow+1, inImage->numCols);                                                 \
    150                 for(jj=rowMin; jj<rowMax; jj++) {                                                            \
    151                     for(ii=colMin; ii<colMax; ii++) {                                                        \
    152                         r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j));                                              \
    153                         rRound = r + 0.5;                                                                    \
    154                         if(rRound <= grow) {                                                                 \
    155                             inMask->data.PS_TYPE_MASK_DATA[jj][ii] |=                                        \
    156                                     (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal);                            \
    157                         }                                                                                    \
    158                     }                                                                                        \
    159                 }                                                                                            \
    160             }                                                                                                \
    161         }                                                                                                    \
    162     }                                                                                                        \
    163     break;
    164 
    165     // Switch to call bad pixel masking macro defined above
    166     switch(inType) {
    167         PM_BAD_PIXELS(U8);
    168         PM_BAD_PIXELS(U16);
    169         PM_BAD_PIXELS(U32);
    170         PM_BAD_PIXELS(U64);
    171         PM_BAD_PIXELS(S8);
    172         PM_BAD_PIXELS(S16);
    173         PM_BAD_PIXELS(S32);
    174         PM_BAD_PIXELS(S64);
    175         PM_BAD_PIXELS(F32);
    176         PM_BAD_PIXELS(F64);
    177     default:
    178         psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    179                  PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED,
    180                  inType);
    181     }
    182 
    183     return false;
     124    return true;
    184125}
Note: See TracChangeset for help on using the changeset viewer.