IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 15, 2005, 10:09:03 AM (20 years ago)
Author:
gusciora
Message:

SubtractBias was recoded. Significant mods to removeBadPixels.
Additional mods to other files.

File:
1 edited

Legend:

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

    r5170 r5516  
    1919 *  @author Ross Harman, MHPCC
    2020 *
    21  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2005-09-28 20:43:52 $
     21 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     22 *  @date $Date: 2005-11-15 20:09:03 $
    2323 *
    2424 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmMaskBadPixels.h"
    3636#include "pmMaskBadPixelsErrors.h"
     37#include "pmSubtractBias.h"
     38
     39/******************************************************************************
     40GrowPixel(inMask, row, col, radius, maskVal): This private routine takes an
     41input image mask and a pixel location, then sets (logical or) all pixels with
     42parameter radius if that pixel to maskVal parameter.
     43 *****************************************************************************/
     44psBool GrowPixel(
     45    psImage *inMask,
     46    psS32 col,
     47    psS32 row,
     48    psS32 radius,
     49    psU32 maskVal)
     50{
     51    psS32 rowMin = PS_MAX(row-radius, 0);
     52    psS32 rowMax = PS_MIN(row+radius+1, inMask->numRows);
     53    psS32 colMin = PS_MAX(col-radius, 0);
     54    psS32 colMax = PS_MIN(col+radius+1, inMask->numCols);
     55    psF32 squareRadius = PS_SQR(radius);
     56
     57
     58    for(psS32 i=rowMin; i<rowMax; i++) {
     59        for(psS32 j=colMin; j<colMax; j++) {
     60            // Old code:
     61            //            psF32 rRound = 0.5 + sqrtf((psF32) (((col-j)*(col-j)) + ((row-i)*(row-i))));
     62            //            if(rRound <= radius) {
     63            psF32 squareDis = (psF32) (((col-j)*(col-j)) + ((row-i)*(row-i)));
     64            if (squareDis <= squareRadius) {
     65                inMask->data.U8[i][j] |= maskVal;
     66            }
     67        }
     68    }
     69    return(true);
     70}
     71
     72/******************************************************************************
     73GetRadius(inImg, col, row, sat, growVal, grow): This private routine takes an
     74input image and pixel location and determines what radius that pixel must grow
     75by.
     76 
     77//XXX: Inline this or macro it for speed.
     78 *****************************************************************************/
     79static psS32 GetRadius(
     80    psImage *inImg,
     81    psS32 col,
     82    psS32 row,
     83    psF32 sat,
     84    psU32 growVal,
     85    psS32 grow)
     86{
     87    psS32 growRadius = 0;
     88    if (inImg->type.type == PS_TYPE_F32) {
     89        if(inImg->data.F32[row][col] == growVal) {
     90            growRadius = grow;
     91        }
     92        if (inImg->data.F32[row][col] > sat) {
     93            growRadius = PS_MAX(growRadius+1, 2);
     94        }
     95    } else if (inImg->type.type == PS_TYPE_S32) {
     96        if(inImg->data.S32[row][col] == growVal) {
     97            growRadius = grow;
     98        }
     99        if (inImg->data.S32[row][col] > sat) {
     100            growRadius = PS_MAX(growRadius+1, 2);
     101        }
     102    } else if (inImg->type.type == PS_TYPE_U16) {
     103        if(inImg->data.U16[row][col] == growVal) {
     104            growRadius = grow;
     105        }
     106        if (inImg->data.U16[row][col] > sat) {
     107            growRadius = PS_MAX(growRadius+1, 2);
     108        }
     109    } else {
     110        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
     111                 PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE,
     112                 inImg->type.type);
     113    }
     114    return(growRadius);
     115}
     116
    37117
    38118bool pmMaskBadPixels(
    39119    pmReadout *in,
    40     const psImage *mask,
     120    const pmReadout *mask,
    41121    unsigned int maskVal,
    42122    float sat,
     
    44124    int grow)
    45125{
     126    // XXX: Review this code then put all asserts at the top.
     127    PS_ASSERT_PTR_NON_NULL(in, true);
     128    PS_ASSERT_PTR_NON_NULL(in->image, false);
     129    PS_WARN_PTR_NON_NULL(in->parent);
     130    if (in->parent != NULL) {
     131        PS_WARN_PTR_NON_NULL(in->parent->concepts);
     132    }
     133    PS_ASSERT_PTR_NON_NULL(mask, false);
    46134    int i = 0;
    47135    int j = 0;
    48     int jj = 0;
    49     int ii = 0;
    50     int rRound = 0;
    51     int rowMin = 0;
    52     int rowMax = 0;
    53     int colMin = 0;
    54     int colMax = 0;
    55136    int totOffCol = 0;
    56137    int totOffRow = 0;
    57     float r = 0.0f;
    58138    psElemType inType;
    59139    psElemType maskType;
    60     psImage *inImage = NULL;
    61140    psImage *inMask = NULL;
    62141
    63 
    64     // Check for nulls
    65     if (in == NULL) {
    66         return true;   // Readout may not have data in it
    67     } else if(mask==NULL) {
    68         psError( PS_ERR_BAD_PARAMETER_NULL, true,
    69                  PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE);
    70         return false;
    71     }
    72 
    73     inImage = in->image;
    74     if (inImage == NULL) {
    75         psError( PS_ERR_BAD_PARAMETER_NULL, true,
    76                  PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE);
    77         return false;
    78     } else if(in->mask == NULL) {
    79         in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
    80         memset(in->mask->data.V[0], 0, inImage->numCols*inImage->numRows*PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
     142    //
     143    // Determine trimmed image from metadata.
     144    //
     145    psImage *trimmedImg = p_psDetermineTrimmedImage(in);
     146    if(in->mask == NULL) {
     147        in->mask = psImageAlloc(trimmedImg->numCols, trimmedImg->numRows, PS_TYPE_MASK);
     148        PS_IMAGE_SET_U8(in->mask, 0);
    81149    }
    82150    inMask = in->mask;
    83151
    84152    // Check input image and its mask are not larger than mask
    85     if(inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) {
     153    if(trimmedImg->numRows > mask->image->numRows || trimmedImg->numCols > mask->image->numCols) {
    86154        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    87155                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
    88                  inImage->numRows, inImage->numCols, mask->numRows, mask->numCols);
    89         return false;
    90     } else if(inMask->numRows>mask->numRows || inMask->numCols>mask->numCols) {
     156                 trimmedImg->numRows, trimmedImg->numCols, mask->image->numRows, mask->image->numCols);
     157        return false;
     158    } else if(inMask->numRows > mask->image->numRows || inMask->numCols > mask->image->numCols) {
    91159        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    92160                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE,
    93                  inMask->numRows, inMask->numCols, mask->numRows, mask->numCols);
     161                 inMask->numRows, inMask->numCols, mask->image->numRows, mask->image->numCols);
    94162        return false;
    95163    }
    96164
    97165    // Determine total offset based on image offset with chip offset
    98     totOffCol = inImage->col0 + in->col0;
    99     totOffRow = inImage->row0 + in->row0;
     166    totOffCol = trimmedImg->col0 + in->col0;
     167    totOffRow = trimmedImg->row0 + in->row0;
    100168
    101169    // Check that offsets are within image limits
    102     if(totOffRow>=mask->numRows || totOffCol>=mask->numCols) {
     170    if(totOffRow>=mask->image->numRows || totOffCol>=mask->image->numCols) {
    103171        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    104172                 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE,
    105                  totOffRow, totOffCol, mask->numRows, mask->numCols);
    106         return false;
    107     } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
     173                 totOffRow, totOffCol, mask->image->numRows, mask->image->numCols);
     174        return false;
     175    } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {
    108176        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    109177                 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE,
    110                  totOffRow, totOffCol, inImage->numRows, inImage->numCols);
     178                 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);
    111179        return false;
    112180    } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
     
    118186
    119187    // Check for incorrect types
    120     inType = inImage->type.type;
    121     maskType = mask->type.type;
     188    inType = trimmedImg->type.type;
     189    maskType = mask->image->type.type;
    122190    if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
    123191        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
     
    132200    }
    133201
    134     // Macro for all PS types
    135     #define PM_BAD_PIXELS(TYPE)                                                                              \
    136 case PS_TYPE_##TYPE:                                                                                         \
    137     for(j=totOffRow; j<inImage->numRows; j++) {                                                              \
    138         for(i=totOffCol; i<inImage->numCols; i++) {                                                          \
    139             \
    140             /* Pixels with flux greater than sat shall be masked */                                          \
    141             if(inImage->data.TYPE[j][i] > sat) {                                                             \
    142                 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT;                                         \
    143             }                                                                                                \
    144             \
    145             /* Pixels which satisfy maskVal shall be masked */                                               \
    146             inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal);            \
    147             \
    148             /* Pixels which satisfy growVal and within the grow radius shall be masked */                    \
    149             if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) {                                               \
    150                 rowMin = MAX(j-grow, 0);                                                                     \
    151                 rowMax = MIN(j+grow+1, inImage->numRows);                                                    \
    152                 colMin = MAX(i-grow, 0);                                                                     \
    153                 colMax = MIN(i+grow+1, inImage->numCols);                                                    \
    154                 for(jj=rowMin; jj<rowMax; jj++) {                                                            \
    155                     for(ii=colMin; ii<colMax; ii++) {                                                        \
    156                         r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j));                                              \
    157                         rRound = r + 0.5;                                                                    \
    158                         if(rRound <= grow) {                                                                 \
    159                             inMask->data.PS_TYPE_MASK_DATA[jj][ii] |=                                        \
    160                                     (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal);                            \
    161                         }                                                                                    \
    162                     }                                                                                        \
    163                 }                                                                                            \
    164             }                                                                                                \
    165         }                                                                                                    \
    166     }                                                                                                        \
    167     break;
    168 
    169     // Switch to call bad pixel masking macro defined above
    170     switch(inType) {
    171         PM_BAD_PIXELS(U8);
    172         PM_BAD_PIXELS(U16);
    173         PM_BAD_PIXELS(U32);
    174         PM_BAD_PIXELS(U64);
    175         PM_BAD_PIXELS(S8);
    176         PM_BAD_PIXELS(S16);
    177         PM_BAD_PIXELS(S32);
    178         PM_BAD_PIXELS(S64);
    179         PM_BAD_PIXELS(F32);
    180         PM_BAD_PIXELS(F64);
    181     default:
    182         psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    183                  PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED,
    184                  inType);
    185     }
    186 
    187     return false;
     202    //
     203    // This is the main loop which examines each pixel and masks pixels if
     204    //    A: The mask matches the maskValue
     205    //    B: The pixel is larger than the saturation value
     206    //    C: The pixel equals the grow value (in which case a circle is masked)
     207    //
     208    for(i=totOffRow; i<trimmedImg->numRows; i++) {
     209        for(j=totOffCol; j<trimmedImg->numCols; j++) {
     210            //
     211            // A: Pixels which satisfy maskVal shall be masked
     212            //
     213            if (mask->image->data.U8[i][j] == maskVal) {
     214                in->mask->data.U8[i][j] |= maskVal;
     215            }
     216
     217            //
     218            // We first determine how much we need to grow by and store this in
     219            // growRadius.
     220            //
     221            psS32 growRadius = GetRadius(trimmedImg, j, i, sat, growVal, grow);
     222
     223            //
     224            // Grow the pixel mask if necessary.
     225            //
     226            if (growRadius != 0) {
     227                GrowPixel(in->mask, j, i, growRadius, maskVal);
     228            }
     229        }
     230    }
     231
     232    return true;
    188233}
Note: See TracChangeset for help on using the changeset viewer.