Changeset 7256 for trunk/psModules/src/imcombine/pmReadoutCombine.c
- Timestamp:
- May 31, 2006, 4:26:32 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmReadoutCombine.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmReadoutCombine.c
r7254 r7256 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-0 5-31 22:51:15$7 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-06-01 02:26:32 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 25 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 26 26 27 #if 128 27 // Return the statistic of interest 29 static double getStat(const psStats *stats, // Statistics structure30 psStatsOptions option // Statistics option31 )28 static inline double getStat(const psStats *stats, // Statistics structure 29 psStatsOptions option // Statistics option 30 ) 32 31 { 33 32 switch (option) { … … 59 58 return NAN; 60 59 } 61 #endif62 63 // Mask for combination --- used only locally64 typedef enum {65 PM_READOUT_COMBINE_CLEAR = 0x00, // No problem66 PM_READOUT_COMBINE_NO_IMAGE = 0x01, // No image available67 PM_READOUT_COMBINE_MASKED = 0x02, // Pixel is masked68 PM_READOUT_COMBINE_BAD = 0x03, // Pixel is bad (NO_IMAGE | MASKED)69 PM_READOUT_COMBINE_CLIPPED = 0x04 // Pixel has been clipped70 } pmReadoutCombineMask;71 72 60 73 61 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 96 84 *****************************************************************************/ 97 85 bool pmReadoutCombine(pmReadout *output, 98 constpsArray *inputs,86 psArray *inputs, 99 87 const psVector *zero, 100 88 const psVector *scale, … … 144 132 psVector *mask = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack 145 133 mask->n = inputs->n; 146 psVectorInit(mask, 0); 134 147 135 bool haveWeights = false; // Do we have weight images? 148 136 bool valid = false; // Do we have a single valid input? … … 150 138 pmReadout *readout = inputs->data[i]; // Readout of interest 151 139 if (!readout || !readout->image) { 152 mask->data.U8[i] = PM_READOUT_COMBINE_NO_IMAGE;153 continue;140 psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %d is NULL or has NULL image.\n", i); 141 return false; 154 142 } 155 143 … … 179 167 psError(PS_ERR_IO, true, "No valid inputs.\n"); 180 168 return NULL; 169 } 170 171 // Apply scale and zero 172 if (scale || zero) { 173 for (int i = 0; i < inputs->n; i++) { 174 pmReadout *readout = inputs->data[i]; // The particular readout 175 if (zero) { 176 psBinaryOp(readout->image, readout->image, "-", 177 psScalarAlloc(zero->data.F32[i], PS_TYPE_F32)); 178 } 179 if (scale) { 180 float scaleFactor = 1.0 / scale->data.F32[i]; // Scaling 181 psBinaryOp(readout->image, readout->image, "*", psScalarAlloc(scaleFactor, PS_TYPE_F32)); 182 if (haveWeights) { 183 psBinaryOp(readout->weight, readout->weight, "*", 184 psScalarAlloc(scaleFactor * scaleFactor, PS_TYPE_F32)); 185 } 186 } 187 } 181 188 } 182 189 … … 277 284 } 278 285 for (int j = minInputCols; j < maxInputCols; j++) { 279 280 286 int numValid = 0; // Number of valid pixels in the stack 287 memset(mask->data.U8, 0, mask->n * sizeof(psU8)); // Reset the mask 281 288 for (int r = 0; r < inputs->n; r++) { 282 289 pmReadout *readout = inputs->data[r]; // Input readout … … 284 291 int xIn = j - readout->col0; // x position on input readout 285 292 286 // Check existence and bounds287 if (mask->data.U8[r] & PM_READOUT_COMBINE_NO_IMAGE || 288 xIn < 0 || xIn >= readout->image->numCols ||289 yIn < 0 || yIn >= readout->image->numRows) {293 psImage *image = readout->image; // The readout image 294 295 // Check bounds 296 if (xIn < 0 || xIn >= image->numCols || yIn < 0 || yIn >= image->numRows) { 290 297 continue; 291 298 } 299 300 pixels->data.F32[r] = image->data.F32[yIn][xIn]; 292 301 293 302 // Check mask 294 303 if (readout->mask && readout->mask->data.U8[yIn][xIn] & maskVal) { 295 mask->data.U8[r] &= PM_READOUT_COMBINE_MASKED;304 mask->data.U8[r] = 1; 296 305 continue; 297 306 } 298 307 299 pixels->data.F32[r] = readout->image->data.F32[yIn][xIn];300 301 // Apply zero and scale302 if (zero) {303 pixels->data.F32[r] -= zero->data.F32[r];304 }305 if (scale) {306 pixels->data.F32[r] /= scale->data.F32[r];307 }308 309 if (haveWeights) {310 weights->data.F32[r] = readout->weight->data.F32[yIn][xIn];311 if (scale) {312 weights->data.F32[r] /= scale->data.F32[r] * scale->data.F32[r];313 }314 }315 308 numValid++; 316 309 } … … 331 324 int numHigh = numValid * params->fracHigh; // Number of high pixels to clip 332 325 // Low pixels 333 for (int k = 0, numMasked = 0; numMasked < numLow ; k++) {326 for (int k = 0, numMasked = 0; numMasked < numLow && k < index->n; k++) { 334 327 // Don't count the ones that are already masked 335 if (! mask->data.U8[index->data.S32[k]] & PM_READOUT_COMBINE_BAD) {336 mask->data.U8[index->data.S32[k]] |= PM_READOUT_COMBINE_CLIPPED;328 if (!mask->data.U8[index->data.S32[k]]) { 329 mask->data.U8[index->data.S32[k]] = 1; 337 330 numMasked++; 338 331 } 339 332 } 340 333 // High pixels 341 for (int k = pixels->n , numMasked = 0; numMasked < numHigh; k++) {334 for (int k = pixels->n - 1, numMasked = 0; numMasked < numHigh && k < index->n; k++) { 342 335 // Don't count the ones that are already masked 343 if (! mask->data.U8[index->data.S32[k]] & PM_READOUT_COMBINE_BAD) {344 mask->data.U8[index->data.S32[k]] |= PM_READOUT_COMBINE_CLIPPED;336 if (! mask->data.U8[index->data.S32[k]]) { 337 mask->data.U8[index->data.S32[k]] = 1; 345 338 numMasked++; 346 339 } … … 349 342 350 343 // Combination 351 psVectorStats(stats, pixels, weights, mask, PM_READOUT_COMBINE_BAD | PM_READOUT_COMBINE_CLIPPED);344 psVectorStats(stats, pixels, weights, mask, 1); 352 345 output->image->data.F32[yOut][xOut] = getStat(stats, params->combine); 353 346 if (haveWeights) { 354 output->weight->data.F32[yOut][xOut] = PS_SQR(getStat(stats, combineStdev)); // Variance 355 } 356 357 // Clear the clipping 358 psBinaryOp(mask, mask, "&", psScalarAlloc(~PM_READOUT_COMBINE_CLIPPED, PS_TYPE_U8)); 359 347 float stdev = getStat(stats, combineStdev); 348 output->weight->data.F32[yOut][xOut] = PS_SQR(stdev); // Variance 349 } 360 350 } 361 351 }
Note:
See TracChangeset
for help on using the changeset viewer.
