IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 28, 2008, 5:10:17 PM (18 years ago)
Author:
Paul Price
Message:

Merging pap_branch_080328 so we can use the modernised version of ppMerge.

File:
1 edited

Legend:

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

    r16413 r17228  
    8181
    8282
    83 psImage *pmMaskFlagSuspectPixels(psImage *out, const pmReadout *readout, float rej,
    84                                  psMaskType maskVal)
     83bool pmMaskFlagSuspectPixels(pmReadout *output, const pmReadout *readout, float median, float stdev,
     84                             float rej, psMaskType maskVal)
    8585{
    86     PS_ASSERT_PTR_NON_NULL(readout, NULL);
    87     PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, NULL);
    88     PS_ASSERT_IMAGE_NON_NULL(readout->image, NULL);
    89     PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL);
    90     PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, NULL);
     86    PS_ASSERT_PTR_NON_NULL(readout, false);
     87    PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false);
     88    PS_ASSERT_IMAGE_NON_NULL(readout->image, false);
     89    PS_ASSERT_IMAGE_NON_EMPTY(readout->image, false);
     90    PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, false);
    9191    if (readout->mask) {
    92         PS_ASSERT_IMAGE_NON_EMPTY(readout->mask, NULL);
    93         PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, readout->mask, NULL);
    94         PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, NULL);
    95     }
    96     if (out) {
    97         PS_ASSERT_IMAGE_NON_EMPTY(out, NULL);
    98         PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_S32, NULL);
    99         PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, out, NULL);
    100     }
    101 
    102     bool status;
     92        PS_ASSERT_IMAGE_NON_EMPTY(readout->mask, false);
     93        PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, readout->mask, false);
     94        PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, false);
     95    }
     96    PS_ASSERT_PTR_NON_NULL(output, false);
     97
     98    bool mdok;                          // Status of MD lookup
     99    psImage *suspect = psMetadataLookupPtr(&mdok, output->analysis, PM_MASK_ANALYSIS_SUSPECT); // Suspect img
     100    if (suspect) {
     101        PS_ASSERT_IMAGE_NON_EMPTY(suspect, false);
     102        PS_ASSERT_IMAGE_TYPE(suspect, PS_TYPE_S32, false);
     103        PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, suspect, false);
     104        psMemIncrRefCounter(suspect);
     105    } else {
     106        suspect = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_S32);
     107        psImageInit(suspect, 0);
     108        psMetadataAddImage(output->analysis, PS_LIST_TAIL, PM_MASK_ANALYSIS_SUSPECT, PS_META_REPLACE,
     109                           "Suspect pixels", suspect);
     110        psMetadataAddS32(output->analysis, PS_LIST_TAIL, PM_MASK_ANALYSIS_NUM, PS_META_REPLACE,
     111                         "Number of input images", 0);
     112    }
     113
     114    if (!isfinite(median) || !isfinite(stdev)) {
     115        // If we get down here and the statistics are missing, then we should go and mask the entire image
     116        psWarning("Missing statistics --- flagging entire image as suspect.");
     117        return (psImage*)psBinaryOp(suspect, suspect, "+", psScalarAlloc(1.0, PS_TYPE_S32));
     118    }
     119
    103120    psImage *image = readout->image;    // Image of interest
    104121    psImage *mask = readout->mask;      // Corresponding mask
    105122
    106     if (!out) {
    107         out = psImageAlloc(image->numCols, image->numRows, PS_TYPE_S32);
    108         psImageInit(out, 0);
    109     }
    110 
    111     bool whole = false;                 // Mask whole image?
    112     float median = psMetadataLookupF32 (&status, readout->analysis, "READOUT.MEDIAN");
    113     if (!status || !isfinite(median)) {
    114         whole = true;
    115     }
    116     float stdev  = psMetadataLookupF32 (&status, readout->analysis, "READOUT.STDEV");
    117     if (!status || !isfinite(stdev)) {
    118         whole = true;
    119     }
    120 
    121 
    122123    psTrace ("psModules.detrend", 3, "suspect: %f +/- %f\n", median, stdev);
    123 
    124     if (whole) {
    125         // If we get down here and the statistics are missing, then we should go and mask the entire image
    126         psWarning("Missing statistics --- flagging entire image as suspect.");
    127         return (psImage*)psBinaryOp(out, out, "+", psScalarAlloc(1.0, PS_TYPE_S32));
    128     }
    129124
    130125    for (int y = 0; y < image->numRows; y++) {
     
    132127            if (fabs((image->data.F32[y][x] - median) / stdev) >= rej &&
    133128                    (!mask || !(mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal))) {
    134                 out->data.S32[y][x]++;
    135             }
    136         }
    137     }
    138 
    139     return out;
    140 }
    141 
    142 psImage *pmMaskIdentifyBadPixels(const psImage *suspects, psMaskType maskVal, int nTotal, float thresh, pmMaskIdentifyMode mode)
     129                suspect->data.S32[y][x]++;
     130            }
     131        }
     132    }
     133    psFree(suspect);                    // Drop reference
     134
     135    psMetadataItem *numItem = psMetadataLookup(output->analysis, PM_MASK_ANALYSIS_NUM); // Item with number
     136    assert(numItem);
     137    numItem->data.S32++;
     138
     139    return true;
     140}
     141
     142bool pmMaskIdentifyBadPixels(pmReadout *output, psMaskType maskVal, float thresh, pmMaskIdentifyMode mode)
    143143{
    144     PS_ASSERT_IMAGE_NON_NULL(suspects, NULL);
    145     PS_ASSERT_IMAGE_NON_EMPTY(suspects, NULL);
    146     PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, NULL);
     144    PS_ASSERT_PTR_NON_NULL(output, false);
     145    psImage *suspects = psMetadataLookupPtr(NULL, output->analysis, PM_MASK_ANALYSIS_SUSPECT); // Suspect img
     146    if (!suspects) {
     147        psError(PS_ERR_UNKNOWN, false, "Unable to find image with suspected bad pixels.");
     148        return false;
     149    }
     150    PS_ASSERT_IMAGE_NON_EMPTY(suspects, false);
     151    PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, false);
     152    if (output->mask) {
     153        PS_ASSERT_IMAGE_NON_EMPTY(output->mask, false);
     154        PS_ASSERT_IMAGES_SIZE_EQUAL(output->mask, suspects, false);
     155        PS_ASSERT_IMAGE_TYPE(output->mask, PS_TYPE_MASK, false);
     156    } else {
     157        output->mask = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK);
     158    }
     159    int num = psMetadataLookupS32(NULL, output->analysis, PM_MASK_ANALYSIS_NUM); // Number of inputs
     160    PS_ASSERT_INT_POSITIVE(num, false);
    147161
    148162    float limit = NAN;                  // Limit for masking
    149 
    150163    switch (mode) {
    151164      case PM_MASK_ID_VALUE:
     
    154167
    155168      case PM_MASK_ID_FRACTION:
    156         limit = thresh * nTotal;
     169        limit = thresh * num;
    157170        break;
    158171
     
    200213        limit = max + 1.0 - thresh * sqrtf((float)max + 1.0);
    201214
    202         psTrace ("psModules.detrend", 3, "bad: mode: %d, stdev: %f, limit: %f\n", max, sqrtf((float)max + 1.0), limit);
     215        psTrace ("psModules.detrend", 3, "bad: mode: %d, stdev: %f, limit: %f\n",
     216                 max, sqrtf((float)max + 1.0), limit);
    203217        break;
    204218      }
     
    207221        return NULL;
    208222    }
    209 
    210     psImage *badpix = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK); // Bad pixel mask
    211     psImageInit(badpix, 0);
    212223
    213224    if (psTraceGetLevel("psModules.detrend") > 9) {
     
    227238    psTrace ("psModules.detrend", 3, "bad pixel threshold: %f", limit);
    228239
     240    psImage *badpix = output->mask;     // Bad pixel mask
     241    psImageInit(badpix, 0);
     242
    229243    for (int y = 0; y < suspects->numRows; y++) {
    230244        for (int x = 0; x < suspects->numCols; x++) {
     
    235249    }
    236250
    237     return badpix;
     251    return true;
    238252}
    239253
    240254pmMaskIdentifyMode pmMaskIdentifyModeFromString (const char *string) {
    241255
    242     if (!strcasecmp (string, "VALUE")) {
     256    if (!strcasecmp(string, "VALUE")) {
    243257      return PM_MASK_ID_VALUE;
    244258    }
    245     if (!strcasecmp (string, "FRACTION")) {
     259    if (!strcasecmp(string, "FRACTION")) {
    246260      return PM_MASK_ID_FRACTION;
    247261    }
    248     if (!strcasecmp (string, "SIGMA")) {
     262    if (!strcasecmp(string, "SIGMA")) {
    249263      return PM_MASK_ID_SIGMA;
    250264    }
    251     if (!strcasecmp (string, "POISSON")) {
     265    if (!strcasecmp(string, "POISSON")) {
    252266      return PM_MASK_ID_POISSON;
    253267    }
Note: See TracChangeset for help on using the changeset viewer.