IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 3, 2007, 10:29:07 AM (19 years ago)
Author:
magnier
Message:

updates to image map code, tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psLib/src/imageops/psImageMap.c

    r14725 r14726  
    77 *  @author Eugene Magnier, IfA
    88 *
    9  *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-09-02 20:29:50 $
     9 *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-09-03 20:29:07 $
    1111 *
    1212 *  Copyright 2007 Institute for Astronomy, University of Hawaii
     
    6363
    6464    psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK);
     65    psImage *xCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32);
     66    psImage *yCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32);
    6567
    6668    // accumulate the values for each map pixel
    6769   
    68     // we can do this by accumulating a sub-vector for each cell
    69     psArray *vectors = psArrayAlloc (map->map->numCols*map->map->numRows);
    70     for (int i = 0; i < vectors->n; i++) {
    71         vectors->data[i] = psVectorAllocEmpty (4, PS_TYPE_F32);
     70    // we can do this by accumulating a vector of pixel indexes for each cell
     71    psArray *pixelSets = psArrayAlloc (map->map->numCols*map->map->numRows);
     72    for (int i = 0; i < pixelsSets->n; i++) {
     73        pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32);
    7274    }
    73 
     75    // associate each value with a cell
    7476    for (int i = 0; i < x->n; i++) {
    75        
     77        // XXX use the psImageUnbin command to convert from x,y, to xRuff,yRuff?
    7678        int xRuff = x->data.F32[i] / map->binning->nXbin;
    7779        int yRuff = y->data.F32[i] / map->binning->nYbin;
     
    7981        int bin = xRuff + yRuff*map->map->numCols;
    8082       
    81         psVector *vector = vectors->data[bin];
    82         vector->data.F32[vector->n] = f->data.F32[i];
     83        psVector *pixels = pixelSets->data[bin];
     84        pixels->data.S32[pixels->n] = i;
    8385        psVectorExtend (vector, 4, 1);
    8486    }
    8587
     88    // accumulate the x,y coords for each point to calculate the mean position.
    8689    int Nx = map->map->numCols;
    8790    int Ny = map->map->numRows;
     
    8992        for (int ix = 0; ix < Nx; ix++) {
    9093   
    91             // select the vector
    92             psVector *vector = vectors->data[ix + iy*Nx];
     94            // select the vector.  use psImageUnbin command to convert xRuff,yRuff to
     95            // xFine,yFine
     96            psVector *pixels = pixelSets->data[ix + iy*Nx];
     97
     98            psVector xCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     99            psVector yCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     100            psVector fCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     101
     102            for (int i = 0; i < pixels->n; i++) {
     103                bin = pixels->data.S32[i];
     104                xCell->data.F32[i] = x->data.F32[bin];
     105                yCell->data.F32[i] = y->data.F32[bin];
     106                fCell->data.F32[i] = f->data.F32[bin];
     107            }
    93108
    94109            // reset the stats to avoid contamination from the previous loop
     
    96111
    97112            // get the value
    98             if (psVectorStats (map->stats, vector, NULL, NULL, 0)) {
     113            // XXX need to supply a mask and skip the masked pixels when calculating the centroid
     114            // this will not in general be properly weighted...
     115            if (psVectorStats (map->stats, fCell, NULL, NULL, 0)) {
    99116                mask->data.U8[iy][ix] = 0;
    100117                // XXX ensure only one option is selected, or save both position and width
    101118                map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
     119
     120                // calculate the mean position and save:
     121                psVectorStats (meanStat, xCell, NULL, NULL, 0);
     122                xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
     123                psVectorStats (meanStat, yCell, NULL, NULL, 0);
     124                yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    102125            } else {
    103126                mask->data.U8[iy][ix] = 1;
    104127            }
     128           
     129            psFree (xCell);
     130            psFree (yCell);
     131            psFree (fCell);
    105132        }
    106133    }
     134
     135    // at this point, for each map pixel, we have (f,x,y), or the pixel is masked.
    107136
    108137    psImage *state = psImagePixelInterpolateState (&map->nBad, &map->nPoor, mask, 0xff);
     
    112141    }
    113142
     143    // fit the valid pixels to (0,1,2) order polynomials, interpolate values to the pixel center
     144    // XXX I need to be careful about the pixel coordinates: center is 0,0 or 0.5, 0.5?
     145    psImagePixelInterpolateCenters (map->map, xCoord, yCoord, state, mask, 0xff);
     146    psFree (xCoord);
     147    psFree (yCoord);
     148
    114149    psImagePixelInterpolatePoor (map->map, state, mask, 0xff);
     150
    115151    return true;
    116152}
Note: See TracChangeset for help on using the changeset viewer.