IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:38:09 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201 (main change was PATTERN to PATTERN.ROW, added PATTERN.CELL)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageDetrendPattern.c

    r26694 r26895  
    55#include "ppImage.h"
    66
    7 #define ESCAPE(MESSAGE) {                               \
    8         psError(PS_ERR_UNKNOWN, false, MESSAGE);        \
     7#define ESCAPE(STATUS,...) {                    \
     8        psError(PS_ERR_UNKNOWN, STATUS, __VA_ARGS__);   \
    99        psFree(view);                                   \
    1010        return false;                                   \
    1111    }
     12
     13static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipename, const char *recipevalue);
    1214
    1315bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView,
     
    1618    pmCell *cell = NULL;
    1719
    18     assert (options->doPattern); // do not call if not needed
    19     assert (inputView->chip != -1);
    20     assert (inputView->cell == -1);
    21     assert (inputView->readout == -1);
    22     bool status;
    23     pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT");
     20    assert(options->doPatternRow || options->doPatternCell); // do not call if not needed
     21    assert(inputView->chip != -1);
     22    assert(inputView->cell == -1);
     23    assert(inputView->readout == -1);
    2424
    25     pmFPAview *view = pmFPAviewAlloc(0); // View for local processing
    26     *view = *inputView;
     25    if (options->doPatternRow) {
     26        bool status;
     27        pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT");
     28        pmFPAview *view = pmFPAviewAlloc(0); // View for local processing
     29        *view = *inputView;
     30        while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
     31            if (!cell->process || !cell->file_exists) {
     32                continue;
     33            }
     34            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     35              ESCAPE(false, "load failure for Cell");
     36            }
    2737
    28     while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
    29         if (!cell->process || !cell->file_exists) {
    30             continue;
    31         }
    32         if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    33             ESCAPE("load failure for Cell");
    34         }
    35 
    36         if (!cell->data_exists) {
    37             continue;
    38         }
    39 
    40         if (cell->readouts->n > 1) {
    41             psWarning ("Skipping Video Cell for ppImageDetrendPatternApply");
    42             continue;
    43         }
    44 
    45         psMetadataItem *doPattern = pmConfigRecipeValueByView(config, RECIPE_NAME, "PATTERN.SUBSET",
    46                                                               chip->parent, view); // Do we do pattern sub?
    47         if (!doPattern || doPattern->type != PS_DATA_BOOL) {
    48             ESCAPE("Unable to determine whether pattern matching should be applied.");
    49         }
    50         if (!doPattern->data.B) {
    51             continue;
    52         }
    53 
    54         psLogMsg("ppImage", PS_LOG_INFO, "Performing pattern subtraction for %d,%d\n", view->chip, view->cell);
    55 
    56         // process each of the readouts
    57         pmReadout *readout;         // Readout from cell
    58         while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
    59             if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    60                 ESCAPE("load failure for Readout");
    61             }
    62             if (!readout->data_exists) {
     38            if (!cell->data_exists) {
    6339                continue;
    6440            }
    6541
    66             // perfore pattern correction
    67             if (!pmPatternRow(readout, options->patternOrder, options->patternIter, options->patternRej,
    68                               options->patternThresh, options->patternMean, options->patternStdev,
    69                               options->maskValue, options->darkMask)) {
    70                 psFree(view);
    71                 return(false);
     42            if (cell->readouts->n > 1) {
     43                psWarning ("Skipping Video Cell for ppImageDetrendPatternApply");
     44                continue;
     45            }
     46
     47            bool doPattern = false;
     48            if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.ROW.SUBSET")) {
     49                ESCAPE(false, "Unable to determine whether row pattern matching should be applied.");
     50            }
     51            if (!doPattern) continue;
     52
     53            const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");
     54            const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME");
     55            psLogMsg("ppImage", PS_LOG_INFO, "Performing row pattern correction for %s, %s\n",
     56                     chipName, cellName);
     57
     58            // process each of the readouts
     59            pmReadout *readout;         // Readout from cell
     60            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
     61                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     62                    ESCAPE(false, "load failure for Readout");
     63                }
     64                if (!readout->data_exists) {
     65                    continue;
     66                }
     67
     68                // Perform pattern correction
     69                if (!pmPatternRow(readout, options->patternRowOrder, options->patternRowIter,
     70                                  options->patternRowRej, options->patternRowThresh, options->patternRowMean,
     71                                  options->patternRowStdev, options->maskValue, options->darkMask)) {
     72                    psFree(view);
     73                    return(false);
     74                }
    7275            }
    7376        }
     77        psFree(view);
    7478    }
    7579
    76     psFree(view);
     80    if (options->doPatternCell) {
     81        int numCells = chip->cells->n;       // Number of cells
     82        psVector *tweak = psVectorAlloc(numCells, PS_TYPE_U8); // Tweak cell?
     83        pmFPAview *view = pmFPAviewAlloc(0); // View for local processing
     84        *view = *inputView;
     85        for (int i = 0; i < chip->cells->n; i++) {
     86            view->cell = i;
     87
     88            bool doPattern = false;
     89            if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.CELL.SUBSET")) {
     90                ESCAPE(false, "Unable to determine whether row pattern matching should be applied.");
     91            }
     92            if (doPattern) {
     93                tweak->data.U8[i] = 0xFF;
     94            }
     95        }
     96
     97        // Tweak the cells
     98        if (!pmPatternCell(chip, tweak, options->patternCellBG, options->patternCellMean,
     99                           options->maskValue, options->darkMask)) {
     100            psFree(tweak);
     101            psFree(view);
     102            return false;
     103        }
     104        psFree(tweak);
     105        psFree(view);
     106    }
     107
    77108    return(true);
    78109}
    79110
     111static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipeName, const char *recipeValue) {
    80112
     113    *doit = false;
     114
     115    psMetadataItem *doPattern = pmConfigRecipeValueByView(config, recipeName, recipeValue, chip->parent, view);
     116    if (!doPattern) {
     117        psError(PS_ERR_UNKNOWN, false, "Unable to determine whether row pattern matching should be applied.");
     118        return false;
     119    }
     120    if (doPattern->type == PS_DATA_BOOL) {
     121        *doit = doPattern->data.B;
     122        return true;
     123    }
     124    if (doPattern->type == PS_DATA_STRING) {
     125        // expect a string of the form "000110001001" with at least view->cell entries
     126        char *string = doPattern->data.str;
     127        if (strlen(string) < view->cell) {
     128            psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET chip string (too few elements %d)", (int) strlen(string));
     129            return false;
     130        }
     131        switch (string[view->cell]) {
     132          case '0':
     133          case 'f':
     134          case 'F':
     135          case 'n':
     136          case 'N':
     137            *doit = false;
     138            return true;
     139          case '1':
     140          case 't':
     141          case 'T':
     142          case 'y':
     143          case 'Y':
     144            *doit = true;
     145            return true;
     146          default:
     147            psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET chip string %s (unknown value %c))", string, string[view->cell]);
     148            return false;
     149        }
     150        psAbort("imposible to reach here");
     151    }
     152    psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET : invalid data type");
     153    return false;
     154}
Note: See TracChangeset for help on using the changeset viewer.