Changeset 7715 for trunk/psModules/src/camera/pmFPAMaskWeight.c
- Timestamp:
- Jun 27, 2006, 6:03:35 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAMaskWeight.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAMaskWeight.c
r7432 r7715 90 90 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 91 91 92 bool pmReadoutSetMask(pmReadout *readout // Readout for which to set mask92 bool pmReadoutSetMask(pmReadout *readout// Readout for which to set mask 93 93 ) 94 94 { 95 95 PS_ASSERT_PTR_NON_NULL(readout, false); 96 PS_ASSERT_IMAGE_NON_NULL(readout->image, false); 96 97 97 98 pmCell *cell = readout->parent; // The parent cell … … 111 112 psTrace(__func__, 5, "Saturation: %f, bad: %f\n", saturation, bad); 112 113 113 // Create the mask image if required114 if (!readout->mask) {115 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section116 if (!mdok || psRegionIsNaN(*trimsec)) {117 psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set --- unable to set mask.\n");118 return false;119 }120 121 pmHDU *hdu = pmHDUFromCell(cell); // The HDU containing the cell's pixels122 PS_ASSERT_PTR_NON_NULL(hdu, false);123 if (!hdu->images && !pmHDUGenerateForCell(cell)) {124 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell.\n");125 return false;126 }127 128 createParentMasks(hdu);129 130 // Need to identify which readout we're working with....131 long index = identifyReadout(hdu, readout); // Index of the readout132 if (index == -1) {133 psError(PS_ERR_UNKNOWN, true, "Unable to identify readout image in HDU.\n");134 return false;135 }136 137 psImage *mask = psImageSubset(hdu->masks->data[index], *trimsec); // The mask pixels138 if (!mask) {139 psString trimsecString = psRegionToString(*trimsec);140 psError(PS_ERR_UNKNOWN, false, "Unable to set mask from HDU with trimsec: %s.\n", trimsecString);141 psFree(trimsecString);142 return NULL;143 }144 psImageInit(mask, 0);145 readout->mask = mask;146 }147 114 148 115 // Set up the mask 149 116 psImage *image = readout->image; // The image pixels 117 if (!readout->mask) { 118 // Generate a (throwaway) mask image, if required 119 readout->mask = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8); 120 } 150 121 psImage *mask = readout->mask; // The mask pixels 151 122 for (long i = 0; i < image->numRows; i++) { … … 163 134 } 164 135 136 bool pmReadoutGenerateMask(pmReadout *readout // Readout for which to generate mask 137 ) 138 { 139 PS_ASSERT_PTR_NON_NULL(readout, false); 140 141 pmCell *cell = readout->parent; // The parent cell 142 bool mdok = true; // Status of MD lookup 143 144 // Create the mask image if required 145 if (!readout->mask) { 146 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section 147 if (!mdok || psRegionIsNaN(*trimsec)) { 148 psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set --- unable to set mask.\n"); 149 return false; 150 } 151 152 pmHDU *hdu = pmHDUFromCell(cell); // The HDU containing the cell's pixels 153 PS_ASSERT_PTR_NON_NULL(hdu, false); 154 if (!hdu->images && !pmHDUGenerateForCell(cell)) { 155 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell.\n"); 156 return false; 157 } 158 159 createParentMasks(hdu); 160 161 // Need to identify which readout we're working with.... 162 long index = identifyReadout(hdu, readout); // Index of the readout 163 if (index == -1) { 164 psError(PS_ERR_UNKNOWN, true, "Unable to identify readout image in HDU.\n"); 165 return false; 166 } 167 168 psImage *mask = psImageSubset(hdu->masks->data[index], *trimsec); // The mask pixels 169 if (!mask) { 170 psString trimsecString = psRegionToString(*trimsec); 171 psError(PS_ERR_UNKNOWN, false, "Unable to set mask from HDU with trimsec: %s.\n", trimsecString); 172 psFree(trimsecString); 173 return false; 174 } 175 psImageInit(mask, 0); 176 readout->mask = mask; 177 } 178 179 return pmReadoutSetMask(readout); 180 } 181 165 182 bool pmReadoutSetWeight(pmReadout *readout // Readout for which to set weight 166 183 ) … … 182 199 return false; 183 200 } 201 202 // Set weight image to the variance in ADU = f/g + rn^2 203 psImage *image = readout->image; // The image pixels 204 readout->weight = (psImage*)psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32)); 205 readout->weight = (psImage*)psBinaryOp(readout->weight, readout->weight, "+", 206 psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32)); 207 208 return true; 209 } 210 211 bool pmReadoutGenerateWeight(pmReadout *readout // Readout for which to generate weight 212 ) 213 { 214 PS_ASSERT_PTR_NON_NULL(readout, false); 215 216 pmCell *cell = readout->parent; // The parent cell 217 bool mdok = true; // Status of MD lookup 184 218 185 219 // Create the weight image if required … … 213 247 trimsecString); 214 248 psFree(trimsecString); 215 return NULL;249 return false; 216 250 } 217 251 psImageInit(weight, 0); … … 219 253 } 220 254 221 // Set weight image to the variance in ADU = f/g + rn^2 222 psImage *image = readout->image; // The image pixels 223 psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32)); 224 psBinaryOp(readout->weight, readout->weight, "+", 225 psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32)); 226 227 return true; 228 } 229 230 bool pmCellSetMaskWeight(pmCell *cell // Cell for which to set weights 231 ) 255 return pmReadoutSetWeight(readout); 256 } 257 258 bool pmCellGenerateMaskWeight(pmCell *cell // Cell for which to set weights 259 ) 232 260 { 233 261 PS_ASSERT_PTR_NON_NULL(cell, false); … … 237 265 for (int i = 0; i < readouts->n; i++) { 238 266 pmReadout *readout = readouts->data[i]; // The readout 239 success |= pmReadout SetMask(readout);240 success |= pmReadout SetWeight(readout);267 success |= pmReadoutGenerateMask(readout); 268 success |= pmReadoutGenerateWeight(readout); 241 269 } 242 270 … … 244 272 } 245 273 246 bool pmReadout SetMaskWeight(pmReadout *readout // Readout for which to set mask and weights247 )274 bool pmReadoutGenerateMaskWeight(pmReadout *readout // Readout for which to set mask and weights 275 ) 248 276 { 249 277 PS_ASSERT_PTR_NON_NULL(readout, false); … … 251 279 bool success; 252 280 253 success |= pmReadout SetMask(readout);254 success |= pmReadout SetWeight(readout);281 success |= pmReadoutGenerateMask(readout); 282 success |= pmReadoutGenerateWeight(readout); 255 283 256 284 return success;
Note:
See TracChangeset
for help on using the changeset viewer.
