Changeset 27400 for trunk/psModules/src/imcombine/pmStack.c
- Timestamp:
- Mar 22, 2010, 8:34:28 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStack.c (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r27310 r27400 35 35 36 36 //#define TESTING // Enable test output 37 //#define TEST_X 2148-1 // x coordinate to examine38 //#define TEST_Y 248-1 // y coordinate to examine37 //#define TEST_X 843-1 // x coordinate to examine 38 //#define TEST_Y 813-1 // y coordinate to examine 39 39 //#define TEST_RADIUS 0 // Radius to examine 40 40 … … 46 46 psVector *variances; // Pixel variances 47 47 psVector *weights; // Pixel weightings 48 psVector *exps; // Pixel exposures 48 49 psVector *sources; // Pixel sources (which image did they come from?) 49 50 psVector *limits; // Rejection limits … … 57 58 psFree(buffer->variances); 58 59 psFree(buffer->weights); 60 psFree(buffer->exps); 59 61 psFree(buffer->sources); 60 62 psFree(buffer->limits); … … 73 75 buffer->variances = psVectorAlloc(numImages, PS_TYPE_F32); 74 76 buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32); 77 buffer->exps = psVectorAlloc(numImages, PS_TYPE_F32); 75 78 buffer->sources = psVectorAlloc(numImages, PS_TYPE_U16); 76 79 buffer->limits = psVectorAlloc(numImages, PS_TYPE_F32); … … 95 98 static bool combinationMeanVariance(float *mean, // Mean value, to return 96 99 float *var, // Variance value, to return 100 float *exp, // Exposure time, to return 101 float *expWeight, // Weighted exposure time, to return 97 102 const psVector *values, // Values to combine 98 103 const psVector *variances, // Pixel variances to combine 104 const psVector *exps, // Exposure times to combine 99 105 const psVector *weights // Weights to apply 100 106 ) … … 121 127 float sumVarianceWeight = 0.0; // Sum of the pixel variances multiplied by the global weights 122 128 float sumWeight = 0.0; // Sum of the image weights 129 float sumExp = 0.0; // Sum of the exposure time 130 float sumExpWeight = 0.0; // Sum of the exposure time multiplied by the global weights 123 131 for (int i = 0; i < values->n; i++) { 124 132 sumValueWeight += values->data.F32[i] * weights->data.F32[i]; … … 127 135 sumVarianceWeight += variances->data.F32[i] * PS_SQR(weights->data.F32[i]); 128 136 } 137 if (exps) { 138 sumExp += exps->data.F32[i]; 139 sumExpWeight += exps->data.F32[i] * weights->data.F32[i]; 140 } 129 141 } 130 142 … … 136 148 if (var) { 137 149 *var = sumVarianceWeight / PS_SQR(sumWeight); 150 } 151 if (exp) { 152 *exp = sumExp; 153 } 154 if (expWeight) { 155 *expWeight = sumExpWeight / sumWeight; 138 156 } 139 157 return true; … … 276 294 const psArray *inputs, // Stack data 277 295 const psVector *weights, // Global (single value) weights for data, or NULL 296 const psVector *exps, // Exposures for data, or NULL 278 297 const psVector *addVariance, // Additional variance for data 279 298 const psVector *reject, // Indices of pixels to reject, or NULL … … 292 311 psVector *pixelVariances = variance ? buffer->variances : NULL; // Variances for the pixel of interest 293 312 psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest 313 psVector *pixelExps = buffer->exps; // Exposure times 294 314 psVector *pixelSources = buffer->sources; // Sources for the pixel of interest 295 315 psVector *pixelLimits = buffer->limits; // Limits for the pixel of interest … … 331 351 } 332 352 pixelWeights->data.F32[numGood] = data->weight; 353 pixelExps->data.F32[numGood] = data->exp; 333 354 pixelSources->data.U16[numGood] = i; 334 355 numGood++; … … 347 368 if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) { 348 369 for (int i = 0; i < numGood; i++) { 349 fprintf(stderr, "Input %d, pixel %d,%d (%" PRIu16 "): %f %f (%f) %f % d\n",370 fprintf(stderr, "Input %d, pixel %d,%d (%" PRIu16 "): %f %f (%f) %f %f %d\n", 350 371 i, x, y, pixelSources->data.U16[i], pixelData->data.F32[i], pixelVariances->data.F32[i], 351 addVariance->data.F32[i], pixelWeights->data.F32[i], pixelSuspects->data.U8[i]); 372 addVariance->data.F32[i], pixelWeights->data.F32[i], pixelExps->data.F32[i], 373 pixelSuspects->data.U8[i]); 352 374 } 353 375 } … … 362 384 psImage *mask, // Combined mask, for output 363 385 psImage *variance, // Combined variance map, for output 386 psImage *exp, // Exposure map (time), for output 387 psImage *expnum, // Exposure map (number) for output 388 psImage *expweight, // Exposure map (weighted time) for output 364 389 int num, // Number of good pixels 365 390 combineBuffer *buffer, // Buffer with vectors … … 372 397 psVector *pixelVariances = variance ? buffer->variances : NULL; // Variances for the pixel of interest 373 398 psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest 399 psVector *pixelExps = buffer->exps; // Exposure times 374 400 375 401 // Default option is that the pixel is bad 376 402 float imageValue = NAN, varianceValue = NAN; // Value for combined image and variance map 377 403 psImageMaskType maskValue = bad; // Value for combined mask 404 float expValue = 0.0, expWeightValue = NAN; // Exposure value (straight, and weighted) 405 378 406 switch (num) { 379 407 case 0: { … … 393 421 varianceValue = pixelVariances->data.F32[0]; 394 422 } 423 if (exp) { 424 expValue = pixelExps->data.F32[0]; 425 } 395 426 maskValue = 0; 396 427 #ifdef TESTING … … 411 442 // Automatically accept the mean of the pixels only if we're not playing safe 412 443 if (!safe) { 413 float mean, var; // Mean and variance from combination 414 if (combinationMeanVariance(&mean, &var, pixelData, pixelVariances, pixelWeights)) { 415 imageValue = mean; 416 varianceValue = var; 444 if (combinationMeanVariance(&imageValue, &varianceValue, &expValue, &expWeightValue, 445 pixelData, pixelVariances, pixelExps, pixelWeights)) { 417 446 maskValue = 0; 418 447 #ifdef TESTING 419 448 if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) { 420 449 fprintf(stderr, "Two inputs to combine using unsafe, pixel %d,%d --> %f %f\n", 421 x, y, mean, var);450 x, y, imageValue, varianceValue); 422 451 } 423 452 #endif … … 435 464 default: { 436 465 // Can combine without too much worrying 437 float mean, var; // Mean and variance of the combination438 if (!combinationMeanVariance(&mean, &var, pixelData, pixelVariances, pixelWeights)) {466 if (!combinationMeanVariance(&imageValue, &varianceValue, &expValue, &expWeightValue, 467 pixelData, pixelVariances, pixelExps, pixelWeights)) { 439 468 break; 440 469 } 441 imageValue = mean;442 varianceValue = var;443 470 maskValue = 0; 444 471 #ifdef TESTING 445 472 if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) { 446 fprintf(stderr, "Combined inputs, pixel %d,%d --> %f %f\n", x, y, mean, var);473 fprintf(stderr, "Combined inputs, pixel %d,%d --> %f %f\n", x, y, imageValue, varianceValue); 447 474 } 448 475 #endif … … 456 483 variance->data.F32[y][x] = varianceValue; 457 484 } 458 459 #ifdef TESTING 460 mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = num; 461 #endif 462 485 if (exp) { 486 exp->data.F32[y][x] = expValue; 487 } 488 if (expnum) { 489 expnum->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = num; 490 } 491 if (expweight) { 492 expweight->data.F32[y][x] = expWeightValue; 493 } 463 494 464 495 return; … … 803 834 int *numCols, int *numRows, // Size of (sky) images 804 835 const psArray *input, // Input array of pmStackData to validate 805 const pmReadout *output // Output readout 836 const pmReadout *output, // Output readout 837 const pmReadout *exp // Exposure map 806 838 ) 807 839 { … … 869 901 } 870 902 903 if (exp) { 904 PM_ASSERT_READOUT_NON_NULL(exp, false); 905 if (exp->image) { 906 PS_ASSERT_IMAGES_SIZE_EQUAL(exp->image, output->image, false); 907 } 908 if (exp->mask) { 909 PS_ASSERT_IMAGES_SIZE_EQUAL(exp->mask, output->image, false); 910 } 911 } 912 871 913 return true; 872 914 } … … 937 979 938 980 /// Constructor 939 pmStackData *pmStackDataAlloc(pmReadout *readout, float weight, float addVariance)981 pmStackData *pmStackDataAlloc(pmReadout *readout, float weight, float exp, float addVariance) 940 982 { 941 983 pmStackData *data = psAlloc(sizeof(pmStackData)); // Stack data, to return … … 946 988 data->inspect = NULL; 947 989 data->weight = weight; 990 data->exp = exp; 948 991 data->addVariance = addVariance; 949 992 … … 952 995 953 996 /// Stack input images 954 bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType maskSuspect, 955 psImageMaskType bad, int kernelSize, float iter, float rej, float sys, float olympic, 997 bool pmStackCombine(pmReadout *combined, pmReadout *expmaps, psArray *input, 998 psImageMaskType maskVal, psImageMaskType maskSuspect, 999 psImageMaskType bad, int kernelSize, 1000 float iter, float rej, float sys, float olympic, 956 1001 bool useVariance, bool safe, bool rejection) 957 1002 { … … 959 1004 int num; // Number of inputs 960 1005 int numCols, numRows; // Size of (sky) images 961 if (!validateInputData(&haveVariances, &num, &numCols, &numRows, input, combined )) {1006 if (!validateInputData(&haveVariances, &num, &numCols, &numRows, input, combined, expmaps)) { 962 1007 return false; 963 1008 } … … 977 1022 psVector *addVariance = psVectorAlloc(num, PS_TYPE_F32); // Additional variance for each image 978 1023 psVector *weights = psVectorAlloc(num, PS_TYPE_F32); // Relative weighting for each image 1024 psVector *exps = psVectorAlloc(num, PS_TYPE_F32); // Exposure times for each image 979 1025 psArray *stack = psArrayAlloc(num); // Stack of readouts 980 1026 for (int i = 0; i < num; i++) { … … 982 1028 if (!data) { 983 1029 weights->data.F32[i] = 0.0; 1030 exps->data.F32[i] = NAN; 984 1031 continue; 985 1032 } 986 1033 weights->data.F32[i] = data->weight; 1034 exps->data.F32[i] = data->exp; 987 1035 pmReadout *ro = data->readout; // Readout of interest 988 1036 stack->data[i] = psMemIncrRefCounter(ro); … … 1045 1093 combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 1046 1094 combinedVariance = combined->variance; 1095 } 1096 1097 psImage *exp = NULL, *expnum = NULL; // Exposure map and exposure number 1098 if (expmaps) { 1099 if (!expmaps->image) { 1100 expmaps->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 1101 } 1102 exp = expmaps->image; 1103 1104 if (!expmaps->mask) { 1105 expmaps->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 1106 } 1107 expnum = expmaps->mask; 1047 1108 } 1048 1109 … … 1083 1144 bool suspect; // Suspect pixels in stack? 1084 1145 combineExtract(&num, &suspect, buffer, combinedImage, combinedMask, combinedVariance, 1085 input, weights, addVariance, reject, x, y, maskVal, maskSuspect); 1086 combinePixels(combinedImage, combinedMask, combinedVariance, num, buffer, x, y, bad, safe); 1146 input, weights, exps, addVariance, reject, x, y, maskVal, maskSuspect); 1147 combinePixels(combinedImage, combinedMask, combinedVariance, exp, expnum, NULL, 1148 num, buffer, x, y, bad, safe); 1087 1149 1088 1150 if (iter > 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
