Changeset 30981
- Timestamp:
- Mar 18, 2011, 5:29:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110213/psLib/src/imageops/psImageBackground.c
r27069 r30981 86 86 87 87 float value = image->data.F32[iy][ix]; 88 // 2011/03/16 - MWV: Keep a running overall min and max 88 89 min = PS_MIN(value, min); 89 90 max = PS_MAX(value, max); … … 93 94 } 94 95 } else { 96 // 2011/03/16 - MWV: Hmmm... this overwites the previously defined Npixels that only counted finite-valued pixels. 97 Npixels = nx * ny; 98 95 99 // Subsample all pixels 96 100 // This is not optimal, since there may be a large masked fraction that leaves us with few good pixels. 97 101 // 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]; 102 119 int ix = pixel % nx; 103 120 int iy = pixel / nx; … … 108 125 109 126 float value = image->data.F32[iy][ix]; 127 // 2011/03/16 - MWV: Keep a running overall min and max 110 128 min = PS_MIN(value, min); 111 129 max = PS_MAX(value, max);
Note:
See TracChangeset
for help on using the changeset viewer.
