IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 21, 2007, 5:05:50 PM (19 years ago)
Author:
Paul Price
Message:

Including psMemory.h where required.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageMap.c

    r14924 r14983  
    77 *  @author Eugene Magnier, IfA
    88 *
    9  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-09-20 23:54:25 $
     9 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-09-22 03:05:50 $
    1111 *
    1212 *  Copyright 2007 Institute for Astronomy, University of Hawaii
     
    1818
    1919#include <stdio.h>
     20
    2021#include "psError.h"
    2122#include "psAbort.h"
     
    2627#include "psFitsImage.h"
    2728
     29#include "psMemory.h"
    2830#include "psVector.h"
    2931#include "psImage.h"
     
    9698
    9799    // accumulate the values for each map pixel
    98    
     100
    99101    // we can do this by accumulating a vector of pixel indexes for each cell
    100102    psArray *pixelSets = psArrayAlloc (map->map->numCols*map->map->numRows);
    101103    for (int i = 0; i < pixelSets->n; i++) {
    102         pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32);
     104        pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32);
    103105    }
    104106    // associate each value with a cell
    105107    for (int i = 0; i < x->n; i++) {
    106         int xRuff = psImageBinningGetRuffX (map->binning, x->data.F32[i]);
    107         int yRuff = psImageBinningGetRuffY (map->binning, y->data.F32[i]);
    108 
    109         int bin = xRuff + yRuff*map->map->numCols;
    110         assert (bin >= 0);
    111         assert (bin < pixelSets->n);
    112        
    113         psVector *pixels = pixelSets->data[bin];
    114         pixels->data.S32[pixels->n] = i;
    115         psVectorExtend (pixels, 4, 1);
     108        int xRuff = psImageBinningGetRuffX (map->binning, x->data.F32[i]);
     109        int yRuff = psImageBinningGetRuffY (map->binning, y->data.F32[i]);
     110
     111        int bin = xRuff + yRuff*map->map->numCols;
     112        assert (bin >= 0);
     113        assert (bin < pixelSets->n);
     114
     115        psVector *pixels = pixelSets->data[bin];
     116        pixels->data.S32[pixels->n] = i;
     117        psVectorExtend (pixels, 4, 1);
    116118    }
    117119
     
    123125    int Ny = map->map->numRows;
    124126    for (int iy = 0; iy < Ny; iy++) {
    125         for (int ix = 0; ix < Nx; ix++) {
    126    
    127             // pixel index for this cell
    128             psVector *pixels = pixelSets->data[ix + iy*Nx];
    129 
    130             // storage vectors
    131             psVector *xCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
    132             psVector *yCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
    133             psVector *fCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
    134 
    135             // error vector, if needed
    136             psVector *dfCell = NULL;
    137             if (df) {
    138                 dfCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
    139             }           
    140 
    141             // collect data for this cell
    142             for (int i = 0; i < pixels->n; i++) {
    143                 int bin = pixels->data.S32[i];
    144                 // convert x,y in the fine image to the ruff image
    145                 xCell->data.F32[i]  = psImageBinningGetRuffX (map->binning, x->data.F32[bin]);
    146                 yCell->data.F32[i]  = psImageBinningGetRuffY (map->binning, y->data.F32[bin]);
    147                 fCell->data.F32[i]  = f->data.F32[bin];
    148                 if (df) {
    149                     dfCell->data.F32[i] = df->data.F32[bin];
    150                 }
    151             }
    152 
    153             // reset the stats to avoid contamination from the previous loop
    154             psStatsInit (map->stats);
    155 
    156             // get the value
    157             // XXX need to supply a mask and skip the masked pixels when calculating the centroid
    158             // this will not in general be properly weighted...
    159             if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
    160                 mask->data.U8[iy][ix] = 0;
    161                 // XXX ensure only one option is selected, or save both position and width
    162                 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
    163 
    164                 // calculate the mean position and save:
    165                 psStatsInit (meanStat);
    166                 psVectorStats (meanStat, xCell, NULL, NULL, 0);
    167                 xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    168                 psStatsInit (meanStat);
    169                 psVectorStats (meanStat, yCell, NULL, NULL, 0);
    170                 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    171             } else {
    172                 mask->data.U8[iy][ix] = 1;
    173             }
    174            
    175             psFree (xCell);
    176             psFree (yCell);
    177             psFree (fCell);
    178             psFree (dfCell);
    179         }
     127        for (int ix = 0; ix < Nx; ix++) {
     128
     129            // pixel index for this cell
     130            psVector *pixels = pixelSets->data[ix + iy*Nx];
     131
     132            // storage vectors
     133            psVector *xCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     134            psVector *yCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     135            psVector *fCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     136
     137            // error vector, if needed
     138            psVector *dfCell = NULL;
     139            if (df) {
     140                dfCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
     141            }
     142
     143            // collect data for this cell
     144            for (int i = 0; i < pixels->n; i++) {
     145                int bin = pixels->data.S32[i];
     146                // convert x,y in the fine image to the ruff image
     147                xCell->data.F32[i]  = psImageBinningGetRuffX (map->binning, x->data.F32[bin]);
     148                yCell->data.F32[i]  = psImageBinningGetRuffY (map->binning, y->data.F32[bin]);
     149                fCell->data.F32[i]  = f->data.F32[bin];
     150                if (df) {
     151                    dfCell->data.F32[i] = df->data.F32[bin];
     152                }
     153            }
     154
     155            // reset the stats to avoid contamination from the previous loop
     156            psStatsInit (map->stats);
     157
     158            // get the value
     159            // XXX need to supply a mask and skip the masked pixels when calculating the centroid
     160            // this will not in general be properly weighted...
     161            if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
     162                mask->data.U8[iy][ix] = 0;
     163                // XXX ensure only one option is selected, or save both position and width
     164                map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
     165
     166                // calculate the mean position and save:
     167                psStatsInit (meanStat);
     168                psVectorStats (meanStat, xCell, NULL, NULL, 0);
     169                xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
     170                psStatsInit (meanStat);
     171                psVectorStats (meanStat, yCell, NULL, NULL, 0);
     172                yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
     173            } else {
     174                mask->data.U8[iy][ix] = 1;
     175            }
     176
     177            psFree (xCell);
     178            psFree (yCell);
     179            psFree (fCell);
     180            psFree (dfCell);
     181        }
    180182    }
    181183    psFree (pixelSets);
     
    193195    map->nGood = mask->numCols * mask->numRows - map->nBad - map->nPoor;
    194196    if (map->nBad > badFrac * mask->numCols * mask->numRows) {
    195         psFree (xCoord);
    196         psFree (yCoord);
    197         psFree (mask);
    198         return false;
     197        psFree (xCoord);
     198        psFree (yCoord);
     199        psFree (mask);
     200        return false;
    199201    }
    200202
     
    222224// using the points given, generate a map with maximum resolution that yields only good and ok pixels
    223225bool psImageMapGenerateScale (psImageMap *map, psVector *x, psVector *y, psVector *f, psVector *df, float badFrac) {
    224    
     226
    225227    int nXruff, nYruff;
    226        
     228
    227229    while (!psImageMapGenerate (map, x, y, f, df, badFrac)) {
    228         // if we failed to build an acceptable map, decrease nXruff, nYruff as appropriate, and
    229         // try again...  try to keep the aspect ratio.
    230 
    231         // if both axes are at 1, give up
    232         if ((map->binning->nXruff == 1) && (map->binning->nYruff == 1)) {
    233             return false;
    234         }
    235 
    236         // if one axis is at 1, decrement the other
    237         if (map->binning->nXruff == 1) {
    238             nXruff = map->binning->nXruff;
    239             nYruff = map->binning->nYruff - 1;
    240             psImageMapModifyScale (map, nXruff, nYruff);
    241             continue;
    242         }
    243         if (map->binning->nYruff == 1) {
    244             nYruff = map->binning->nYruff;
    245             nXruff = map->binning->nXruff - 1;
    246             psImageMapModifyScale (map, nXruff, nYruff);
    247             continue;
    248         }
    249 
    250         // otherwise, decrement the larger axis, and set the smaller based
    251         // on the aspect ratio
    252         float aRatio = map->binning->nXruff / map->binning->nYruff;
    253         if (map->binning->nXruff > map->binning->nYruff) {
    254             nXruff = map->binning->nXruff - 1;
    255             nYruff = (int)(0.5 + (nXruff / aRatio));
    256         } else {
    257             nYruff = map->binning->nYruff - 1;
    258             nXruff = (int)(0.5 + (nYruff * aRatio));
    259         }
    260 
    261         psImageMapModifyScale (map, nXruff, nYruff);
     230        // if we failed to build an acceptable map, decrease nXruff, nYruff as appropriate, and
     231        // try again...  try to keep the aspect ratio.
     232
     233        // if both axes are at 1, give up
     234        if ((map->binning->nXruff == 1) && (map->binning->nYruff == 1)) {
     235            return false;
     236        }
     237
     238        // if one axis is at 1, decrement the other
     239        if (map->binning->nXruff == 1) {
     240            nXruff = map->binning->nXruff;
     241            nYruff = map->binning->nYruff - 1;
     242            psImageMapModifyScale (map, nXruff, nYruff);
     243            continue;
     244        }
     245        if (map->binning->nYruff == 1) {
     246            nYruff = map->binning->nYruff;
     247            nXruff = map->binning->nXruff - 1;
     248            psImageMapModifyScale (map, nXruff, nYruff);
     249            continue;
     250        }
     251
     252        // otherwise, decrement the larger axis, and set the smaller based
     253        // on the aspect ratio
     254        float aRatio = map->binning->nXruff / map->binning->nYruff;
     255        if (map->binning->nXruff > map->binning->nYruff) {
     256            nXruff = map->binning->nXruff - 1;
     257            nYruff = (int)(0.5 + (nXruff / aRatio));
     258        } else {
     259            nYruff = map->binning->nYruff - 1;
     260            nXruff = (int)(0.5 + (nYruff * aRatio));
     261        }
     262
     263        psImageMapModifyScale (map, nXruff, nYruff);
    262264    }
    263265    return true;
     
    271273    result = psImageUnbinPixel_V2(x, y, map->map, map->binning);
    272274
    273     return result; 
     275    return result;
    274276}
    275277
     
    284286
    285287    for (int i = 0; i < x->n; i++) {
    286         result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning);
    287     }
    288 
    289     return result; 
    290 }
     288        result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning);
     289    }
     290
     291    return result;
     292}
Note: See TracChangeset for help on using the changeset viewer.