IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1871


Ignore:
Timestamp:
Sep 23, 2004, 2:23:48 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

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

    r1862 r1871  
    11/** @file  psMinimize.c
    22 *  \brief basic minimization functions
    3  *  @ingroup Math
     3 *  @ingroup Modules
    44 *
    55 *  This file will contain a module which will subtract the detector bias
     
    88 *  @author George Gusciora, MHPCC
    99 *
    10  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-09-23 06:48:30 $
     10 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-09-24 00:23:48 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636
    3737
    38 psReadout *psSubtractFrame(in, bias)
     38psReadout *psSubtractFrame(psReadout *in,
     39                           const psReadout *bias)
    3940{
     41    int i;
     42    int j;
     43
    4044    if (bias == NULL) {
    4145        return(in);
    4246    }
    43     // XXX: Check sizes
    44     // XXX: use offsets
    45 
    46     for (i=0;i<rows;i++)
    47         for (j=0;j<cols;j++)
    48             in[i][j]-=bias[i][j];
     47
     48    if (((in->image)->numRows + in->row0 - bias->row0) > (bias->image)->numRows) {
     49        // XXX: psErrorMsg() bias image does not have enough rows.
     50    }
     51    if (((in->image)->numCols + in->row0 - bias->row0) > (bias->image)->numCols) {
     52        // XXX: psErrorMsg() bias image does not have enough columns.
     53    }
     54
     55    // XXX: Verify that this is the correct way to use offsets.
     56    // XXX: Instead of performing an if-statement to determine if the mask
     57    //      is non-zero, we instead always or the bias mask with the image
     58    //      mask.  Might want to verify this is faster.
     59    for (i=0;i<(in->image)->numRows;i++) {
     60        for (j=0;j<(in->image)->numCols;j++) {
     61            (in->image)->data.F32[i][j]-=
     62                (bias->image)->data.F32[i+in->row0-bias->row0][j+in->col0-bias->col0];
     63            ((in->mask)->data.U8[i][j])|=
     64                (bias->mask)->data.U8[i+in->row0-bias->row0][j+in->col0-bias->col0];
     65        }
     66    }
     67
     68    return(in);
    4969}
     70
     71// XXX: Is there already a function which does this?
     72psImage *p_psImageSubtractScalar(psImage *image,
     73                                 float *scalar)
     74{
     75    int i;
     76    int j;
     77
     78    for (i=0;i<image->numRows;i++) {
     79        for (j=0;j<image->numCols;j++) {
     80            image->data.F32[i][j]-= scalar;
     81        }
     82    }
     83    return(image);
     84}
     85
    5086
    5187psReadout *pmSubtractBias(psReadout *in,
     
    5894                          const psReadout *bias)
    5995{
    60     if ((overscans == NULL) &&
    61             (overScanAxis != PM_OVERSCAN_NONE)) {
     96    int i;
     97    int j;
     98    int nBin;
     99    int numBins;
     100    static psVector *tmp = NULL;
     101    static psVector *tmpRow = NULL;
     102    static psVector *tmpCol = NULL;
     103    static psVector *tmpMask = NULL;
     104
     105    if (in == NULL) {
    62106        //XXX: psErrorMsg()
    63107    }
    64     if ((overscans != NULL) &&
    65             (overScanAxis == PM_OVERSCAN_NONE)) {
     108
     109    if ((overscans == NULL) && (overScanAxis != PM_OVERSCAN_NONE)) {
     110        //XXX: psErrorMsg()
     111    }
     112    if ((overscans != NULL) && (overScanAxis == PM_OVERSCAN_NONE)) {
    66113        //XXX: psWarningMsg()
    67         psSubtractFrame(in, bias);
    68     }
     114        return(psSubtractFrame(in, bias));
     115    }
     116
    69117    if (overScanAxis == PM_OVERSCAN_ALL) {
    70         psImageStats(in->image..., stat);
    71         psSubtractScalarFromImage(...);
    72         return()?
     118        psImageStats(stat, in->image, in->mask, 0xffffffff);
     119        p_psImageSubtractScalar(in->image, stat->value);
     120        return(in)
    73121          }
     122
    74123          if (((overScanAxis == PM_OVERSCAN_NONE) ||
    75124                  (overScanAxis == PM_OVERSCAN_ALL)) &&
     
    77126              //XXX: psWarningMsg()
    78127              //XXX: Then what?
    79           }
    80           if (overScanAxis == PM_OVERSCAN_ROW) {
    81               myVec = reduce the overscan area to a vector
    82                   }
    83                   if (overScanAxis == PM_OVERSCAN_COL) {
    84                       myVec = reduce the overscan area to a vector
    85                           }
    86                           if (nBin > 0) {
    87                               psVector *myBin = psVectorAlloc(nBin, PS_TYPE_F32);
    88                           }
    89                           if (!((fitSpec == NULL) || (fit ==PM_FIT_NONE))) {
    90                               fit the vector to a linear or cubic spline.
    91                           }
    92 
    93                           if (overScanAxis == PM_OVERSCAN_ROW) {
    94                               for (i=0;i<rows;i++)
    95                                   for (j=0;j<cols;j++)
    96                                       image[i][j]-= myBin[i];
    97                           }
    98                           if (overScanAxis == PM_OVERSCAN_COLUMN) {
    99                               for (i=0;i<rows;i++)
    100                                   for (j=0;j<cols;j++)
    101                                       image[i][j]-= myBin[j];
    102                           }
    103                           return(in);
    104 }
    105 
     128              return(in)
     129                }
     130
     131                // XXX: Is there a better way to extract a psVector from a psImage without
     132                // having to copy every element in that vector?
     133
     134                // XXX: If we get here, do we know that overScanAxis == PM_OVERSCAN_ROW
     135                // or PM_OVERSCAN_COL?
     136
     137                if ((overScanAxis == PM_OVERSCAN_ROW) || (overScanAxis == PM_OVERSCAN_COL)) {
     138                    if (overScanAxis == PM_OVERSCAN_ROW) {
     139                        tmp = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
     140                        tmpRow = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
     141                        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                        }
     150                    }
     151                    if (overScanAxis == PM_OVERSCAN_COL) {
     152                        tmp = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
     153                        tmpcol = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
     154                        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);
     167                        psVector *myBin = psVectorAlloc(numBins, PS_TYPE_F32);
     168
     169                        for (i=0;i<numBins;i++) {
     170                            // XXX: do this
     171                        }
     172                        // XXX: resize tmp to myBin, and store myBin elements there.
     173                    } else {
     174                        nBin = 1;
     175                    }
     176
     177                    if (!((fitSpec == NULL) || (fit ==PM_FIT_NONE))) {
     178                        fit the vector to a linear or cubic spline.
     179                    }
     180
     181                    if (overScanAxis == PM_OVERSCAN_ROW) {
     182                        for (i=0;i<(in->image)->numCols;i++) {
     183                            for (j=0;j<(in->image)->numRows;j++) {
     184                                (in->image)->data.F32[i][j]-= tmp->data.F32[j/nBin];
     185                            }
     186                        }
     187                    }
     188
     189                    if (overScanAxis == PM_OVERSCAN_COLUMN) {
     190                        for (i=0;i<(in->image)->numRows;i++) {
     191                            for (j=0;j<(in->image)->numCols;j++) {
     192                                (in->image)->data.F32[i][j]-= tmp->data.F32[j/nBin];
     193                            }
     194                        }
     195                    }
     196                    return(in);
     197                }
     198
     199                if (bias != NULL) {
     200                    return(psSubtractFrame(in, bias));
     201                }
     202
     203                // XXX: psErrorMsg(): Shouldn't get here?
     204            }
     205
Note: See TracChangeset for help on using the changeset viewer.