Changeset 14602 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Aug 21, 2007, 4:56:53 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r14581 r14602 4 4 * @author GLG, MHPCC 5 5 * 6 * @version $Revision: 1.4 3$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-08-2 1 18:16:54$6 * @version $Revision: 1.44 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-08-22 02:56:53 $ 8 8 * 9 9 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 24 24 25 25 #include "pmSubtraction.h" 26 27 #define PIXEL_LIST_BUFFER 100 // Number of entries to add to pixel list at a time 28 26 29 27 30 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 880 883 } 881 884 882 float background = solution->data.F64[solution->n-1]; // The difference in background 885 int numBackground = polyTerms(kernels->bgOrder); // Number of background terms 886 float background = solution->data.F64[solution->n - numBackground]; // The difference in background 883 887 int numCols = inImage->numCols, numRows = inImage->numRows; // Image dimensions 884 888 … … 1017 1021 return true; 1018 1022 } 1023 1024 1025 psPixels *pmSubtractionDeconvolveMask(const psPixels *in, float threshold, const psArray *regions, 1026 const psArray *solutions, const pmSubtractionKernels *kernels) 1027 { 1028 PS_ASSERT_PIXELS_NON_NULL(in, NULL); 1029 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(threshold, 0.0, NULL); 1030 PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(threshold, 1.0, NULL); 1031 PS_ASSERT_ARRAY_NON_NULL(regions, NULL); 1032 PS_ASSERT_ARRAY_NON_NULL(solutions, NULL); 1033 PS_ASSERT_ARRAYS_SIZE_EQUAL(regions, solutions, NULL); 1034 PS_ASSERT_PTR_NON_NULL(kernels, NULL); 1035 1036 // Get the original image size 1037 int numRegions = regions->n; // Number of regions 1038 int numCols = 0, numRows = 0; // Size of original image 1039 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0 1040 for (int i = 0; i < numRegions; i++) { 1041 psRegion *region = regions->data[i]; // Region of interest 1042 if (region->x0 < minCols) { 1043 minCols = region->x0; 1044 } 1045 if (region->y0 < minRows) { 1046 minRows = region->y0; 1047 } 1048 if (region->x1 > numCols) { 1049 numCols = region->x1; 1050 } 1051 if (region->y1 > numRows) { 1052 numRows = region->y1; 1053 } 1054 } 1055 if (minCols != 0 || minRows != 0) { 1056 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1057 "Some error with image regions --- minimum coordinate is not 0,0"); 1058 return NULL; 1059 } 1060 1061 psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image 1062 psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve 1063 psFree(mask); 1064 1065 // Convolve the image with the kernel --- we're basically applying a matched filter and then thresholding 1066 psImage *convolved = NULL; // Convolved mask image 1067 psPixels *out = NULL; // List of pixels that should be masked 1068 for (int i = 0; i < numRegions; i++) { 1069 psRegion *region = regions->data[i]; // Region of interest 1070 psVector *solution = solutions->data[i]; // Solution of interest 1071 if (!pmSubtractionConvolve(&convolved, NULL, NULL, image, NULL, NULL, 0, region, solution, kernels)) { 1072 psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i); 1073 psFree(convolved); 1074 psFree(image); 1075 return NULL; 1076 } 1077 1078 // Need to adjust the thresholding level for the normalisation of the kernel --- the application of 1079 // the kernel may scale the unit level that we've inserted. 1080 1081 // Image of the kernel at the centre 1082 psImage *kernel = pmSubtractionKernelImage(solution, kernels, 1083 region->x0 + 0.5 * (region->x1 - region->x0), 1084 region->y0 + 0.5 * (region->y1 - region->y0)); 1085 float sum = 0.0; 1086 for (int y = 0; y < kernel->numRows; y++) { 1087 for (int x = 0; x < kernel->numCols; x++) { 1088 sum += kernel->data.F32[y][x]; 1089 } 1090 } 1091 psFree(kernel); 1092 1093 // Threshold the convolved image 1094 float adjustedThreshold = sum * threshold; // Threshold adjusted for the kernel normalisation 1095 for (int y = region->y0; y < region->y1; y++) { 1096 for (int x = region->x0; x < region->x1; x++) { 1097 if (image->data.F32[y][x] > adjustedThreshold) { 1098 out = psPixelsAdd(out, PIXEL_LIST_BUFFER, x, y); 1099 } 1100 } 1101 } 1102 } 1103 psFree(image); 1104 1105 return out; 1106 }
Note:
See TracChangeset
for help on using the changeset viewer.
