Changeset 7403
- Timestamp:
- Jun 7, 2006, 11:02:55 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAMaskWeight.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAMaskWeight.c
r7308 r7403 1 1 #include <stdio.h> 2 #include "pslib.h" 2 #include <assert.h> 3 4 #include <pslib.h> 3 5 #include "pmFPA.h" 6 #include "pmHDU.h" 7 #include "pmHDUUtils.h" 8 #include "pmHDUGenerate.h" 4 9 #include "pmFPAMaskWeight.h" 10 11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 // File-static (private) functions 13 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 14 15 // Create the parent mask images that reside in the HDU 16 static void createParentMasks(pmHDU *hdu // The HDU for which to create 17 ) 18 { 19 assert(hdu); 20 assert(hdu->images); 21 22 // Generate the parent mask images 23 psArray *images = hdu->images; // Array of images 24 psArray *masks = hdu->masks; // Array of masks 25 if (!masks) { 26 masks = psArrayAlloc(images->n); 27 masks->n = images->n; 28 hdu->masks = masks; 29 } 30 31 for (long i = 0; i < images->n; i++) { 32 psImage *image = images->data[i]; // The image for this readout 33 if (!image || masks->data[i]) { 34 continue; 35 } 36 masks->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 37 } 38 39 return; 40 } 41 42 // Create the parent weight images that reside in the HDU 43 static void createParentWeights(pmHDU *hdu // The HDU for which to create 44 ) 45 { 46 assert(hdu); 47 assert(hdu->images); 48 49 // Generate the parent mask images 50 psArray *images = hdu->images; // Array of images 51 psArray *weights = hdu->weights; // Array of weight images 52 if (!masks) { 53 weights = psArrayAlloc(images->n); 54 weights->n = images->n; 55 hdu->weights = weights; 56 } 57 58 for (long i = 0; i < images->n; i++) { 59 psImage *image = images->data[i]; // The image for this readout 60 if (!image || weights->data[i]) { 61 continue; 62 } 63 weights->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 64 } 65 66 return; 67 } 68 69 // Identify a readout within the HDU, on the basis of the image pointer. 70 // This is a little dirty, but hopefully should work.... 71 static long identifyReadout(pmHDU *hdu, // The HDU containing the readouts 72 pmReadout *readout // The readout to be identified 73 ) 74 { 75 assert(hdu); 76 assert(readout); 77 78 long index = -1; // Index of the readout 79 for (long i = 0; i < hdu->images->n && index == -1; i++) { 80 if (hdu->images->data[i] == readout->image) { 81 index = i; 82 } 83 } 84 85 return index; 86 } 87 88 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 89 // Public functions 90 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 91 6 92 bool pmReadoutSetMask(pmReadout *readout // Readout for which to set mask … … 25 111 psTrace(__func__, 5, "Saturation: %f, bad: %f\n", saturation, bad); 26 112 113 // Create the mask image if required 114 if (!readout->mask) { 115 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section 116 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 pixels 122 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 readout 132 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->images->data[index], *trimsec); // The mask pixels 138 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 148 // Set up the mask 27 149 psImage *image = readout->image; // The image pixels 28 150 psImage *mask = readout->mask; // The mask pixels 29 if (!mask) { 30 mask = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8); 31 mask->col0 = image->col0; 32 mask->row0 = image->row0; 33 readout->mask = mask; 34 psImageInit(mask, 0); 35 } 36 37 // Set up the mask 38 for (int i = 0; i < image->numRows; i++) { 39 for (int j = 0; j < image->numCols; j++) { 151 for (long i = 0; i < image->numRows; i++) { 152 for (long j = 0; j < image->numCols; j++) { 40 153 if (image->data.F32[i][j] >= saturation) { 41 154 mask->data.U8[i][j] |= PM_MASK_SAT; … … 70 183 } 71 184 185 // Create the weight image if required 186 if (!readout->weight) { 187 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section 188 if (!mdok || psRegionIsNaN(*trimsec)) { 189 psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set --- unable to set weight.\n"); 190 return false; 191 } 192 193 pmHDU *hdu = pmHDUFromCell(cell); // The HDU containing the cell's pixels 194 PS_ASSERT_PTR_NON_NULL(hdu, false); 195 if (!hdu->images && !pmHDUGenerateForCell(cell)) { 196 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell.\n"); 197 return false; 198 } 199 200 createParentWeights(hdu); 201 202 // Need to identify which readout we're working with.... 203 long index = identifyReadout(hdu, readout); // Index of the readout 204 if (index == -1) { 205 psError(PS_ERR_UNKNOWN, true, "Unable to identify readout image in HDU.\n"); 206 return false; 207 } 208 209 psImage *weight = psImageSubset(hdu->images->data[index], *trimsec); // The weight pixels 210 if (!weight) { 211 psString trimsecString = psRegionToString(*trimsec); 212 psError(PS_ERR_UNKNOWN, false, "Unable to set weight from HDU with trimsec: %s.\n", 213 trimsecString); 214 psFree(trimsecString); 215 return NULL; 216 } 217 psImageInit(weight, 0); 218 readout->weight = weight; 219 } 220 221 // Set weight image to the variance in ADU = f/g + rn^2 72 222 psImage *image = readout->image; // The image pixels 73 psImage *weight = readout->weight; // The weight pixels74 if (!weight) {75 weight = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32);76 weight->col0 = image->col0;77 weight->row0 = image->row0;78 readout->weight = weight;79 psImageInit(weight, 0.0);80 }81 82 // Set weight image to the variance in ADU = f/g + rn^283 223 psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32)); 84 224 psBinaryOp(readout->weight, readout->weight, "+", … … 104 244 } 105 245 106 bool pmReadoutSetMaskWeight(pmReadout *readout // Readout for which to set weights246 bool pmReadoutSetMaskWeight(pmReadout *readout // Readout for which to set mask and weights 107 247 ) 108 248 {
Note:
See TracChangeset
for help on using the changeset viewer.
