IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30956


Ignore:
Timestamp:
Mar 17, 2011, 4:34:04 PM (15 years ago)
Author:
mwv
Message:

Updated random selection of sky pixels
to not double-select pixels.
This stabilizes selection of Nsubset pixels
as Nsubset approaches Npixels for a supercell.

File:
1 edited

Legend:

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

    r27069 r30956  
    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        //  Paul Price suggests fixing this up so that it gets all Nsubset pixels, skipping over the masked ones.
     117        //  This would be implemented with a while loop.  I'm leaving this comment-out till I test the simpler version that just makes this one conceptual change.
     118        //  Ah, we can just use n
     119        int i=0;
     120        while ((n < Nsubset) && (i < Npixels)) {
     121            i++;
     122//        for (long i = 0; i < Nsubset; i++) {
     123            int pixel = frndSortedPixelOrder->data.S32[i];
    102124            int ix = pixel % nx;
    103125            int iy = pixel / nx;
     
    108130
    109131            float value = image->data.F32[iy][ix];
     132            // 2011/03/16 - MWV:  Keep a running overall min and max
    110133            min = PS_MIN(value, min);
    111134            max = PS_MAX(value, max);
Note: See TracChangeset for help on using the changeset viewer.