Changeset 14632 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Aug 23, 2007, 10:38:47 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r14624 r14632 4 4 * @author GLG, MHPCC 5 5 * 6 * @version $Revision: 1.4 6$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-08-23 02:00:29$6 * @version $Revision: 1.47 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-08-23 20:38:47 $ 8 8 * 9 9 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 1023 1023 1024 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 size1037 int numRegions = regions->n; // Number of regions1038 int numCols = 0, numRows = 0; // Size of original image1039 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,01040 for (int i = 0; i < numRegions; i++) {1041 psRegion *region = regions->data[i]; // Region of interest1042 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 image1062 psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve1063 psFree(mask);1064 1065 // Convolve the image with the kernel --- we're basically applying a matched filter and then thresholding1066 psImage *convolved = NULL; // Convolved image1067 psPixels *out = NULL; // List of pixels that should be masked1068 for (int i = 0; i < numRegions; i++) {1069 psRegion *region = regions->data[i]; // Region of interest1070 psVector *solution = solutions->data[i]; // Solution of interest1071 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 of1079 // the kernel may scale the unit level that we've inserted.1080 1081 // Image of the kernel at the centre of the region1082 float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - numCols/2.0) / (float)numCols;1083 float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - numRows/2.0) / (float)numRows;1084 psImage *kernel = pmSubtractionKernelImage(solution, kernels, xNorm, yNorm);1085 if (!kernel) {1086 psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image.");1087 psFree(convolved);1088 psFree(image);1089 return NULL;1090 }1091 float sum = 0.0;1092 for (int y = 0; y < kernel->numRows; y++) {1093 for (int x = 0; x < kernel->numCols; x++) {1094 sum += kernel->data.F32[y][x];1095 }1096 }1097 psFree(kernel);1098 1099 psImage *subConv = psImageSubset(convolved, *region); // Sub-image of convolved image1100 psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32));1101 }1102 psFree(image);1103 1104 // Threshold the convolved image1105 for (int y = 0; y < numRows; y++) {1106 for (int x = 0; x < numCols; x++) {1107 if (convolved->data.F32[y][x] > threshold) {1108 out = psPixelsAdd(out, PIXEL_LIST_BUFFER, x, y);1109 }1110 }1111 }1112 psFree(convolved);1113 1114 return out;1115 }
Note:
See TracChangeset
for help on using the changeset viewer.
