Changeset 25964 for branches/pap/psModules/src/imcombine/pmStack.c
- Timestamp:
- Oct 28, 2009, 5:35:05 PM (17 years ago)
- File:
-
- 1 edited
-
branches/pap/psModules/src/imcombine/pmStack.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/psModules/src/imcombine/pmStack.c
r25960 r25964 290 290 291 291 // Mark a pixel for inspection 292 // Value in pixel doesn't seem to agree with the stack, so need to look closer 292 293 static inline void combineInspect(const psArray *inputs, // Stack data 293 294 int x, int y, // Pixel … … 301 302 } 302 303 data->inspect = psPixelsAdd(data->inspect, data->inspect->nalloc, x, y); 304 return; 305 } 306 307 // Mark a pixel for rejection 308 // Cannot possibly inspect this pixel and confirm that it's good. 309 // e.g., Only a single input 310 static inline void combineReject(const psArray *inputs, // Stack data 311 int x, int y, // Pixel 312 int source // Source image index 313 ) 314 { 315 pmStackData *data = inputs->data[source]; // Stack data of interest 316 if (!data) { 317 psWarning("Can't find input data for source %d", source); 318 return; 319 } 320 data->reject = psPixelsAdd(data->reject, data->reject->nalloc, x, y); 303 321 return; 304 322 } … … 319 337 float rej, // Number of standard deviations at which to reject 320 338 float sys, // Relative systematic error 321 float discard,// Fraction of values to discard (Olympic weighted mean)339 float olympic,// Fraction of values to discard (Olympic weighted mean) 322 340 bool useVariance, // Use variance for rejection when combining? 323 341 bool safe, // Combine safely? 324 bool reject Inspect, // Reject values marked for inspection from combination?342 bool rejection, // Reject values marked for inspection from combination? 325 343 combineBuffer *buffer // Buffer for combination; to avoid multiple allocations 326 344 ) … … 419 437 } 420 438 maskValue = 0; 421 } 422 #ifdef TESTING 423 else { 439 } else { 440 if (!rejection) { 441 combineReject(inputs, x, y, pixelSources->data.U16[0]); 442 } 443 #ifdef TESTING 424 444 numRejected = 1; 425 445 if (x == TEST_X && y == TEST_Y) { 426 446 fprintf(stderr, "Single input to combine, safety on, pixel is bad.\n"); 427 447 } 448 #endif 428 449 } 429 #endif430 450 break; 431 451 } … … 459 479 if (PS_SQR(diff) > PS_SQR(rej) * sigma2) { 460 480 // Not consistent: mark both for inspection 461 if (reject Inspect) {481 if (rejection) { 462 482 imageValue = NAN; 463 483 varianceValue = NAN; … … 550 570 } 551 571 #endif 552 median = combinationWeightedOlympic(pixelData, pixelWeights, pixelMasks, discard, sort);572 median = combinationWeightedOlympic(pixelData, pixelWeights, pixelMasks, olympic, sort); 553 573 } 554 574 … … 563 583 #define MASK_PIXEL_FOR_INSPECTION() \ 564 584 pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff; \ 565 if (!reject Inspect) { \585 if (!rejection) { \ 566 586 combineInspect(inputs, x, y, pixelSources->data.U16[j]); \ 567 587 } \ … … 605 625 } 606 626 607 if (reject Inspect&& totalClipped > 0) {627 if (rejection && totalClipped > 0) { 608 628 // Get rid of the masked values 609 629 // The alternative to this is to make combinationMeanVariance() accept a mask … … 658 678 // Ensure the input array of pmStackData is valid, and get some details out of it 659 679 static bool validateInputData(bool *haveVariances, // Do we have variance maps in the sky images? 660 bool *haveRejects, // Do we have lists of rejected pixels?661 680 int *num, // Number of inputs 662 681 int *numCols, int *numRows, // Size of (sky) images 663 psArray *input // Input array of pmStackData to validate 682 const psArray *input, // Input array of pmStackData to validate 683 const pmReadout *output // Output readout 664 684 ) 665 685 { … … 687 707 PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false); 688 708 } 689 *haveRejects = (data->reject != NULL);709 bool haveRejects = (data->reject != NULL); // Do we have rejected pixels? 690 710 691 711 // Make sure the rest correspond with the first … … 700 720 return false; 701 721 } 702 if (( *haveRejects && !data->reject) || (data->reject && !*haveRejects)) {722 if ((haveRejects && !data->reject) || (data->reject && !haveRejects)) { 703 723 psError(PS_ERR_UNEXPECTED_NULL, true, 704 724 "The rejected pixels are specified in some but not all inputs."); … … 716 736 PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false); 717 737 } 738 } 739 740 PM_ASSERT_READOUT_NON_NULL(output, false); 741 if (output->image) { 742 PS_ASSERT_IMAGE_NON_NULL(output->image, false); 743 PS_ASSERT_IMAGE_TYPE(output->image, PS_TYPE_F32, false); 744 PS_ASSERT_IMAGE_NON_NULL(output->mask, false); 745 PS_ASSERT_IMAGE_TYPE(output->mask, PS_TYPE_IMAGE_MASK, false); 746 PS_ASSERT_IMAGES_SIZE_EQUAL(output->image, output->mask, false); 718 747 } 719 748 … … 802 831 /// Stack input images 803 832 bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType bad, 804 int kernelSize, int numIter, float rej, float sys, float discard, 805 bool entire, bool useVariance, bool safe, bool rejectInspect) 806 { 807 PS_ASSERT_PTR_NON_NULL(combined, false); 833 int kernelSize, int numIter, float rej, float sys, float olympic, 834 bool useVariance, bool safe, bool rejection) 835 { 808 836 bool haveVariances; // Do we have the variance maps? 809 bool haveRejects; // Do we have lists of rejected pixels?810 837 int num; // Number of inputs 811 838 int numCols, numRows; // Size of (sky) images 812 if (!validateInputData(&haveVariances, & haveRejects, &num, &numCols, &numRows, input)) {839 if (!validateInputData(&haveVariances, &num, &numCols, &numRows, input, combined)) { 813 840 return false; 814 841 } … … 821 848 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false); 822 849 } 823 if (haveRejects) {824 // This is a subsequent combination, so expect that the image and mask already exist825 PS_ASSERT_IMAGE_NON_NULL(combined->image, false);826 PS_ASSERT_IMAGE_TYPE(combined->image, PS_TYPE_F32, false);827 PS_ASSERT_IMAGE_NON_NULL(combined->mask, false);828 PS_ASSERT_IMAGE_TYPE(combined->mask, PS_TYPE_IMAGE_MASK, false);829 PS_ASSERT_IMAGES_SIZE_EQUAL(combined->image, combined->mask, false);830 }831 850 if (useVariance && !haveVariances) { 832 851 psWarning("Unable to use variance in rejection if no variance maps supplied --- option turned off"); … … 852 871 } 853 872 #endif 854 if (!haveRejects && !data->inspect) { 855 data->inspect = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); 873 if (!rejection) { 874 // Ensure pixels can be put on the appropriate list 875 if (!data->inspect) { 876 data->inspect = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); 877 } 878 if (!data->reject) { 879 data->reject = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); 880 } 856 881 } 857 882 } … … 882 907 combineBuffer *buffer = combineBufferAlloc(num); 883 908 884 if (haveRejects) { 885 psImage *combinedImage = combined->image; // Combined image 886 psImage *combinedMask = combined->mask; // Combined mask 887 psImage *combinedVariance = combined->variance; // Combined variance map 888 889 psArray *pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols, 890 minInputRows, maxInputRows); // Map of pixels to source 891 psPixels *pixels = NULL; // Total list of pixels, with no duplicates 909 // Pull the products out, allocate if necessary 910 psImage *combinedImage = combined->image; // Combined image 911 if (!combinedImage) { 912 combined->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 913 combinedImage = combined->image; 914 } 915 psImage *combinedMask = combined->mask; // Combined mask 916 if (!combinedMask) { 917 combined->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 918 combinedMask = combined->mask; 919 } 920 921 psImage *combinedVariance = combined->variance; // Combined variance map 922 if (haveVariances && !combinedVariance) { 923 combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 924 combinedVariance = combined->variance; 925 } 926 927 // Set up rejection list 928 psArray *pixelMap = NULL; // Map of pixels to source 929 if (rejection) { 930 pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols, minInputRows, maxInputRows); 931 } 932 933 // Combine each pixel 934 for (int y = minInputRows; y < maxInputRows; y++) { 935 for (int x = minInputCols; x < maxInputCols; x++) { 936 psVector *reject = NULL; // Images to reject for this pixel 937 if (rejection) { 938 reject = pixelMapQuery(pixelMap, minInputCols, minInputRows, x, y); 939 } 940 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 941 addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, olympic, 942 useVariance, safe, rejection, buffer); 943 } 944 } 945 946 psFree(pixelMap); 947 psFree(weights); 948 psFree(buffer); 949 950 #ifndef PS_NO_TRACE 951 if (!rejection && psTraceGetLevel("psModules.imcombine") >= 5) { 892 952 for (int i = 0; i < num; i++) { 893 pmStackData *data = input->data[i]; // Stack ing data; contains the list of pixels894 if (!data ) {953 pmStackData *data = input->data[i]; // Stack data for this input 954 if (!data || !data->inspect) { 895 955 continue; 896 956 } 897 pixels = psPixelsConcatenate(pixels, data->reject); 898 } 899 pixels = psPixelsDuplicates(pixels, pixels); 900 901 if (entire) { 902 // Combine entire image 903 for (int y = minInputRows; y < maxInputRows; y++) { 904 for (int x = minInputCols; x < maxInputCols; x++) { 905 psVector *reject = pixelMapQuery(pixelMap, minInputCols, minInputRows, 906 x, y); // Reject these images 907 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 908 addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard, 909 useVariance, safe, rejectInspect, buffer); 910 } 911 } 912 } else { 913 // Only combine previously rejected pixels 914 for (int i = 0; i < pixels->n; i++) { 915 // Pixel coordinates are in the frame of the original image 916 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest 917 if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) { 918 continue; 919 } 920 psVector *reject = pixelMapQuery(pixelMap, minInputCols, minInputRows, 921 x, y); // Reject these images 922 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 923 addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard, 924 useVariance, safe, rejectInspect, buffer); 925 } 926 } 927 psFree(pixels); 928 psFree(pixelMap); 929 } else { 930 // Pull the products out, allocate if necessary 931 psImage *combinedImage = combined->image; // Combined image 932 if (!combinedImage) { 933 combined->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 934 combinedImage = combined->image; 935 } 936 psImage *combinedMask = combined->mask; // Combined mask 937 if (!combinedMask) { 938 combined->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 939 combinedMask = combined->mask; 940 } 941 942 psImage *combinedVariance = combined->variance; // Combined variance map 943 if (haveVariances && !combinedVariance) { 944 combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 945 combinedVariance = combined->variance; 946 } 947 948 for (int y = minInputRows; y < maxInputRows; y++) { 949 for (int x = minInputCols; x < maxInputCols; x++) { 950 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 951 addVariance, NULL, x, y, maskVal, bad, numIter, rej, sys, discard, 952 useVariance, safe, rejectInspect, buffer); 953 } 954 } 955 956 #ifndef PS_NO_TRACE 957 if (psTraceGetLevel("psModules.imcombine") >= 5) { 958 for (int i = 0; i < num; i++) { 959 pmStackData *data = input->data[i]; // Stack data for this input 960 if (!data || !data->inspect) { 961 continue; 962 } 963 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->inspect->n); 964 } 965 } 966 #endif 967 } 968 969 psFree(weights); 970 psFree(buffer); 957 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->inspect->n); 958 } 959 } 960 #endif 971 961 972 962 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
