Changeset 16607 for trunk/psModules/src/imcombine/pmStackReject.c
- Timestamp:
- Feb 22, 2008, 9:50:56 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStackReject.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStackReject.c
r16604 r16607 11 11 #define PIXEL_LIST_BUFFER 100 // Number of pixels to add to list at a time 12 12 13 psPixels *pmStackReject(const psPixels *in, float threshold, const psArray *regions,14 const psArray *s olutions, const pmSubtractionKernels*kernels)13 psPixels *pmStackReject(const psPixels *in, const psRegion *valid, float threshold, 14 const psArray *subRegions, const psArray *kernels) 15 15 { 16 16 PS_ASSERT_PIXELS_NON_NULL(in, NULL); 17 17 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(threshold, 0.0, NULL); 18 18 PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(threshold, 1.0, NULL); 19 PS_ASSERT_ARRAY_NON_NULL(regions, NULL); 20 PS_ASSERT_ARRAY_NON_NULL(solutions, NULL); 21 PS_ASSERT_ARRAYS_SIZE_EQUAL(regions, solutions, NULL); 22 PS_ASSERT_PTR_NON_NULL(kernels, NULL); 19 PS_ASSERT_ARRAY_NON_NULL(subRegions, NULL); 20 PS_ASSERT_ARRAY_NON_NULL(kernels, NULL); 21 PS_ASSERT_ARRAYS_SIZE_EQUAL(subRegions, kernels, NULL); 23 22 24 23 // Get the original image size 25 int numRegions = regions->n; // Number of regions24 int numRegions = subRegions->n; // Number of regions 26 25 int numCols = 0, numRows = 0; // Size of original image 27 26 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image 28 27 int size = 0; // Size of kernel 29 28 for (int i = 0; i < numRegions; i++) { 30 psRegion * region = regions->data[i]; // Region of interest31 if ( region->x0 < minCols) {32 minCols = region->x0;29 psRegion *subRegion = subRegions->data[i]; // Region of interest 30 if (subRegion->x0 < minCols) { 31 minCols = subRegion->x0; 33 32 } 34 if ( region->y0 < minRows) {35 minRows = region->y0;33 if (subRegion->y0 < minRows) { 34 minRows = subRegion->y0; 36 35 } 37 if ( region->x1 > numCols) {38 numCols = region->x1;36 if (subRegion->x1 > numCols) { 37 numCols = subRegion->x1; 39 38 } 40 if (region->y1 > numRows) { 41 numRows = region->y1; 39 if (subRegion->y1 > numRows) { 40 numRows = subRegion->y1; 41 } 42 43 pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest 44 if (size == 0) { 45 size = kernel->size; 46 } else if (kernel->size != size) { 47 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Kernel sizes are not identical: %d vs %d", 48 size, kernel->size); 49 return NULL; 42 50 } 43 51 } 44 if (minCols != 0 || minRows != 0) { 45 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 46 "Some error with image regions --- minimum coordinate is not 0,0"); 47 return NULL; 52 53 // Adjust the size for the size of the subimage 54 if (valid) { 55 minCols = PS_MAX(valid->x0, minCols); 56 minRows = PS_MAX(valid->y0, minRows); 57 numCols = PS_MIN(valid->x1, numCols); 58 numRows = PS_MIN(valid->y1, numRows); 48 59 } 49 60 psTrace("psModules.imcombine", 1, "Rejecting [%d:%d,%d:%d]\n", minCols, numCols, minRows, numRows); 50 61 51 psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image 62 psImage *mask = psPixelsToMask(NULL, in, psRegionSet(minCols, numCols - 1, minRows, numRows - 1), 63 0x01); // Mask 52 64 psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve 53 65 psFree(mask); … … 57 69 pmReadout *inRO = pmReadoutAlloc(NULL); // Readout with input image 58 70 inRO->image = image; 71 inRO->col0 = minCols; 72 inRO->row0 = minRows; 59 73 for (int i = 0; i < numRegions; i++) { 60 74 psRegion *region = subRegions->data[i]; // Region of interest … … 76 90 77 91 // Image of the kernel at the centre of the region 78 float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - numCols/2.0) / (float)numCols; 79 float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - numRows/2.0) / (float)numRows; 80 psImage *kernel = pmSubtractionKernelImage(kernels, xNorm, yNorm, false); 81 if (!kernel) { 92 float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - kernel->numCols/2.0) / 93 (float)kernel->numCols; 94 float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - kernel->numRows/2.0) / 95 (float)kernel->numRows; 96 psImage *image = pmSubtractionKernelImage(kernel, xNorm, yNorm, false); 97 if (!image) { 82 98 psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image."); 83 99 psFree(convRO); … … 86 102 } 87 103 float sum = 0.0; 88 for (int y = 0; y < kernel->numRows; y++) {89 for (int x = 0; x < kernel->numCols; x++) {90 sum += kernel->data.F32[y][x];104 for (int y = 0; y < image->numRows; y++) { 105 for (int x = 0; x < image->numCols; x++) { 106 sum += image->data.F32[y][x]; 91 107 } 92 108 } 93 psFree( kernel);109 psFree(image); 94 110 95 psImage *subConv = psImageSubset(convRO->image, *region); // Sub-image of convolved image 96 psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32)); 111 // Range for normalisation 112 int yMin = PS_MAX(minRows, region->y0) - inRO->row0; 113 int yMax = PS_MIN(numRows - 1, region->y1) - inRO->row0; 114 int xMin = PS_MAX(minCols, region->x0) - inRO->col0; 115 int xMax = PS_MIN(numCols - 1, region->x1) - inRO->col0; 116 psTrace("psModules.imcombine", 2, "Normalising convolved mask image by %f over %d:%d,%d:%d\n", 117 sum, xMin, xMax, yMin, yMax); 118 for (int y = yMin; y <= yMax; y++) { 119 for (int x = xMin; x <= xMax; x++) { 120 convRO->image->data.F32[y][x] /= sum; 121 } 122 } 97 123 } 98 124 psFree(inRO); … … 124 150 for (int y = yMin; y <= yMax; y++) { 125 151 for (int x = xMin; x <= xMax; x++) { 152 assert(x < mask->numCols && y < mask->numRows); 126 153 mask->data.PS_TYPE_MASK_DATA[y][x] = 0xff; 127 154 }
Note:
See TracChangeset
for help on using the changeset viewer.
