IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1813


Ignore:
Timestamp:
Sep 14, 2004, 3:04:29 PM (22 years ago)
Author:
harman
Message:

Changed image offsets
Added protection for unwanted types (complex, some float)
Updated looping per Eugene's request
Added mask image

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pmFlatField.c

    r1804 r1813  
    1515 *  @author Ross Harman, MHPCC
    1616 *
    17  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    18  *  @date $Date: 2004-09-14 18:08:14 $
     17 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     18 *  @date $Date: 2004-09-15 01:04:29 $
    1919 *
    2020 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3333#define CHECK_NULL(STRUCT)                                                                                   \
    3434if (STRUCT == NULL) {                                                                                        \
    35     psAbort(__func__, " : Line %d - Null not allowed for %s", __LINE__, #STRUCT);                            \
     35    psError(__func__, " : Line %d - Null not allowed for %s", __LINE__, #STRUCT);                            \
     36    return false;                                                                                            \
    3637}                                                                                                            \
    3738
    38 psReadout *pmFlatField(psReadout *in, psReadout *inMask, const psReadout *flat, const psReadout *flatMask)
     39bool pmFlatField(psReadout *in, psReadout *inMask, const psReadout *flat)
    3940{
    4041    int i = 0;
    4142    int j = 0;
     43    int totOffCol = 0;
     44    int totOffRow = 0;
    4245    psElemType inType;
    4346    psElemType flatType;
     47    psElemType maskType;
    4448    psImage *inImage = NULL;
    4549    psImage *flatImage = NULL;
    46     psImage *inMaskImage = NULL;
    47     psImage *flatMaskImage = NULL;
     50    psImage *maskImage = NULL;
    4851
    4952    CHECK_NULL(in);
    5053    CHECK_NULL(flat);
    5154    CHECK_NULL(inMask);
    52     CHECK_NULL(flatMask);
    5355
    5456    inImage = in->image;
    5557    flatImage = flat->image;
    56     inMaskImage = inMask->image;
    57     flatMaskImage = flatMask->image;
     58    maskImage = inMask->image;
    5859
    5960    CHECK_NULL(inImage);
    6061    CHECK_NULL(flatImage);
    61     CHECK_NULL(inMaskImage);
    62     CHECK_NULL(flatMaskImage);
     62    CHECK_NULL(maskImage);
     63
     64    totOffCol = inImage->col0 + in->col0;
     65    totOffRow = inImage->row0 + in->row0;
    6366
    6467    if(inImage->numRows > flatImage->numRows) {
    6568        psError(__func__, " : Line %d - Input image exceeds flat image in number of rows. (%d vs %d).",
    6669                __LINE__, inImage->numRows, flatImage->numRows);
    67         return NULL;
     70        return false;
    6871    }
    6972
     
    7174        psError(__func__, " : Line %d - Input image exceeds flat image in number of columns. (%d vs %d).",
    7275                __LINE__, inImage->numCols, flatImage->numCols);
    73         return NULL;
     76        return false;
    7477    }
    7578
    76     if(inImage->row0 > flatImage->numRows-1) {
    77         psError(__func__, " : Line %d - Input image row offset exceeds number of flat image rows. (%d vs %d).",
    78                 __LINE__, inImage->row0, flatImage->numRows);
    79         return NULL;
     79    if(totOffRow > flatImage->numRows-1) {
     80        psError(__func__, " : Line %d - Initial row offset exceeds that of flat image. (%d vs %d).",
     81                __LINE__, totOffRow, flatImage->numRows);
     82        return false;
    8083    }
    8184
    82     if(inImage->col0 > flatImage->numCols-1) {
    83         psError(__func__, " : Line %d - Input image column offset exceeds number of flat image columns. (%d vs %d).",
    84                 __LINE__, inImage->col0, flatImage->numCols);
    85         return NULL;
     85    if(totOffCol > flatImage->numCols-1) {
     86        psError(__func__, " : Line %d - Initial column offset exceeds that of flat image. (%d vs %d).",
     87                __LINE__, totOffCol, flatImage->numCols);
     88        return false;
    8689    }
    8790
    88     inType = in->image->type.type;
    89     flatType = flat->image->type.type;
     91    if(totOffRow > inImage->numRows-1) {
     92        psError(__func__, " : Line %d - Initial row offset exceeds that of input image. (%d vs %d).",
     93                __LINE__, totOffRow, inImage->numRows);
     94        return false;
     95    }
     96
     97    if(totOffCol > inImage->numCols-1) {
     98        psError(__func__, " : Line %d - Initial column offset exceeds that of input image. (%d vs %d).",
     99                __LINE__, totOffCol, inImage->numCols);
     100        return false;
     101    }
     102
     103    inType = inImage->type.type;
     104    flatType = flatImage->type.type;
     105    maskType = maskImage->type.type;
     106
     107    if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
     108        psError(__func__, " : Line %d - Complex types not allowed for input image", __LINE__);
     109        return false;
     110    }
     111
     112    if(PS_IS_PSELEMTYPE_COMPLEX(flatType)) {
     113        psError(__func__, " : Line %d - Complex types not allowedfor flat image", __LINE__);
     114        return false;
     115    }
     116
     117    if(PS_IS_PSELEMTYPE_COMPLEX(maskType)) {
     118        psError(__func__, " : Line %d - Complex types not allowed for mask image", __LINE__);
     119        return false;
     120    }
     121
     122    if(PS_IS_PSELEMTYPE_REAL(maskType)) {
     123        psError(__func__, " : Line %d - Floating point types not allowed for mask image", __LINE__);
     124        return false;
     125    }
     126
    90127    if(inType != flatType) {
    91128        psError(__func__, " : Line %d - Input and flat image types don't agree. (%d vs %d).",
     
    96133    // Macro for all PS types
    97134    #define PM_FLAT_DIVISION(TYPE)                                                                           \
    98 case PS_TYPE_##TYPE:                                                                                         \
    99     for(j = inImage->row0; j < inImage->numRows; j++) {                                                      \
    100         for(i = inImage->col0; i < inImage->numCols; i++) {                                                  \
    101             if(creal(flatImage->data.TYPE[j][i]) <= 0.0) {                                                   \
     135case PS_TYPE_##TYPE:                                                                                     \
     136    /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */  \
     137    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
     138        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
     139            if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
    102140                /* Negative or zero flat pixels shall be masked in input image as  PM_MASK_FLAT */           \
    103                 inMaskImage->data.F64[j][i] = PM_MASK_FLAT;                                                  \
    104             } else if(flatMaskImage->data.TYPE[j][i]){                                                       \
    105                 /* Pixels masked in the flat shall be masked with same values in the output */               \
    106                 inMaskImage->data.TYPE[j][i] = flatMaskImage->data.TYPE[j][i];                               \
     141                maskImage->data.F64[j][i] = PM_MASK_FLAT;                                                    \
    107142            }                                                                                                \
    108             if(creal(flatImage->data.TYPE[j][i]) < 0.0) {                                                    \
    109                 /* Negative pixels from the flat image may be set to zero */                                 \
    110                 inImage->data.TYPE[j][i] = 0.0;                                                              \
    111             } else if(fabs(flatImage->data.TYPE[j][i]) < FLT_EPSILON) {                                      \
    112                 psError(__func__, " : Line %d - Divide by zero. Row: %d Col: %d",__LINE__, j, i);            \
    113             } else {                                                                                         \
     143        }                                                                                                    \
     144    }                                                                                                        \
     145    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
     146        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
     147            if(maskImage->data.F64[j][i] == 0) {                                                             \
    114148                /* Module shall divide the input image by the flat-fielded image */                          \
    115149                inImage->data.TYPE[j][i] = inImage->data.TYPE[j][i]/flatImage->data.TYPE[j][i];              \
    116150            }                                                                                                \
    117         }                                                                                                     \
    118     }                                                                                                         \
     151        }                                                                                                    \
     152    }                                                                                                        \
    119153    break;
    120154
     
    130164        PM_FLAT_DIVISION(F32);
    131165        PM_FLAT_DIVISION(F64);
    132         PM_FLAT_DIVISION(C32);
    133         PM_FLAT_DIVISION(C64);
    134166    default:
    135167        psError(__func__, "Unsupported image datatype (%d)", inType);
Note: See TracChangeset for help on using the changeset viewer.