- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/imageops/psImageBackground.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/psLib/src/imageops/psImageBackground.c
r24481 r27840 15 15 #include "psRandom.h" 16 16 #include "psError.h" 17 18 static int nFailures = 0; 19 20 void psImageBackgroundInit() { 21 nFailures = 0; 22 return; 23 } 17 24 18 25 // XXX allow the user to choose the stats method? … … 39 46 long ny = image->numRows; 40 47 41 const int Npixels = nx*ny; // Total number of pixels 48 psImage *bad = psImageAlloc(nx, ny, PS_TYPE_U8); // Image with bad pixels 49 psImageInit(bad, 0); 50 51 int Npixels = 0; // Total number of pixels 52 for (int y = 0; y < ny; y++) { 53 for (int x = 0; x < nx; x++) { 54 if (!isfinite(image->data.F32[y][x]) || 55 (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue)) { 56 bad->data.U8[y][x] = 0xFF; 57 } 58 Npixels++; 59 } 60 } 61 42 62 const int Nsubset = (stats->nSubsample == 0) ? Npixels : PS_MIN(stats->nSubsample, Npixels); // Number of pixels in subset 43 63 … … 58 78 long n = 0; // Number of actual pixels in subset 59 79 if (Nsubset >= Npixels) { 60 // if we have an image smaller than Nsubset, just loop over theimage pixels61 for (int iy = 0; iy < ny; iy++) {62 for (int ix = 0; ix < nx; ix++) {63 if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {64 continue;65 }80 // if we have an image smaller than Nsubset, just loop over the (good) image pixels 81 for (int iy = 0; iy < ny; iy++) { 82 for (int ix = 0; ix < nx; ix++) { 83 if (bad->data.U8[iy][ix]) { 84 continue; 85 } 66 86 67 float value = image->data.F32[iy][ix];68 min = PS_MIN(value, min);69 max = PS_MAX(value, max);70 values->data.F32[n] = value;71 n++;72 }73 }87 float value = image->data.F32[iy][ix]; 88 min = PS_MIN(value, min); 89 max = PS_MAX(value, max); 90 values->data.F32[n] = value; 91 n++; 92 } 93 } 74 94 } else { 75 for (long i = 0; i < Nsubset; i++) { 76 double frnd = psRandomUniform(rng); 77 int pixel = Npixels * frnd; 78 int ix = pixel % nx; 79 int iy = pixel / nx; 95 // Subsample all pixels 96 // This is not optimal, since there may be a large masked fraction that leaves us with few good pixels. 97 // 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 int ix = pixel % nx; 103 int iy = pixel / nx; 80 104 81 if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {82 continue;83 }105 if (bad->data.U8[iy][ix]) { 106 continue; 107 } 84 108 85 float value = image->data.F32[iy][ix];86 min = PS_MIN(value, min);87 max = PS_MAX(value, max);88 values->data.F32[n] = value;89 n++;90 }109 float value = image->data.F32[iy][ix]; 110 min = PS_MIN(value, min); 111 max = PS_MAX(value, max); 112 values->data.F32[n] = value; 113 n++; 114 } 91 115 } 116 117 psFree(bad); 118 92 119 if (n < 0.01*Nsubset) { 93 psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, 94 "Unable to measure image background: too few data points (%ld)", n); 120 if ((nFailures < 3) || (nFailures % 100 == 0)) { 121 psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, "Unable to measure image background: too few data points (%ld) (%d failures)", n, nFailures); 122 } 123 nFailures ++; 95 124 psFree(values); 96 125 return false; … … 108 137 109 138 if (!psVectorSort(values, values)) { 110 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.\n"); 139 if ((nFailures < 3) || (nFailures % 100 == 0)) { 140 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.(%d failures)\n", nFailures); 141 } 142 nFailures ++; 111 143 psFree(values); 112 144 return false; … … 132 164 fclose (f); 133 165 } 134 psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background " 135 "(%dx%d, (row0,col0) = (%d,%d)", 136 image->numRows, image->numCols, image->row0, image->col0); 166 if ((nFailures < 3) || (nFailures % 100 == 0)) { 167 psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background " 168 "(%dx%d, (row0,col0) = (%d,%d) (%d failures)\n", 169 image->numRows, image->numCols, image->row0, image->col0, nFailures); 170 } 171 nFailures ++; 137 172 psFree(values); 138 173 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
