Changeset 27066 for trunk/psLib/src/imageops/psImageBackground.c
- Timestamp:
- Feb 24, 2010, 3:13:33 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageBackground.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageBackground.c
r26451 r27066 46 46 long ny = image->numRows; 47 47 48 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; // 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[iy][ix]) || 55 (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) { 56 bad->data.U8[y][x] = 0xFF; 57 } 58 Npixels++; 59 } 60 } 61 49 62 const int Nsubset = (stats->nSubsample == 0) ? Npixels : PS_MIN(stats->nSubsample, Npixels); // Number of pixels in subset 50 63 … … 65 78 long n = 0; // Number of actual pixels in subset 66 79 if (Nsubset >= Npixels) { 67 // if we have an image smaller than Nsubset, just loop over theimage pixels68 for (int iy = 0; iy < ny; iy++) {69 for (int ix = 0; ix < nx; ix++) {70 if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {71 continue;72 }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 } 73 86 74 float value = image->data.F32[iy][ix];75 min = PS_MIN(value, min);76 max = PS_MAX(value, max);77 values->data.F32[n] = value;78 n++;79 }80 }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 } 81 94 } else { 82 for (long i = 0; i < Nsubset; i++) { 83 double frnd = psRandomUniform(rng); 84 int pixel = Npixels * frnd; 85 int ix = pixel % nx; 86 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; 87 104 88 if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {89 continue;90 }105 if (bad->data.U8[iy][ix]) { 106 continue; 107 } 91 108 92 float value = image->data.F32[iy][ix];93 min = PS_MIN(value, min);94 max = PS_MAX(value, max);95 values->data.F32[n] = value;96 n++;97 }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 } 98 115 } 116 117 psFree(bad); 118 99 119 if (n < 0.01*Nsubset) { 100 if ((nFailures < 3) || (nFailures % 100 == 0)) {101 psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, "Unable to measure image background: too few data points (%ld) (%d failures)", n, nFailures);102 }103 nFailures ++;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 ++; 104 124 psFree(values); 105 125 return false; … … 117 137 118 138 if (!psVectorSort(values, values)) { 119 if ((nFailures < 3) || (nFailures % 100 == 0)) {120 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.(%d failures)\n", nFailures);121 }122 nFailures ++;139 if ((nFailures < 3) || (nFailures % 100 == 0)) { 140 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.(%d failures)\n", nFailures); 141 } 142 nFailures ++; 123 143 psFree(values); 124 144 return false; … … 144 164 fclose (f); 145 165 } 146 if ((nFailures < 3) || (nFailures % 100 == 0)) {147 psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background "148 "(%dx%d, (row0,col0) = (%d,%d) (%d failures)\n",149 image->numRows, image->numCols, image->row0, image->col0, nFailures);150 } 151 nFailures ++;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 ++; 152 172 psFree(values); 153 173 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
