IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14775


Ignore:
Timestamp:
Sep 7, 2007, 10:19:48 AM (19 years ago)
Author:
magnier
Message:

more testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMap.c

    r14726 r14775  
    2626
    2727    // make a model for a well-sampled field of a simple function (f = ax + by + c)
     28    # if (0)
    2829    {
    2930        // function is defined over the range 0-1000, 0-1000
     
    3940        psVector *f = psVectorAllocEmpty (100, PS_TYPE_F32);
    4041
    41         for (int ix = 0; ix < 1000; ix += 10) {
    42             for (int iy = 0; iy < 1000; iy += 10) {
     42        for (int ix = 0; ix < 1000; ix += 20) {
     43            for (int iy = 0; iy < 1000; iy += 20) {
    4344                x->data.F32[x->n] = ix;
    4445                y->data.F32[y->n] = iy;
     
    7879        for (int ix = 0; ix < map->map->numCols; ix++) {
    7980            for (int iy = 0; iy < map->map->numRows; iy++) {
    80              
    81                 int xo = (ix + 0.5)*map->binning->nXbin;
    82                 int yo = (iy + 0.5)*map->binning->nYbin;
     81                int xo = psImageBinningGetFineX(map->binning, ix + 0.5);
     82                int yo = psImageBinningGetFineY(map->binning, iy + 0.5);
    8383                float df = field->data.F32[yo][xo] - map->map->data.F32[iy][ix];
    8484                fprintf (stderr, "%d %d -> %d %d  :  %f = %f - %f\n", ix, iy, xo, yo, df, field->data.F32[yo][xo], map->map->data.F32[iy][ix]);
    8585            }
    8686        }
     87
     88        psImage *model = psImageAlloc(1000, 1000, PS_TYPE_F32);
     89        for (int ix = 0; ix < 1000; ix++) {
     90            for (int iy = 0; iy < 1000; iy++) {
     91                model->data.F32[iy][ix] = psImageUnbinPixel (ix + 0.5, iy + 0.5, map->map, map->binning);
     92            }
     93        }
     94        SaveImage (NULL, model, "model.fits");
    8795    }
     96    # endif
    8897
    8998    // make a model for a poorly-sampled field of a simple function (f = ax + by + c)
     
    91100    // choose a model scale for a poorly-sampled field of a simple function (f = ax + by + c)
    92101
    93     // make a model for a well-sampled field of a non-polynomial function (f = (a(x-xo)^2 + b(y-yo)^2)^-1)
     102    // make a model for a well-sampled field of a high-order polynomial function (f = (a(x-xo)^2 + b(y-yo)^2) + c)
     103    # if (0)
    94104    {
    95105        // function is defined over the range 0-1000, 0-1000
     
    105115        psVector *f = psVectorAllocEmpty (100, PS_TYPE_F32);
    106116
    107         for (int ix = 0; ix < 1000; ix += 10) {
    108             for (int iy = 0; iy < 1000; iy += 10) {
     117        for (int ix = 0; ix < 1000; ix += 20) {
     118            for (int iy = 0; iy < 1000; iy += 20) {
    109119                x->data.F32[x->n] = ix;
    110120                y->data.F32[y->n] = iy;
    111                 f->data.F32[f->n] = C00 / (C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500) + 0.1);
     121                f->data.F32[f->n] = C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500);
    112122                psVectorExtend (x, 100, 1);
    113123                psVectorExtend (y, 100, 1);
     
    136146        for (int ix = 0; ix < 1000; ix++) {
    137147            for (int iy = 0; iy < 1000; iy++) {
    138                 field->data.F32[iy][ix] = C00 / (C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500) + 0.1);
     148                field->data.F32[iy][ix] = C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500);
    139149            }
    140150        }
     
    144154        for (int ix = 0; ix < map->map->numCols; ix++) {
    145155            for (int iy = 0; iy < map->map->numRows; iy++) {
    146              
    147                 int xo = (ix + 0.5)*map->binning->nXbin;
    148                 int yo = (iy + 0.5)*map->binning->nYbin;
     156                int xo = psImageBinningGetFineX(map->binning, ix + 0.5);
     157                int yo = psImageBinningGetFineY(map->binning, iy + 0.5);
    149158                float df = field->data.F32[yo][xo] - map->map->data.F32[iy][ix];
    150159                fprintf (stderr, "%d %d -> %d %d  :  %f = %f - %f\n", ix, iy, xo, yo, df, field->data.F32[yo][xo], map->map->data.F32[iy][ix]);
     
    152161        }
    153162    }
     163    # endif
     164
     165    // make a model for a well-sampled field of a high-order polynomial function (f = (a(x-xo)^2 + b(y-yo)^2) + c)
     166    # if (1)
     167    {
     168        // function is defined over the range 0-1000, 0-1000
     169        psImageBinning *binning = psImageBinningAlloc();
     170        binning->nXfine = 1000;
     171        binning->nYfine = 1000;
     172        binning->nXruff = 5;
     173        binning->nYruff = 5;
     174
     175        // generate a grid of test data points
     176        psVector *x = psVectorAllocEmpty (100, PS_TYPE_F32);
     177        psVector *y = psVectorAllocEmpty (100, PS_TYPE_F32);
     178        psVector *f = psVectorAllocEmpty (100, PS_TYPE_F32);
     179
     180        for (int ix = 0; ix < 1000; ix += 20) {
     181            for (int iy = 0; iy < 1000; iy += 20) {
     182                x->data.F32[x->n] = ix;
     183                y->data.F32[y->n] = iy;
     184                f->data.F32[f->n] = C10*(ix-500) + PS_SQR(C01*(iy-500));
     185                psVectorExtend (x, 100, 1);
     186                psVectorExtend (y, 100, 1);
     187                psVectorExtend (f, 100, 1);
     188            }
     189        }
     190
     191        psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     192
     193        // scale defines both field and map image sizes (nXfine, nXruff)
     194        psImageMap *map = psImageMapAlloc (NULL, binning, stats);
     195
     196        // allocate a map, but we have no field image to supply
     197        // XXX this function needs to correct for the mean superpixel position
     198        // which is sampled...
     199        psImageMapGenerate (map, x, y, f, 0.1);
     200        psFree (binning);
     201
     202        fprintf (stderr, "nGood: %d\n", map->nGood);
     203        fprintf (stderr, "nPoor: %d\n", map->nPoor);
     204        fprintf (stderr, "nBad:  %d\n", map->nBad);
     205       
     206        SaveImage (NULL, map->map, "map.fits");
     207       
     208        psImage *field = psImageAlloc(1000, 1000, PS_TYPE_F32);
     209        for (int ix = 0; ix < 1000; ix++) {
     210            for (int iy = 0; iy < 1000; iy++) {
     211                field->data.F32[iy][ix] = C10*(ix-500) + PS_SQR(C01*(iy-500));
     212            }
     213        }
     214        SaveImage (NULL, field, "field.fits");
     215
     216        // measure difference between model (map) and data (field)
     217        for (int ix = 0; ix < map->map->numCols; ix++) {
     218            for (int iy = 0; iy < map->map->numRows; iy++) {
     219                int xo = psImageBinningGetFineX(map->binning, ix + 0.5);
     220                int yo = psImageBinningGetFineY(map->binning, iy + 0.5);
     221                float df = field->data.F32[yo][xo] - map->map->data.F32[iy][ix];
     222                fprintf (stderr, "%d %d -> %d %d  :  %f = %f - %f\n", ix, iy, xo, yo, df, field->data.F32[yo][xo], map->map->data.F32[iy][ix]);
     223            }
     224        }
     225
     226
     227        psImage *model = psImageAlloc(1000, 1000, PS_TYPE_F32);
     228        for (int ix = 0; ix < 1000; ix++) {
     229            for (int iy = 0; iy < 1000; iy++) {
     230                // XXX the binned coordinates are probably off by 0.5 pix, or we are interpolating
     231                // to the wrong binned coordinate. 
     232                // XXX fix edge cases
     233                model->data.F32[iy][ix] = psImageUnbinPixel (ix + 0.5, iy + 0.5, map->map, map->binning);
     234            }
     235        }
     236        SaveImage (NULL, model, "model.fits");
     237    }
     238    # endif
    154239
    155240    // make a model for a poorly-sampled field of a non-polynomial function (f = (a(x-xo)^2 + b(y-yo)^2)^-1)
Note: See TracChangeset for help on using the changeset viewer.