Changeset 14196
- Timestamp:
- Jul 13, 2007, 10:47:50 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppSub/src/ppSubReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSub/src/ppSubReadout.c
r14193 r14196 6 6 #include <pslib.h> 7 7 #include <psmodules.h> 8 #include <psphot.h> 8 9 9 10 #include "ppSub.h" 10 11 #define MASK_BAD 0x01 // Mask value for bad pixel12 #define MASK_STAMP 0x02 // Mask value for bad stamp (and bad stamp region)13 11 14 12 bool ppSubReadout(pmConfig *config, const pmFPAview *view) … … 16 14 pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout 17 15 pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout 18 #if 019 16 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell 20 17 pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout 21 #endif22 18 23 19 psImage *input = inRO->image; // Input image … … 45 41 config); // Mask for blank reg. 46 42 47 i f (!inRO->mask && !pmReadoutGenerateMask(inRO, pmConfigMask("SAT", config),48 pmConfigMask("BAD", config))) {49 psError(PS_ERR_UNKNOWN, false, "Unable to generate mask for input image");50 return false;43 int numCols = input->numCols, numRows = input->numRows; // Image dimensions 44 if (!inRO->mask) { 45 inRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 46 psImageInit(inRO->mask, 0); 51 47 } 52 if (!inRO->weight && !pmReadoutGenerateWeight(inRO, true)) { 53 psError(PS_ERR_UNKNOWN, false, "Unable to generate weight map for input image"); 54 return false; 55 } 56 if (!refRO->mask && !pmReadoutGenerateMask(refRO, pmConfigMask("SAT", config), 57 pmConfigMask("BAD", config))) { 58 psError(PS_ERR_UNKNOWN, false, "Unable to generate mask for reference image"); 59 return false; 60 } 61 if (!refRO->weight && !pmReadoutGenerateWeight(refRO, true)) { 62 psError(PS_ERR_UNKNOWN, false, "Unable to generate weight map for reference image"); 63 return false; 48 if (!refRO->mask) { 49 refRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 50 psImageInit(refRO->mask, 0); 64 51 } 65 52 66 // Worried about the masks for bad pixels and bad stamps colliding, so make our own mask 67 int numCols = input->numCols, numRows = input->numRows; // Image dimensions 68 psImage *stampMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Mask to use for stamps 69 for (int y = 0; y < numRows; y++) { 70 for (int x = 0; x < numCols; x++) { 71 stampMask->data.PS_TYPE_MASK_DATA[y][x] = 72 (refRO->mask->data.PS_TYPE_MASK_DATA[y][x] & maskBad) ? MASK_BAD : 0; 73 } 74 } 53 // Mask for subtraction 54 psImage *subMask = pmSubtractionMask(inRO->mask, refRO->mask, maskBad, size, footprint); 75 55 76 56 #if 0 … … 97 77 int numRejected = -1; // Number of rejected stamps in each iteration 98 78 for (int i = 0; i < iter && numRejected != 0; i++) { 99 stamps = pmSubtractionFindStamps(stamps, refRO->image, stampMask, MASK_BAD, MASK_STAMP, 100 threshold, spacing, size + footprint); 79 stamps = pmSubtractionFindStamps(stamps, refRO->image, subMask, threshold, spacing); 101 80 if (!stamps) { 102 81 psError(PS_ERR_UNKNOWN, false, "Unable to find stamps on reference image."); … … 116 95 } 117 96 118 numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, s tampMask, MASK_STAMP,97 numRejected = pmSubtractionRejectStamps(stamps, refRO->image, inRO->image, subMask, 119 98 solution, footprint, rej, kernels); 120 99 if (numRejected < 0) { … … 124 103 psLogMsg("ppSub", PS_LOG_INFO, "%d stamps rejected on iteration %d.", numRejected, i); 125 104 } 126 psFree(s tampMask);105 psFree(subMask); 127 106 128 107 psImage *convImage = NULL, *convWeight = NULL, *convMask = NULL; // Convolved images 129 if (!pmSubtractionConvolve(&convImage, &convWeight, &convMask, 130 refRO->image, refRO->weight, refRO->mask, 131 MASK_BAD, maskBlank, solution, kernels)) { 108 if (!pmSubtractionConvolve(&convImage, &convWeight, &convMask, refRO->image, refRO->weight, subMask, 109 maskBlank, solution, kernels)) { 132 110 psError(PS_ERR_UNKNOWN, false, "Unable to convolve reference image."); 133 111 goto ERROR; … … 136 114 // Do the subtraction 137 115 if (reverse) { 138 (void)psBinaryOp(inRO->image, convImage, "-", inRO->image);116 outRO->image = (psImage*)psBinaryOp(NULL, convImage, "-", inRO->image); 139 117 } else { 140 (void)psBinaryOp(inRO->image, inRO->image, "-", convImage);118 outRO->image = (psImage*)psBinaryOp(NULL, inRO->image, "-", convImage); 141 119 } 142 (void)psBinaryOp(inRO->mask, convMask, "|", inRO->mask); 143 (void)psBinaryOp(inRO->weight, convWeight, "+", inRO->weight); 120 outRO->mask = (psImage*)psBinaryOp(NULL, convMask, "|", inRO->mask); 121 if (convWeight) { 122 outRO->weight = (psImage*)psBinaryOp(NULL, convWeight, "+", inRO->weight); 123 } 144 124 145 125 psFree(convImage); 146 126 psFree(convMask); 147 127 psFree(convWeight); 128 129 outRO->data_exists = true; 130 outCell->data_exists = true; 131 outCell->parent->data_exists = true; 132 133 if (!pmFPACopyConcepts(outCell->parent->parent, inRO->parent->parent->parent)) { 134 psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output."); 135 return false; 136 } 148 137 149 138 #if 0 … … 180 169 #endif 181 170 171 psFree(kernels); 172 psFree(stamps); 173 psFree(solution); 182 174 183 psFree(kernels); 184 psFree(stamps); 185 psFree(solution); 186 return true; 175 if (psMetadataLookupBool(NULL, config->arguments, "PHOTOMETRY")) { 176 pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); 177 pmFPACopy(photFile->fpa, inRO->parent->parent->parent); 187 178 188 ERROR: 189 psFree(kernels); 190 psFree(stamps); 191 psFree(solution); 192 return false; 179 psphotReadout(config, view); 180 181 pmFPAfileActivate(config->files, false, "PSPHOT.INPUT"); 182 } 183 184 return true; 185 186 ERROR: 187 psFree(kernels); 188 psFree(stamps); 189 psFree(solution); 190 return false; 193 191 }
Note:
See TracChangeset
for help on using the changeset viewer.
