IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30981


Ignore:
Timestamp:
Mar 18, 2011, 5:29:30 PM (15 years ago)
Author:
mwv
Message:

Fixes from MWV and Paul for randomn sky sampling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110213/psLib/src/imageops/psImageBackground.c

    r27069 r30981  
    8686
    8787                float value = image->data.F32[iy][ix];
     88                // 2011/03/16 - MWV:  Keep a running overall min and max
    8889                min = PS_MIN(value, min);
    8990                max = PS_MAX(value, max);
     
    9394        }
    9495    } else {
     96        // 2011/03/16 - MWV: Hmmm... this overwites the previously defined Npixels that only counted finite-valued pixels.
     97        Npixels = nx * ny;
     98
    9599        // Subsample all pixels
    96100        // This is not optimal, since there may be a large masked fraction that leaves us with few good pixels.
    97101        // In that case, you should have set Nsubset.......
    98         Npixels = nx * ny;
    99         for (long i = 0; i < Nsubset; i++) {
    100             double frnd = psRandomUniform(rng);
    101             int pixel = Npixels * frnd;
     102        // 2011/03/16 - MWV:  Fixed double-sampling of sky pixels.
     103        //   The pick-a-random-pixel-at-a-time approach  doesn't work well when Npixels is close to Nsubset
     104        //   If Nsubset is 0.8*Npixels, then we will get lots of pixels double-counted
     105        //   This is correct on average, but isn't the optimal way to estimate the sky level
     106        // I suggest instead the following approach:
     107        //   1) Calculate a random ordering of the pixels
     108        //   2) Go through this ordering up to Nsubset to select pixels
     109        psVector *frndPixelOrder = psVectorAlloc(Npixels, PS_TYPE_F32);
     110        for (long i = 0; i < Npixels; i++) {
     111            frndPixelOrder->data.F32[i] = psRandomUniform(rng);
     112        }
     113        // Now sort the array so that we end up with a list of the pixels in random order
     114        psVector *frndSortedPixelOrder = psVectorSortIndex(NULL, frndPixelOrder);
     115        // Now loop in our new sorted order;
     116        // Note that it's the number of good samples found, "n", that will generally terminate the loop
     117        for (long i = 0; n < Nsubset && i < Npixels; i++) {
     118            int pixel = frndSortedPixelOrder->data.S32[i];
    102119            int ix = pixel % nx;
    103120            int iy = pixel / nx;
     
    108125
    109126            float value = image->data.F32[iy][ix];
     127            // 2011/03/16 - MWV:  Keep a running overall min and max
    110128            min = PS_MIN(value, min);
    111129            max = PS_MAX(value, max);
Note: See TracChangeset for help on using the changeset viewer.