IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11311


Ignore:
Timestamp:
Jan 25, 2007, 6:52:28 PM (19 years ago)
Author:
eugene
Message:

fixed definition of binned image range XBIN, XOFF, etc

File:
1 edited

Legend:

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

    r11263 r11311  
    11# include "psphot.h"
     2# define TESTSAVE
    23
    34// generate the median in NxN boxes, clipping heavily
     
    8081
    8182    // overhang : we will balance this evenly
    82     int dx = (Nx % DX) / 2;
    83     int dy = (Ny % DY) / 2;
     83    int xExtra = (Nx % DX) / 2;
     84    int yExtra = (Ny % DY) / 2;
     85    int xOffset = (xExtra > 0) ? DX - xExtra : 0;
     86    int yOffset = (yExtra > 0) ? DY - yExtra : 0;
     87    xOffset -= image->col0;
     88    yOffset -= image->row0;
    8489
    8590    // dimensions of binned image
    86     int nx = (Nx % DX) ? (int)(Nx / DX) + 1 : Nx / DX;
    87     int ny = (Ny % DY) ? (int)(Ny / DY) + 1 : Ny / DY;
     91    int nx, ny;
     92    if (Nx % DX == 0) {
     93        nx = Nx / DX;
     94    } else {
     95        nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1;
     96    }
     97    if (Ny % DY == 0) {
     98        ny = Ny / DY;
     99    } else {
     100        ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1;
     101    }
    88102
    89103    // select model pixels (from output background model file, or create internal file)
     
    108122
    109123    assert(model->analysis != NULL);
    110     psMetadataAdd(model->analysis, PS_LIST_TAIL, "XBIN", PS_DATA_S32 | PS_META_REPLACE,
     124    psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XBIN", PS_DATA_S32 | PS_META_REPLACE,
    111125                  "Background x-binsize", DX);
    112     psMetadataAdd(model->analysis, PS_LIST_TAIL, "YBIN", PS_DATA_S32 | PS_META_REPLACE,
     126    psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YBIN", PS_DATA_S32 | PS_META_REPLACE,
    113127                  "Background x-binsize", DY);
    114     psMetadataAdd(model->analysis, PS_LIST_TAIL, "x0", PS_DATA_S32 | PS_META_REPLACE,
    115                   "Background x-overhang", dx);
    116     psMetadataAdd(model->analysis, PS_LIST_TAIL, "y0", PS_DATA_S32 | PS_META_REPLACE,
    117                   "Background y-overhang", dy);
     128    psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XOFF", PS_DATA_S32 | PS_META_REPLACE,
     129                  "Background x-overhang", xOffset);
     130    psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YOFF", PS_DATA_S32 | PS_META_REPLACE,
     131                  "Background y-overhang", yOffset);
     132
    118133
    119134    // measure clipped median for subimages
     
    121136        for (int ix = 0; ix < nx; ix++) {
    122137            // sx, sy are in parent coords
    123             int sx = ix*DX - dx + image->col0;
    124             int sy = iy*DY - dy + image->row0;
     138            int sx = ix*DX - xOffset;
     139            int sy = iy*DY - yOffset;
    125140            region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY);
    126141            region = psRegionForImage (image, region);
     
    133148            psImage *submask = psImageSubset (mask, region);
    134149
    135             // XXX the value of the upper and lower cuts probably should be studied...
     150            // Use the selected background statistic for the first pass
     151            // If it fails, fall back on the "ROBUST_MEDIAN" version
     152            // If both fail, set the pixel to NAN and (below) interpolate
     153            // XXX psImageBackground will probably be renamed psImageStats
    136154            if (psImageBackground(stats, subset, submask, 0xff, rng)) {
    137155                if (stats->options & PS_STAT_ROBUST_QUARTILE) {
     
    151169                    modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);
    152170                }
    153                 psErrorClear(); // drop errors caused by this condition
     171                // drop errors caused by psImageBackground failures
     172                // XXX we probably should trap and exit on serious failures
     173                psErrorClear();
    154174                stats->options = currentOptions;
    155175            }
    156176            modelData[iy][ix] += SKY_BIAS;
    157 
    158177            psFree (subset);
    159178            psFree (submask);
    160 
    161             // XXX psImageStats is still very inefficient and poorly coded...
    162             // psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    163             // stats = psImageStats (stats, subset, maskset, 0xff);
    164             // backMdl->data.F32[iy][ix] = stats->clippedMean;
    165179        }
    166180    }
     
    243257
    244258    // linear interpolation to full-scale
    245     psImageUnbin (background->image, model->image, DX, DY, dx, dy);
     259    if (!psImageUnbin (background->image, model->image, DX, DY, xOffset, yOffset)) {
     260        psError (PSPHOT_ERR_PROG, true, "failed to build background iamge");
     261        return false;
     262    }
     263       
    246264    psLogMsg ("psphot", PS_LOG_MINUTIA, "build resampled image: %f sec\n", psTimerMark ("psphot"));
    247265
Note: See TracChangeset for help on using the changeset viewer.