Changeset 30956
- Timestamp:
- Mar 17, 2011, 4:34:04 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/psLib/src/imageops/psImageBackground.c
r27069 r30956 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 // 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]; 102 124 int ix = pixel % nx; 103 125 int iy = pixel / nx; … … 108 130 109 131 float value = image->data.F32[iy][ix]; 132 // 2011/03/16 - MWV: Keep a running overall min and max 110 133 min = PS_MIN(value, min); 111 134 max = PS_MAX(value, max);
Note:
See TracChangeset
for help on using the changeset viewer.
