IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1880


Ignore:
Timestamp:
Sep 24, 2004, 11:05:00 AM (22 years ago)
Author:
gusciora
Message:

...

Location:
trunk/psModules/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/Makefile.am

    r1849 r1880  
    22bin_PROGRAMS = tst_pmFlatField tst_pmMaskBadPixels
    33
    4 libpsmodule_a_SOURCES = pmFlatField.c pmMaskBadPixels.c psTest.c
    5 libpsmodule_a_HEADERS = pmFlatField.h pmMaskBadPixels.h psTest.h
     4libpsmodule_a_SOURCES = pmFlatField.c pmMaskBadPixels.c pmSubtractBias.c psTest.c
     5libpsmodule_a_HEADERS = pmFlatField.h pmMaskBadPixels.h pmSubtractBias.h psTest.h
    66libpsmodule_adir = .
    77
     
    1111tst_pmMaskBadPixels_SOURCES = tst_pmMaskBadPixels.c
    1212tst_pmMaskBadPixels_LDFLAGS = libpsmodule.a
     13
     14tst_pmSB_SOURCES = tst_pmMaskBadPixels.c
     15tst_pmSB_LDFLAGS = libpsmodule.a
  • trunk/psModules/src/pmSubtractBias.c

    r1877 r1880  
    88 *  @author George Gusciora, MHPCC
    99 *
    10  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-09-24 18:31:02 $
     10 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-09-24 21:05:00 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535//    PM_FIT_SPLINE                             ///< Fit cubic splines
    3636
     37#define PM_SUBTRACT_BIAS_POLYNOMIAL_ORDER 2
     38#define PM_SUBTRACT_BIAS_SPLINE_ORDER 3
    3739
    3840psReadout *psSubtractFrame(psReadout *in,
     
    8486}
    8587
     88/******************************************************************************
     89GenNewStatOptions(): this routine will take as input the options member of
     90the stat data structure, determine if multiple options have been specified,
     91issue a warning message if so, and return the highest priority option
     92(according to the order of the if-statements in this code).
     93 *****************************************************************************/
     94psStatsOptions GenNewStatOptions(const psStats *stat)
     95{
     96    int numOptions = 0;
     97    psStatsOptions opt;
     98
     99    if (stat->options & PS_STAT_SAMPLE_MEAN) {
     100        numOptions++;
     101        opt = PS_STAT_SAMPLE_MEAN;
     102    }
     103
     104    if (stat->options & PS_STAT_SAMPLE_MEDIAN) {
     105        if (numOptions == 0) {
     106            opt = PS_STAT_SAMPLE_MEDIAN;
     107        }
     108        numOptions++;
     109    }
     110
     111    if (stat->options & PS_STAT_CLIPPED_MEAN) {
     112        if (numOptions == 0) {
     113            opt = PS_STAT_CLIPPED_MEAN;
     114        }
     115        numOptions++;
     116    }
     117
     118    if (stat->options & PS_STAT_ROBUST_MEAN) {
     119        if (numOptions == 0) {
     120            opt = PS_STAT_ROBUST_MEAN;
     121        }
     122        numOptions++;
     123    }
     124
     125    if (stat->options & PS_STAT_ROBUST_MEDIAN) {
     126        if (numOptions == 0) {
     127            opt = PS_STAT_ROBUST_MEDIAN;
     128        }
     129        numOptions++;
     130    }
     131
     132    if (stat->options & PS_STAT_ROBUST_MODE) {
     133        if (numOptions == 0) {
     134            opt = PS_STAT_ROBUST_MODE;
     135        }
     136        numOptions++;
     137    }
     138
     139    if (numOptions != 1) {
     140\\ XXX:
     141        Generate warning message.
     142    }
     143
     144    return(opt);
     145}
     146
     147// XXX: Must scale the overscan vector
     148psVector *ScaleOverscanVector(overscanVector,
     149                              (in->image)->numCols,
     150                              pmFit fit)
     151{
     152    return(overscanVector);
     153}
     154
    86155
    87156psReadout *pmSubtractBias(psReadout *in,
     
    98167    int nBin;
    99168    int numBins;
    100     static psVector *tmp = NULL;
    101     static psVector *tmpRow = NULL;
    102     static psVector *tmpCol = NULL;
    103     static psVector *tmpMask = NULL;
     169    static psVector *overscanVector = NULL;
     170    psVector *tmpRow = NULL;
     171    psVector *tmpCol = NULL;
     172    psVector *tmpMask = NULL;
     173    psVector *myBin = NULL;
     174    psVector *binVec = NULL;
     175    psList *tmpOverscan = NULL;
    104176
    105177    if (in == NULL) {
     
    107179    }
    108180
     181    //
     182    //  Determine if multiple options are specified in stat.
     183    //
     184    if (stat != NULL) {
     185        stat->options = GenNewStatOptions(stat);
     186    }
     187
    109188    if ((overscans == NULL) && (overScanAxis != PM_OVERSCAN_NONE)) {
    110189        //XXX: psErrorMsg()
    111     }
    112     if ((overscans != NULL) && (overScanAxis == PM_OVERSCAN_NONE)) {
    113         //XXX: psWarningMsg()
    114         return(psSubtractFrame(in, bias));
    115     }
    116 
    117     if (overScanAxis == PM_OVERSCAN_ALL) {
    118         psImageStats(stat, in->image, in->mask, 0xffffffff);
    119         p_psImageSubtractScalar(in->image, stat->value);
    120190        return(in);
    121191    }
     
    129199    }
    130200
     201    if (overScanAxis == PM_OVERSCAN_NONE) {
     202        if (overscans != NULL) {
     203            //XXX: psWarningMsg()
     204        }
     205        return(psSubtractFrame(in, bias));
     206    }
     207
     208    if (overScanAxis == PM_OVERSCAN_ALL) {
     209        psImageStats(stat, in->image, in->mask, 0xffffffff);
     210        p_psImageSubtractScalar(in->image, stat->value);
     211        return(in);
     212    }
     213
    131214    // XXX: Is there a better way to extract a psVector from a psImage without
    132215    // having to copy every element in that vector?
     
    135218    // or PM_OVERSCAN_COL?
    136219
     220    // XXX: How to use multiple overscans?  Currently, only the first is used.
    137221    if ((overScanAxis == PM_OVERSCAN_ROW) || (overScanAxis == PM_OVERSCAN_COL)) {
     222        myOverscanImage = (psImage *) overscans->data;
     223
    138224        if (overScanAxis == PM_OVERSCAN_ROW) {
    139             tmp = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
     225            overscanVector = psVectorAlloc((myOverscanImage->image)->numCols, PS_TYPE_F32);
     226            for (i=0;i<overscanVector->n;i++) {
     227                overscanVector->data.F32[i] = 0.0;
     228            }
    140229            tmpRow = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
    141230            tmpMask = psVectorAlloc((in->image)->numCols, PS_TYPE_U8);
    142             for (i=0;i<(in->image)->numCols;i++) {
    143                 for (j=0;j<(in->image)->numRows;j++) {
    144                     tmpRow->data.F32[j] = (in->image)->data.F32[i][j];
    145                     tmpMask->data.U8[j] = (in->mask)->data.U8[i][j];
    146                 }
    147                 stat = psVectorStats(stat, tmpRow, tmpMask, 0xffffffff);
    148                 tmp->data.F32[i] = stat->value;
    149             }
     231
     232            tmpOverscan = (psList *) overscans;
     233            while (tmpOverscan) {
     234                myOverscanImage = (psImage *) tmpOverscan->data;
     235                for (i=0;i<(myOverscanImage->image)->numCols;i++) {
     236                    for (j=0;j<(myOverscanImage->image)->numRows;j++) {
     237                        tmpRow->data.F32[j] = (myOverscanImage->image)->data.F32[i][j];
     238                        tmpMask->data.U8[j] = (myOverscanImage->mask)->data.U8[i][j];
     239                    }
     240                    stat = psVectorStats(stat, tmpRow, tmpMask, 0xffffffff);
     241                    overscanVector->data.F32[i] = stat->value;
     242                }
     243                //                tmpOverscan = tmpOverscan->next;
     244tmpOverscan = NULL:
     245                          }
     246
     247                          psFree(tmpRow);
     248            psFree(tmpMask);
     249            ScaleOverscanVector(overscanVector, (in->image)->numCols, fit);
    150250        }
    151251        if (overScanAxis == PM_OVERSCAN_COL) {
    152             tmp = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
     252            overscanVector = psVectorAlloc((myOverscanImage->image)->numRows, PS_TYPE_F32);
     253            for (i=0;i<overscanVector->n;i++) {
     254                overscanVector->data.F32[i] = 0.0;
     255            }
    153256            tmpcol = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
    154257            tmpMask = psVectorAlloc((in->image)->nuRows, PS_TYPE_U8);
    155             for (i=0;i<(in->image)->numRows;i++) {
    156                 for (j=0;j<(in->image)->numCols;j++) {
    157                     tmpRow->data.F32[j] = (in->image)->data.F32[i][j];
    158                     tmpMask->data.U8[j] = (in->mask)->data.U8[i][j];
    159                 }
    160                 stat = psVectorStats(stat, tmpRow, tmpMask, 0xffffffff);
    161                 tmp->data.F32[i] = stat->value;
    162             }
    163         }
    164 
    165         if (nBin > 0) {
    166             numBins = 1+((tmp->n)/nBin);
     258
     259            tmpOverscan = (psList *) overscans;
     260            while (tmpOverscan) {
     261                for (i=0;i<(myOverscanImage->image)->numRows;i++) {
     262                    for (j=0;j<(myOverscanImage->image)->numCols;j++) {
     263                        tmpRow->data.F32[j] = (myOverscanImage->image)->data.F32[i][j];
     264                        tmpMask->data.U8[j] = (myOverscanImage->mask)->data.U8[i][j];
     265                    }
     266                    stat = psVectorStats(stat, tmpRow, tmpMask, 0xffffffff);
     267                    overscanVector->data.F32[i] = stat->value;
     268                }
     269                //                tmpOverscan = tmpOverscan->next;
     270tmpOverscan = NULL:
     271                          }
     272                          psFree(tmpCol);
     273            psFree(tmpMask);
     274            ScaleOverscanVector(overscanVector, (in->image)->numRows, fit);
     275        }
     276
     277        if ((nBin > 0) && (nBin < overscanVector->n)) {
     278            numBins = 1+((overscanVector->n)/nBin);
    167279            psVector *myBin = psVectorAlloc(numBins, PS_TYPE_F32);
     280            binVec = psVectorAlloc(nBin, PS_TYPE_F32);
    168281
    169282            for (i=0;i<numBins;i++) {
    170                 // XXX: do this
    171             }
    172             // XXX: resize tmp to myBin, and store myBin elements there.
     283                for(j=0;j<nBin;j++) {
     284                    if (overscanVector->n > ((i*nBin)+j)) {
     285                        binVec->data.F32[j] = overscanVector->data.F32[(i*nBin)+j];
     286                    } else {
     287                        // XXX: we get here if nBin does not evenly divide
     288                        // the overscanVector vector.  This is the last bin.  Should
     289                        // we change the binVec->n to acknowledge that?
     290                        binVec->n = j;
     291                    }
     292                }
     293                stat = psVectorStats(stat, binVec, NULL, 0);
     294                myBin->data.F32[i] = stat->value;
     295            }
     296            // Change the effective size of overscanVector.
     297            overscanVector->n = numBins;
     298            for (i=0;i<numBins;i++) {
     299                overscanVector->data.F32[i] = myBin->data.F32[i];
     300            }
     301            psFree(binVec);
     302            psFree(myBin);
    173303        } else {
    174304            nBin = 1;
    175305        }
    176306
    177         if (!((fitSpec == NULL) || (fit ==PM_FIT_NONE))) {
    178             fit the vector to a linear or cubic spline.
     307        if (!((fitSpec == NULL) || (fit == PM_FIT_NONE))) {
     308            if (fit == PM_FIT_POLYNOMIAL) {
     309                myPoly = (psPolynomial1D *) fitSpec;
     310                myPoly = psVectorFitPolynomial1D(myPoly, NULL, overscanVector, NULL);
     311                for (i=0;i<numBins;i++) {
     312                    overscanVector->data.F32[i] = psPolynomial1DEval((float) i, myPoly);
     313                }
     314
     315            } else if (fit == PM_FIT_SPLINE) {
     316                mySpline = (psSPline1D *) fitSpec;
     317                // XXX: What is the point of doing this?
     318            }
    179319        }
    180320
     
    182322            for (i=0;i<(in->image)->numCols;i++) {
    183323                for (j=0;j<(in->image)->numRows;j++) {
    184                     (in->image)->data.F32[i][j]-= tmp->data.F32[j/nBin];
     324                    (in->image)->data.F32[i][j]-= overscanVector->data.F32[j/nBin];
    185325                }
    186326            }
     
    190330            for (i=0;i<(in->image)->numRows;i++) {
    191331                for (j=0;j<(in->image)->numCols;j++) {
    192                     (in->image)->data.F32[i][j]-= tmp->data.F32[j/nBin];
    193                 }
    194             }
    195         }
     332                    (in->image)->data.F32[i][j]-= overscanVector->data.F32[j/nBin];
     333                }
     334            }
     335        }
     336        psFree(overscanVector);
    196337        return(in);
    197338    }
Note: See TracChangeset for help on using the changeset viewer.