Changeset 16423 for trunk/psModules/src/imcombine/pmStackReject.c
- Timestamp:
- Feb 13, 2008, 2:13:09 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStackReject.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStackReject.c
r16419 r16423 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, const psArray *kernels) 13 psPixels *pmStackReject(const psPixels *in, const psRegion *valid, float threshold, 14 const psArray *subRegions, const psArray *kernels) 14 15 { 15 16 PS_ASSERT_PIXELS_NON_NULL(in, NULL); 16 17 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(threshold, 0.0, NULL); 17 18 PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(threshold, 1.0, NULL); 18 PS_ASSERT_ARRAY_NON_NULL( regions, NULL);19 PS_ASSERT_ARRAY_NON_NULL(subRegions, NULL); 19 20 PS_ASSERT_ARRAY_NON_NULL(kernels, NULL); 20 PS_ASSERT_ARRAYS_SIZE_EQUAL( regions, kernels, NULL);21 PS_ASSERT_ARRAYS_SIZE_EQUAL(subRegions, kernels, NULL); 21 22 22 23 // Get the original image size 23 int numRegions = regions->n; // Number of regions24 int numRegions = subRegions->n; // Number of regions 24 25 int numCols = 0, numRows = 0; // Size of original image 25 26 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0 26 27 int size = 0; // Size of kernel 27 28 for (int i = 0; i < numRegions; i++) { 28 psRegion * region = regions->data[i]; // Region of interest29 if ( region->x0 < minCols) {30 minCols = region->x0;29 psRegion *subRegion = subRegions->data[i]; // Region of interest 30 if (subRegion->x0 < minCols) { 31 minCols = subRegion->x0; 31 32 } 32 if ( region->y0 < minRows) {33 minRows = region->y0;33 if (subRegion->y0 < minRows) { 34 minRows = subRegion->y0; 34 35 } 35 if ( region->x1 > numCols) {36 numCols = region->x1;36 if (subRegion->x1 > numCols) { 37 numCols = subRegion->x1; 37 38 } 38 if ( region->y1 > numRows) {39 numRows = region->y1;39 if (subRegion->y1 > numRows) { 40 numRows = subRegion->y1; 40 41 } 41 42 … … 49 50 } 50 51 } 51 if (minCols != 0 || minRows != 0) { 52 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 53 "Some error with image regions --- minimum coordinate is not 0,0"); 54 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); 55 59 } 56 60 57 psImage *mask = psPixelsToMask(NULL, in, psRegionSet( 0, numCols, 0, numRows), 0x01); // Mask image61 psImage *mask = psPixelsToMask(NULL, in, psRegionSet(minCols, numCols, minRows, numRows), 0x01); // Mask 58 62 psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve 59 63 psFree(mask); … … 63 67 pmReadout *inRO = pmReadoutAlloc(NULL); // Readout with input image 64 68 inRO->image = image; 69 inRO->col0 = minCols; 70 inRO->row0 = minRows; 65 71 for (int i = 0; i < numRegions; i++) { 66 psRegion *region = regions->data[i]; // Region of interest 72 psRegion *subRegion = subRegions->data[i]; // Region of interest 73 if (valid && (subRegion->x0 > valid->x1 || subRegion->x1 < valid->x0 || 74 subRegion->y0 > valid->y1 || subRegion->y1 < valid->y0)) { 75 // Region is outside of our sub-image 76 continue; 77 } 67 78 pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest 68 if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernel, true)) {79 if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, subRegion, kernel, true)) { 69 80 psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i); 70 81 psFree(convRO); … … 77 88 78 89 // Image of the kernel at the centre of the region 79 float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - numCols/2.0) / (float)numCols; 80 float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - numRows/2.0) / (float)numRows; 90 float xNorm = (subRegion->x0 + 0.5 * (subRegion->x1 - subRegion->x0) - kernel->numCols/2.0) / 91 (float)kernel->numCols; 92 float yNorm = (subRegion->y0 + 0.5 * (subRegion->y1 - subRegion->y0) - kernel->numRows/2.0) / 93 (float)kernel->numRows; 81 94 psImage *image = pmSubtractionKernelImage(kernel, xNorm, yNorm, false); 82 95 if (!image) { … … 94 107 psFree(image); 95 108 96 psImage *subConv = psImageSubset(convRO->image, * region); // Sub-image of convolved image109 psImage *subConv = psImageSubset(convRO->image, *subRegion); // Sub-image of convolved image 97 110 psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32)); 98 111 } … … 114 127 // Now, grow the mask to include everything that touches a bad pixel in the convolution 115 128 mask = psPixelsToMask(NULL, bad, psRegionSet(0, numCols - 1, 0, numRows - 1), 0xff); 129 assert(mask->numCols == numCols && mask->numRows == numRows); 116 130 for (int i = 0; i < bad->n; i++) { 117 131 int xPix = bad->data[i].x, yPix = bad->data[i].y; // Coordinates of interest … … 123 137 for (int y = yMin; y <= yMax; y++) { 124 138 for (int x = xMin; x <= xMax; x++) { 139 assert(x < mask->numCols && y < mask->numRows); 125 140 mask->data.PS_TYPE_MASK_DATA[y][x] = 0xff; 126 141 }
Note:
See TracChangeset
for help on using the changeset viewer.
