Changeset 7479
- Timestamp:
- Jun 9, 2006, 4:59:23 PM (20 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
-
pmMaskBadPixels.c (modified) (2 diffs)
-
pmMaskBadPixels.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmMaskBadPixels.c
r7283 r7479 5 5 * match the value to mask. 6 6 * 7 * Given an input image, in, a bad pixel mask, a corresponding value in the bad pixel mask to mask in the 8 * input image, maskVal, a saturation level, and a growing radius, pmMaskBadPixels shall mask in the input 9 * image those pixels in the bad pixel mask that match the value to mask. Note that the input image, in, is 10 * modified in-place. All pixels in the mask which satisfy the maskVal shall have their corresponding pixels 11 * masked in the input image, in. All pixels which satisfy the growVal shall have their corresponding 12 * pixels, along with all pixels within the grow radius masked. Pixels which have flux greater than sat shall 13 * also be masked, but not grown. Note that the input image, in, and the mask need not be the same size, since 14 * the input image may already have been trimmed (following overscan subtraction), but the function shall use 15 * the offsets in the image (in->x0 and in->y0) to determine the appropriate offsets to obtain the correct 16 * pixel on the mask. In the event that the mask image is too small (i.e., pixels on the input image refer to 7 * Apply the supplied bad pixel mask readout (mask) to the given science readout (input). 8 * The science readout must already have a supplied mask element (use eg. pmReadoutSetMask) 9 * The supplied mask image must be of MASK type 10 11 * If maskVal is non-zero, all pixels in the mask have any of the same bits sets as maskVal 12 * shall have the corresponding bits raised. 13 14 * If maskVal is zero, any zero pixels in the mask be OR-ed with PM_MASK_BAD 15 16 * Note that the input image and the mask need not be the same size, since the input image may 17 * already have been trimmed (following overscan subtraction). The function assumes the pixels 18 * originate from the same detector and uses the values of col0,row0 in both the input and the 19 * mask to match corresponding pixels. 20 21 * In the event that the mask image is too small (i.e., pixels on the input image refer to 17 22 * pixels outside the range of the mask image), the function shall generate an error. 18 23 19 24 * @author Ross Harman, MHPCC 25 * @author Eugene Magnier, IfA 20 26 * 21 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $22 * @date $Date: 2006-06- 02 02:16:05$27 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 28 * @date $Date: 2006-06-10 02:59:23 $ 23 29 * 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii30 * Copyright 2004 IfA, University of Hawaii 25 31 */ 26 32 … … 37 43 #include "pmMaskBadPixelsErrors.h" 38 44 39 bool pmMaskBadPixels(pmReadout *in, const psImage *mask, unsigned int maskVal, float sat, 40 unsigned int growVal, int grow) 45 // apply an externally-supplied mask image to the current science image 46 // this function 47 bool pmMaskBadPixels(pmReadout *input, pmReadout *mask, psMaskType maskVal) 41 48 { 42 int i = 0;43 int j = 0;44 int jj = 0;45 int ii = 0;46 int rRound = 0;47 int rowMin = 0;48 int rowMax = 0;49 int colMin = 0;50 int colMax = 0;51 int totOffCol = 0;52 int totOffRow = 0;53 float r = 0.0f;54 psElemType inType;55 psElemType maskType;56 psImage *inImage = NULL;57 psImage *inMask = NULL;58 49 50 int xI; 51 int xJ; 59 52 60 // Check for nulls 61 if (in == NULL) { 62 return true; // Readout may not have data in it 63 } else if(mask==NULL) { 64 psError( PS_ERR_BAD_PARAMETER_NULL, true, 65 PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE); 53 PS_ASSERT_PTR_NON_NULL(input, false); 54 PS_ASSERT_PTR_NON_NULL(input->mask, false); 55 PS_ASSERT_IMAGE_TYPE(input->mask, PS_TYPE_MASK, NULL); 56 57 PS_ASSERT_PTR_NON_NULL(mask, false); 58 PS_ASSERT_PTR_NON_NULL(mask->mask, false); 59 PS_ASSERT_IMAGE_TYPE(mask->mask, PS_TYPE_MASK, NULL); 60 61 psImage *inMask = input->mask; 62 psImage *exMask = mask->mask; 63 64 int rowMax = inMask->row0 + inMask->numRows; 65 int colMax = inMask->col0 + inMask->numCols; 66 67 if (exMask->row0 > inMask->row0) { 68 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 69 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 70 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols); 66 71 return false; 67 72 } 68 69 inImage = in->image; 70 if (inImage == NULL) { 71 psError( PS_ERR_BAD_PARAMETER_NULL, true, 72 PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE); 73 return false; 74 } else if(in->mask == NULL) { 75 in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK); 76 memset(in->mask->data.V[0], 0, inImage->numCols*inImage->numRows*PSELEMTYPE_SIZEOF(PS_TYPE_MASK)); 77 } 78 inMask = in->mask; 79 80 // Check input image and its mask are not larger than mask 81 if(inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) { 73 if (exMask->col0 > inMask->col0) { 82 74 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 83 75 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 84 in Image->numRows, inImage->numCols, mask->numRows, mask->numCols);76 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols); 85 77 return false; 86 } else if(inMask->numRows>mask->numRows || inMask->numCols>mask->numCols) { 78 } 79 if (exMask->row0 + exMask->numRows < rowMax) { 87 80 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 88 PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE, 89 inMask->numRows, inMask->numCols, mask->numRows, mask->numCols); 81 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 82 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols); 83 return false; 84 } 85 if (exMask->col0 + exMask->numCols < colMax) { 86 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 87 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 88 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols); 90 89 return false; 91 90 } 92 91 93 92 // Determine total offset based on image offset with chip offset 94 totOffCol = inImage->col0; // + in->col0; 95 totOffRow = inImage->row0; // + in->row0; 93 // XXX if we choose to correct for the readout location, apply input->col0,row0 here 94 int offCol = inMask->col0 - exMask->col0; 95 int offRow = inMask->row0 - exMask->row0; 96 96 97 // Check that offsets are within image limits 98 if(totOffRow>=mask->numRows || totOffCol>=mask->numCols) { 99 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 100 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE, 101 totOffRow, totOffCol, mask->numRows, mask->numCols); 102 return false; 103 } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) { 104 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 105 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE, 106 totOffRow, totOffCol, inImage->numRows, inImage->numCols); 107 return false; 108 } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) { 109 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 110 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE_MASK, 111 totOffRow, totOffCol, inMask->numRows, inMask->numCols); 112 return false; 97 // masks are both of type PS_TYPE_MASK 98 psMaskType **exVal = exMask->data.U8; 99 psMaskType **inVal = inMask->data.U8; 100 101 // apply exMask values 102 if (maskVal) { 103 // set raised pixels in exMask which are selected by maskVal 104 for (int j = 0; j < inMask->numRows; j++) { 105 xJ = j - offRow; 106 for (int i = 0; i < inMask->numCols; i++) { 107 xI = i - offCol; 108 inVal[j][i] |= (maskVal & exVal[xJ][xI]); 109 } 110 } 111 } else { 112 // set raised pixels in exMask which are selected by maskVal 113 for (int j = 0; j < inMask->numRows; j++) { 114 xJ = j - offRow; 115 for (int i = 0; i < inMask->numCols; i++) { 116 xI = i - offCol; 117 if (exVal[xJ][xI] == 0) { 118 inVal[j][i] |= PM_MASK_BAD; 119 } 120 } 121 } 113 122 } 114 123 115 // Check for incorrect types 116 inType = inImage->type.type; 117 maskType = mask->type.type; 118 if(PS_IS_PSELEMTYPE_COMPLEX(inType)) { 119 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 120 PS_ERRORTEXT_pmMaskBadPixels_TYPE_INPUT_IMAGE, 121 inType); 122 return false; 123 } else if(maskType!=PS_TYPE_MASK) { 124 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 125 PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE, 126 maskType); 127 return false; 128 } 129 130 // Macro for all PS types 131 #define PM_BAD_PIXELS(TYPE) \ 132 case PS_TYPE_##TYPE: \ 133 for(j=totOffRow; j<inImage->numRows; j++) { \ 134 for(i=totOffCol; i<inImage->numCols; i++) { \ 135 \ 136 /* Pixels with flux greater than sat shall be masked */ \ 137 if(inImage->data.TYPE[j][i] > sat) { \ 138 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT; \ 139 } \ 140 \ 141 /* Pixels which satisfy maskVal shall be masked */ \ 142 inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal); \ 143 \ 144 /* Pixels which satisfy growVal and within the grow radius shall be masked */ \ 145 if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) { \ 146 rowMin = PS_MAX(j-grow, 0); \ 147 rowMax = PS_MIN(j+grow+1, inImage->numRows); \ 148 colMin = PS_MAX(i-grow, 0); \ 149 colMax = PS_MIN(i+grow+1, inImage->numCols); \ 150 for(jj=rowMin; jj<rowMax; jj++) { \ 151 for(ii=colMin; ii<colMax; ii++) { \ 152 r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j)); \ 153 rRound = r + 0.5; \ 154 if(rRound <= grow) { \ 155 inMask->data.PS_TYPE_MASK_DATA[jj][ii] |= \ 156 (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal); \ 157 } \ 158 } \ 159 } \ 160 } \ 161 } \ 162 } \ 163 break; 164 165 // Switch to call bad pixel masking macro defined above 166 switch(inType) { 167 PM_BAD_PIXELS(U8); 168 PM_BAD_PIXELS(U16); 169 PM_BAD_PIXELS(U32); 170 PM_BAD_PIXELS(U64); 171 PM_BAD_PIXELS(S8); 172 PM_BAD_PIXELS(S16); 173 PM_BAD_PIXELS(S32); 174 PM_BAD_PIXELS(S64); 175 PM_BAD_PIXELS(F32); 176 PM_BAD_PIXELS(F64); 177 default: 178 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 179 PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED, 180 inType); 181 } 182 183 return false; 124 return true; 184 125 } -
trunk/psModules/src/detrend/pmMaskBadPixels.h
r7283 r7479 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $22 * @date $Date: 2006-06- 02 02:16:05$21 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2006-06-10 02:59:23 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 /** Execute bad pixels module. 33 33 * 34 * Given an input image, a bad pixel mask, a corresponding value in the bad pixel mask to mask, a35 * saturation level, and a growing radius, mask in the input image those pixels in the bad pixel mask that36 * match the value to mask.37 34 * 38 35 * @return bool: True or false for success or failure 39 36 */ 40 bool pmMaskBadPixels(41 pmReadout *in, ///< Readout containing input image data.42 const psImage *mask, ///< Mask data to be added to readout mask data.43 unsigned int maskVal, ///< Mask value to determine what to add to input mask.44 float sat, ///< Saturation limit to mask bad pixels.45 unsigned int growVal, ///< Mask data to determine if a circurlar area should be masked.46 int grow ///< Radius of mask to apply around pixel.47 );48 37 38 bool pmMaskBadPixels(pmReadout *input, pmReadout *mask, psMaskType maskVal); 49 39 50 40 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
