Changeset 16604 for trunk/psModules/src/imcombine/pmStackReject.c
- Timestamp:
- Feb 22, 2008, 9:24:42 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStackReject.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStackReject.c
r16479 r16604 25 25 int numRegions = regions->n; // Number of regions 26 26 int numCols = 0, numRows = 0; // Size of original image 27 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0 27 int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image 28 int size = 0; // Size of kernel 28 29 for (int i = 0; i < numRegions; i++) { 29 30 psRegion *region = regions->data[i]; // Region of interest … … 46 47 return NULL; 47 48 } 49 psTrace("psModules.imcombine", 1, "Rejecting [%d:%d,%d:%d]\n", minCols, numCols, minRows, numRows); 48 50 49 51 psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image … … 56 58 inRO->image = image; 57 59 for (int i = 0; i < numRegions; i++) { 58 psRegion *region = regions->data[i]; // Region of interest 59 if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernels, true)) { 60 psRegion *region = subRegions->data[i]; // Region of interest 61 if (valid && (region->x0 > valid->x1 || region->x1 < valid->x0 || 62 region->y0 > valid->y1 || region->y1 < valid->y0)) { 63 // Region is outside of our sub-image 64 continue; 65 } 66 pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest 67 if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernel, false, true)) { 60 68 psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i); 61 69 psFree(convRO); … … 94 102 // Threshold the convolved image 95 103 psPixels *bad = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); // List of pixels that should be masked 96 for (int y = 0; y < numRows; y++) {97 for (int x = 0; x < numCols; x++) {104 for (int y = size; y < convolved->numRows - size; y++) { 105 for (int x = size; x < convolved->numCols - size; x++) { 98 106 if (convolved->data.F32[y][x] > threshold) { 99 bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x, y); 107 // Pixel coordinates in "bad" correspond to the full image 108 bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x + minCols, y + minRows); 100 109 } 101 110 } … … 103 112 psFree(convolved); 104 113 105 // Now, we want to convolve the original pixels properly106 mask = psPixelsToMask(NULL, bad, psRegionSet(0, numCols, 0, numRows), 0xff);107 int size = kernels->size; // Size of kernels114 // Now, grow the mask to include everything that touches a bad pixel in the convolution 115 int x0 = minCols, y0 = minRows; // Offset for mask image 116 mask = psPixelsToMask(NULL, bad, psRegionSet(x0, numCols - 1, y0, numRows - 1), 0xff); 108 117 for (int i = 0; i < bad->n; i++) { 109 int xPix = bad->data[i].x , yPix = bad->data[i].y; // Coordinates of interest118 int xPix = bad->data[i].x - x0, yPix = bad->data[i].y - y0; // Coordinates in frame of mask image 110 119 // Convolution limits 111 120 int xMin = PS_MAX(xPix - size, 0); 112 int xMax = PS_MIN(xPix + size, numCols - 1);121 int xMax = PS_MIN(xPix + size, mask->numCols - 1); 113 122 int yMin = PS_MAX(yPix - size, 0); 114 int yMax = PS_MIN(yPix + size, numRows - 1);123 int yMax = PS_MIN(yPix + size, mask->numRows - 1); 115 124 for (int y = yMin; y <= yMax; y++) { 116 125 for (int x = xMin; x <= xMax; x++) { … … 119 128 } 120 129 } 121 122 130 bad = psPixelsFromMask(bad, mask, 0xff); 123 131 psFree(mask); 124 132 133 // Convert coordinates to frame of original image 134 for (int i = 0; i < bad->n; i++) { 135 int x = bad->data[i].x + x0; 136 int y = bad->data[i].y + y0; 137 if (x < 0 || x >= numCols || y < 0 || y >= numRows) { 138 psWarning("Bad pixel coordinate %d: %d,%d --- ignored.", 139 i, x, y); 140 continue; 141 } 142 bad->data[i].x = x; 143 bad->data[i].y = y; 144 } 145 125 146 return bad; 126 147 }
Note:
See TracChangeset
for help on using the changeset viewer.
