IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2006, 5:37:11 PM (20 years ago)
Author:
Paul Price
Message:

Moving pslib additional functions from psModules into psLib proper; some API changes fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotImageMedian.c

    r7341 r7385  
    33// generate the median in NxN boxes, clipping heavily
    44// linear interpolation to generate full-scale model
    5 bool psphotImageMedian (pmConfig *config, pmFPAview *view) 
    6 { 
     5bool psphotImageMedian (pmConfig *config, pmFPAview *view)
     6{
    77    bool status;
    88    psRegion region;
     
    1515
    1616    MAX_SAMPLE_PIXELS = psMetadataLookupF32 (&status, recipe, "IMSTATS_NPIX");
    17     if (!status) MAX_SAMPLE_PIXELS = 1000;
     17    if (!status) {
     18        MAX_SAMPLE_PIXELS = 1000;
     19    }
    1820    unsigned long seed = psMetadataLookupS32 (&status, recipe, "IMSTATS_SEED");
    19     if (!status) seed = 0;
    20     psImageClippedStatsInit(MAX_SAMPLE_PIXELS, seed);
     21    if (!status) {
     22        seed = 0;
     23    }
     24    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, seed);
    2125
    2226    // subtract this amount extra from the sky
    2327    float SKY_BIAS = psMetadataLookupF32 (&status, recipe, "SKY_BIAS");
    24     if (!status) SKY_BIAS = 0;
     28    if (!status) {
     29        SKY_BIAS = 0;
     30    }
    2531
    2632    // find the currently selected readout
     
    4955    pmReadout *model = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKMDL");
    5056    if (model == NULL) {
    51         // select model pixels, from output background model file, or create
    52         model = pmFPAfileCreateInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32);
     57        // select model pixels, from output background model file, or create
     58        model = pmFPAfileCreateInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32);
    5359    } else {
    54         // replace the supplied image data with an image of the desired size
    55         psImageRecycle (model->image, nx, ny, PS_TYPE_F32);
     60        // replace the supplied image data with an image of the desired size
     61        psImageRecycle (model->image, nx, ny, PS_TYPE_F32);
    5662    }
    5763    psF32 **modelData = model->image->data.F32;
    5864
    59     // measure clipped median for subimages 
     65    // measure clipped median for subimages
    6066    for (int iy = 0; iy < ny; iy++) {
    61         for (int ix = 0; ix < nx; ix++) {
    62             // sx, sy are in parent coords
    63             int sx = ix*DX - dx + image->col0;
    64             int sy = iy*DY - dy + image->row0;
    65             region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY);
    66             region = psRegionForImage (image, region);
    67             psImage *subset  = psImageSubset (image, region);
    68             psImage *submask = psImageSubset (mask, region);
     67        for (int ix = 0; ix < nx; ix++) {
     68            // sx, sy are in parent coords
     69            int sx = ix*DX - dx + image->col0;
     70            int sy = iy*DY - dy + image->row0;
     71            region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY);
     72            region = psRegionForImage (image, region);
     73            psImage *subset  = psImageSubset (image, region);
     74            psImage *submask = psImageSubset (mask, region);
    6975
    70             // XXX the value of the upper and lower cuts probably should be studied...
    71             psStats *stats = psImageClippedStats (subset, submask, 0xff, 0.25, 0.75);
    72             modelData[iy][ix] = stats->robustMedian + SKY_BIAS;
     76            // XXX the value of the upper and lower cuts probably should be studied...
     77            psStats *stats = psImageBackground(subset, submask, 0xff, 0.25, 0.75, MAX_SAMPLE_PIXELS, rng);
     78            modelData[iy][ix] = stats->robustMedian + SKY_BIAS;
    7379
    74             psFree (stats);
    75             psFree (subset);
    76             psFree (submask);
     80            psFree (stats);
     81            psFree (subset);
     82            psFree (submask);
    7783
    78             // XXX psImageStats is still very inefficient and poorly coded...
    79             // psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    80             // stats = psImageStats (stats, subset, maskset, 0xff);
    81             // backMdl->data.F32[iy][ix] = stats->clippedMean;
    82         }
     84            // XXX psImageStats is still very inefficient and poorly coded...
     85            // psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     86            // stats = psImageStats (stats, subset, maskset, 0xff);
     87            // backMdl->data.F32[iy][ix] = stats->clippedMean;
     88        }
    8389    }
    8490    psLogMsg ("psphot", 3, "build median image: %f sec\n", psTimerMark ("psphot"));
     
    98104    pmReadout *background = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKGND");
    99105    if (background == NULL) {
    100         background = pmFPAfileCreateInternal (config->files, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32);
    101     } 
     106        background = pmFPAfileCreateInternal (config->files, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32);
     107    }
    102108    psF32 **backData = background->image->data.F32;
    103109
     
    115121    // subtract the background model (save in backSub, if requested)
    116122    for (int j = 0; j < image->numRows; j++) {
    117         for (int i = 0; i < image->numCols; i++) {
    118             if (!mask->data.U8[j][i]) {
    119                 image->data.F32[j][i] -= backData[j][i];
    120                 if (backSub) {
    121                     backSub->image->data.F32[j][i] = image->data.F32[j][i];
    122                 }
    123             }
    124         }
     123        for (int i = 0; i < image->numCols; i++) {
     124            if (!mask->data.U8[j][i]) {
     125                image->data.F32[j][i] -= backData[j][i];
     126                if (backSub) {
     127                    backSub->image->data.F32[j][i] = image->data.F32[j][i];
     128                }
     129            }
     130        }
    125131    }
    126132
    127133    psLogMsg ("psphot", 3, "subtracted background model: %f sec\n", psTimerMark ("psphot"));
    128     psImageClippedStatsCleanup();
     134    psFree(rng);
    129135
    130136    // the pmReadout selected in this function are all view on entries in config->files
Note: See TracChangeset for help on using the changeset viewer.