- Timestamp:
- Feb 17, 2006, 7:13:42 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/detrend/pmMaskBadPixels.c
r5543 r6448 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmMaskBadPixels.c 2 7 * … … 19 24 * @author Ross Harman, MHPCC 20 25 * 21 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $22 * @date $Date: 200 5-11-18 19:43:14$26 * @version $Revision: 1.3.12.1 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-02-17 17:13:41 $ 23 28 * 24 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 36 #include<stdio.h> 32 37 #include<math.h> 33 #include<string .h>38 #include<strings.h> 34 39 35 40 #include "pmMaskBadPixels.h" 36 41 #include "pmMaskBadPixelsErrors.h" 37 #include "pmSubtractBias.h"38 42 39 //XXX: REmove, autoconf is broken. 40 #define PS_WARN_PTR_NON_NULL(NAME) \ 41 if ((NAME) == NULL) { \ 42 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \ 43 } \ 43 bool pmMaskBadPixels(pmReadout *in, const psImage *mask, unsigned int maskVal, float sat, 44 unsigned int growVal, int grow) 45 { 46 int i = 0; 47 int j = 0; 48 int jj = 0; 49 int ii = 0; 50 int rRound = 0; 51 int rowMin = 0; 52 int rowMax = 0; 53 int colMin = 0; 54 int colMax = 0; 55 int totOffCol = 0; 56 int totOffRow = 0; 57 float r = 0.0f; 58 psElemType inType; 59 psElemType maskType; 60 psImage *inImage = NULL; 61 psImage *inMask = NULL; 44 62 45 63 46 /****************************************************************************** 47 GrowPixel(inMask, row, col, radius, maskVal): This private routine takes an 48 input image mask and a pixel location, then sets (logical or) all pixels with 49 parameter radius if that pixel to maskVal parameter. 50 *****************************************************************************/ 51 psBool GrowPixel( 52 psImage *inMask, 53 psS32 col, 54 psS32 row, 55 psS32 radius, 56 psU32 maskVal) 57 { 58 psS32 rowMin = PS_MAX(row-radius, 0); 59 psS32 rowMax = PS_MIN(row+radius+1, inMask->numRows); 60 psS32 colMin = PS_MAX(col-radius, 0); 61 psS32 colMax = PS_MIN(col+radius+1, inMask->numCols); 62 psF32 squareRadius = PS_SQR(radius); 64 // Check for nulls 65 if (in == NULL) { 66 return true; // Readout may not have data in it 67 } else if(mask==NULL) { 68 psError( PS_ERR_BAD_PARAMETER_NULL, true, 69 PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE); 70 return false; 71 } 63 72 64 65 for(psS32 i=rowMin; i<rowMax; i++) { 66 for(psS32 j=colMin; j<colMax; j++) { 67 // Old code: 68 // psF32 rRound = 0.5 + sqrtf((psF32) (((col-j)*(col-j)) + ((row-i)*(row-i)))); 69 // if(rRound <= radius) { 70 psF32 squareDis = (psF32) (((col-j)*(col-j)) + ((row-i)*(row-i))); 71 if (squareDis <= squareRadius) { 72 inMask->data.U8[i][j] |= maskVal; 73 } 74 } 75 } 76 return(true); 77 } 78 79 /****************************************************************************** 80 GetRadius(inImg, col, row, sat, growVal, grow): This private routine takes an 81 input image and pixel location and determines what radius that pixel must grow 82 by. 83 84 //XXX: Inline this or macro it for speed. 85 *****************************************************************************/ 86 static psS32 GetRadius( 87 psImage *inImg, 88 psS32 col, 89 psS32 row, 90 psF32 sat, 91 psU32 growVal, 92 psS32 grow) 93 { 94 psS32 growRadius = 0; 95 if (inImg->type.type == PS_TYPE_F32) { 96 if(inImg->data.F32[row][col] == growVal) { 97 growRadius = grow; 98 } 99 if (inImg->data.F32[row][col] > sat) { 100 growRadius = PS_MAX(growRadius+1, 2); 101 } 102 } else if (inImg->type.type == PS_TYPE_S32) { 103 if(inImg->data.S32[row][col] == growVal) { 104 growRadius = grow; 105 } 106 if (inImg->data.S32[row][col] > sat) { 107 growRadius = PS_MAX(growRadius+1, 2); 108 } 109 } else if (inImg->type.type == PS_TYPE_U16) { 110 if(inImg->data.U16[row][col] == growVal) { 111 growRadius = grow; 112 } 113 if (inImg->data.U16[row][col] > sat) { 114 growRadius = PS_MAX(growRadius+1, 2); 115 } 116 } else { 117 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 118 PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE, 119 inImg->type.type); 120 } 121 return(growRadius); 122 } 123 124 125 bool pmMaskBadPixels( 126 pmReadout *in, 127 const pmReadout *mask, 128 unsigned int maskVal, 129 float sat, 130 unsigned int growVal, 131 int grow) 132 { 133 // XXX: Review this code then put all asserts at the top. 134 PS_ASSERT_PTR_NON_NULL(in, true); 135 PS_ASSERT_PTR_NON_NULL(in->image, false); 136 PS_WARN_PTR_NON_NULL(in->parent); 137 if (in->parent != NULL) { 138 PS_WARN_PTR_NON_NULL(in->parent->concepts); 139 } 140 PS_ASSERT_PTR_NON_NULL(mask, false); 141 int i = 0; 142 int j = 0; 143 int totOffCol = 0; 144 int totOffRow = 0; 145 psElemType inType; 146 psElemType maskType; 147 psImage *inMask = NULL; 148 149 // 150 // Determine trimmed image from metadata. 151 // 152 psImage *trimmedImg = p_psDetermineTrimmedImage(in); 153 if(in->mask == NULL) { 154 in->mask = psImageAlloc(trimmedImg->numCols, trimmedImg->numRows, PS_TYPE_MASK); 155 PS_IMAGE_SET_U8(in->mask, 0); 73 inImage = in->image; 74 if (inImage == NULL) { 75 psError( PS_ERR_BAD_PARAMETER_NULL, true, 76 PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE); 77 return false; 78 } else if(in->mask == NULL) { 79 in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK); 80 memset(in->mask->data.V[0], 0, inImage->numCols*inImage->numRows*PSELEMTYPE_SIZEOF(PS_TYPE_MASK)); 156 81 } 157 82 inMask = in->mask; 158 83 159 84 // Check input image and its mask are not larger than mask 160 if( trimmedImg->numRows > mask->image->numRows || trimmedImg->numCols > mask->image->numCols) {85 if(inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) { 161 86 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 162 87 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 163 trimmedImg->numRows, trimmedImg->numCols, mask->image->numRows, mask->image->numCols);88 inImage->numRows, inImage->numCols, mask->numRows, mask->numCols); 164 89 return false; 165 } else if(inMask->numRows > mask->image->numRows || inMask->numCols > mask->image->numCols) {90 } else if(inMask->numRows>mask->numRows || inMask->numCols>mask->numCols) { 166 91 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 167 92 PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE, 168 inMask->numRows, inMask->numCols, mask-> image->numRows, mask->image->numCols);93 inMask->numRows, inMask->numCols, mask->numRows, mask->numCols); 169 94 return false; 170 95 } 171 96 172 97 // Determine total offset based on image offset with chip offset 173 totOffCol = trimmedImg->col0 + in->col0;174 totOffRow = trimmedImg->row0 + in->row0;98 totOffCol = inImage->col0 + in->col0; 99 totOffRow = inImage->row0 + in->row0; 175 100 176 101 // Check that offsets are within image limits 177 if(totOffRow>=mask-> image->numRows || totOffCol>=mask->image->numCols) {102 if(totOffRow>=mask->numRows || totOffCol>=mask->numCols) { 178 103 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 179 104 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE, 180 totOffRow, totOffCol, mask-> image->numRows, mask->image->numCols);105 totOffRow, totOffCol, mask->numRows, mask->numCols); 181 106 return false; 182 } else if(totOffRow>= trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {107 } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) { 183 108 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 184 109 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE, 185 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);110 totOffRow, totOffCol, inImage->numRows, inImage->numCols); 186 111 return false; 187 112 } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) { … … 193 118 194 119 // Check for incorrect types 195 inType = trimmedImg->type.type;196 maskType = mask-> image->type.type;120 inType = inImage->type.type; 121 maskType = mask->type.type; 197 122 if(PS_IS_PSELEMTYPE_COMPLEX(inType)) { 198 123 psError( PS_ERR_BAD_PARAMETER_TYPE, true, … … 207 132 } 208 133 209 // 210 // This is the main loop which examines each pixel and masks pixels if 211 // A: The mask matches the maskValue 212 // B: The pixel is larger than the saturation value 213 // C: The pixel equals the grow value (in which case a circle is masked) 214 // 215 for(i=totOffRow; i<trimmedImg->numRows; i++) { 216 for(j=totOffCol; j<trimmedImg->numCols; j++) { 217 // 218 // A: Pixels which satisfy maskVal shall be masked 219 // 220 if (mask->image->data.U8[i][j] == maskVal) { 221 in->mask->data.U8[i][j] |= maskVal; 222 } 134 // Macro for all PS types 135 #define PM_BAD_PIXELS(TYPE) \ 136 case PS_TYPE_##TYPE: \ 137 for(j=totOffRow; j<inImage->numRows; j++) { \ 138 for(i=totOffCol; i<inImage->numCols; i++) { \ 139 \ 140 /* Pixels with flux greater than sat shall be masked */ \ 141 if(inImage->data.TYPE[j][i] > sat) { \ 142 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT; \ 143 } \ 144 \ 145 /* Pixels which satisfy maskVal shall be masked */ \ 146 inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal); \ 147 \ 148 /* Pixels which satisfy growVal and within the grow radius shall be masked */ \ 149 if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) { \ 150 rowMin = MAX(j-grow, 0); \ 151 rowMax = MIN(j+grow+1, inImage->numRows); \ 152 colMin = MAX(i-grow, 0); \ 153 colMax = MIN(i+grow+1, inImage->numCols); \ 154 for(jj=rowMin; jj<rowMax; jj++) { \ 155 for(ii=colMin; ii<colMax; ii++) { \ 156 r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j)); \ 157 rRound = r + 0.5; \ 158 if(rRound <= grow) { \ 159 inMask->data.PS_TYPE_MASK_DATA[jj][ii] |= \ 160 (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal); \ 161 } \ 162 } \ 163 } \ 164 } \ 165 } \ 166 } \ 167 break; 223 168 224 // 225 // We first determine how much we need to grow by and store this in 226 // growRadius. 227 // 228 psS32 growRadius = GetRadius(trimmedImg, j, i, sat, growVal, grow); 229 230 // 231 // Grow the pixel mask if necessary. 232 // 233 if (growRadius != 0) { 234 GrowPixel(in->mask, j, i, growRadius, maskVal); 235 } 236 } 169 // Switch to call bad pixel masking macro defined above 170 switch(inType) { 171 PM_BAD_PIXELS(U8); 172 PM_BAD_PIXELS(U16); 173 PM_BAD_PIXELS(U32); 174 PM_BAD_PIXELS(U64); 175 PM_BAD_PIXELS(S8); 176 PM_BAD_PIXELS(S16); 177 PM_BAD_PIXELS(S32); 178 PM_BAD_PIXELS(S64); 179 PM_BAD_PIXELS(F32); 180 PM_BAD_PIXELS(F64); 181 default: 182 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 183 PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED, 184 inType); 237 185 } 238 186 239 return true;187 return false; 240 188 }
Note:
See TracChangeset
for help on using the changeset viewer.
