Changeset 5516 for trunk/psModules/src/detrend
- Timestamp:
- Nov 15, 2005, 10:09:03 AM (21 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 4 edited
-
pmFlatField.c (modified) (9 diffs)
-
pmMaskBadPixels.c (modified) (5 diffs)
-
pmMaskBadPixels.h (modified) (3 diffs)
-
pmNonLinear.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmFlatField.c
r5435 r5516 18 18 * @author Ross Harman, MHPCC 19 19 * 20 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $21 * @date $Date: 2005-1 0-20 23:06:24$20 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 21 * @date $Date: 2005-11-15 20:09:03 $ 22 22 * 23 23 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 36 #include "pmMaskBadPixels.h" 37 37 #include "pmFlatFieldErrors.h" 38 #include "pmSubtractBias.h" 38 39 39 40 … … 42 43 const pmReadout *flat) 43 44 { 45 // XXX: Use the proper image and readout asserts. 46 PS_ASSERT_PTR_NON_NULL(in, true); 47 PS_ASSERT_PTR_NON_NULL(in->image, false); 48 PS_ASSERT_PTR_NON_NULL(in->mask, false); 49 PS_ASSERT_PTR_NON_NULL(flat, false); 50 PS_ASSERT_PTR_NON_NULL(flat->image, false); 51 if (in == NULL) 52 printf("XXX: NULL\n"); 53 44 54 // XXX: Not sure if this is correct. Must consult with IfA. 45 55 PS_ASSERT_PTR_NON_NULL(in->mask, false); 56 57 PS_WARN_PTR_NON_NULL(in->parent); 58 if (in->parent != NULL) { 59 PS_WARN_PTR_NON_NULL(in->parent->concepts); 60 } 46 61 int i = 0; 47 62 int j = 0; … … 51 66 psElemType flatType; 52 67 psElemType maskType; 53 psImage *inImage = NULL;54 68 psImage *inMask = NULL; 55 69 psImage *flatImage = NULL; 56 70 57 58 // Check for nulls 59 if (in == NULL) { 60 return true; // Readout might have data in it 61 } else if(flat==NULL) { 62 psError( PS_ERR_BAD_PARAMETER_NULL, true, 63 PS_ERRORTEXT_pmFlatField_NULL_FLAT_READOUT); 64 return false; 65 } 66 67 inImage = in->image; 71 // 72 // Determine trimmed image from metadata. 73 // 74 psImage *trimmedImg = p_psDetermineTrimmedImage(in); 68 75 flatImage = flat->image; 69 if (inImage == NULL) {70 psError( PS_ERR_BAD_PARAMETER_NULL, true,71 PS_ERRORTEXT_pmFlatField_NULL_INPUT_IMAGE);72 return false;73 } else if(flatImage == NULL) {74 psError( PS_ERR_BAD_PARAMETER_NULL, true,75 PS_ERRORTEXT_pmFlatField_NULL_FLAT_IMAGE);76 return false;77 }78 76 inMask = in->mask; 79 77 80 78 // Check input image and its mask are not larger than flat image 81 79 82 if (inImage->numRows>flatImage->numRows || inImage->numCols>flatImage->numCols) { 80 if (trimmedImg == NULL) 81 printf("XXX: 00\n"); 82 if (flatImage == NULL) 83 printf("XXX 01\n"); 84 85 if (trimmedImg->numRows>flatImage->numRows || trimmedImg->numCols>flatImage->numCols) { 83 86 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 84 87 PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE, 85 inImage->numRows, inImage->numCols, flatImage->numRows, flatImage->numCols);88 trimmedImg->numRows, trimmedImg->numCols, flatImage->numRows, flatImage->numCols); 86 89 return false; 87 90 } … … 94 97 95 98 // Determine total offset based on image offset with chip offset 96 totOffCol = inImage->col0 + in->col0;97 totOffRow = inImage->row0 + in->row0;99 totOffCol = trimmedImg->col0 + in->col0; 100 totOffRow = trimmedImg->row0 + in->row0; 98 101 99 102 // Check that offsets are within image limits … … 103 106 totOffRow, totOffCol, flatImage->numRows, flatImage->numCols); 104 107 return false; 105 } else if(totOffRow>= inImage->numRows || totOffCol>=inImage->numCols) {108 } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) { 106 109 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 107 110 PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE, 108 totOffRow, totOffCol, inImage->numRows, inImage->numCols);111 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols); 109 112 return false; 110 113 } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) { … … 116 119 117 120 // Check for incorrect types 118 inType = inImage->type.type;121 inType = trimmedImg->type.type; 119 122 flatType = flatImage->type.type; 120 123 maskType = inMask->type.type; … … 145 148 case PS_TYPE_##TYPE: \ 146 149 /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */ \ 147 for(j = totOffRow; j < inImage->numRows; j++) { \148 for(i = totOffCol; i < inImage->numCols; i++) { \150 for(j = totOffRow; j < trimmedImg->numRows; j++) { \ 151 for(i = totOffCol; i < trimmedImg->numCols; i++) { \ 149 152 if(flatImage->data.TYPE[j][i] <= 0.0) { \ 150 153 /* Negative or zero flat pixels shall be masked in input image as PM_MASK_FLAT */ \ … … 154 157 } \ 155 158 } \ 156 for(j = totOffRow; j < inImage->numRows; j++) { \157 for(i = totOffCol; i < inImage->numCols; i++) { \159 for(j = totOffRow; j < trimmedImg->numRows; j++) { \ 160 for(i = totOffCol; i < trimmedImg->numCols; i++) { \ 158 161 if(!inMask->data.PS_TYPE_MASK_DATA[j][i]) { \ 159 162 /* Module shall divide the input image by the flat-fielded image */ \ 160 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \163 trimmedImg->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \ 161 164 } \ 162 165 } \ -
trunk/psModules/src/detrend/pmMaskBadPixels.c
r5170 r5516 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $22 * @date $Date: 2005- 09-28 20:43:52$21 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2005-11-15 20:09:03 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 #include "pmMaskBadPixels.h" 36 36 #include "pmMaskBadPixelsErrors.h" 37 #include "pmSubtractBias.h" 38 39 /****************************************************************************** 40 GrowPixel(inMask, row, col, radius, maskVal): This private routine takes an 41 input image mask and a pixel location, then sets (logical or) all pixels with 42 parameter radius if that pixel to maskVal parameter. 43 *****************************************************************************/ 44 psBool GrowPixel( 45 psImage *inMask, 46 psS32 col, 47 psS32 row, 48 psS32 radius, 49 psU32 maskVal) 50 { 51 psS32 rowMin = PS_MAX(row-radius, 0); 52 psS32 rowMax = PS_MIN(row+radius+1, inMask->numRows); 53 psS32 colMin = PS_MAX(col-radius, 0); 54 psS32 colMax = PS_MIN(col+radius+1, inMask->numCols); 55 psF32 squareRadius = PS_SQR(radius); 56 57 58 for(psS32 i=rowMin; i<rowMax; i++) { 59 for(psS32 j=colMin; j<colMax; j++) { 60 // Old code: 61 // psF32 rRound = 0.5 + sqrtf((psF32) (((col-j)*(col-j)) + ((row-i)*(row-i)))); 62 // if(rRound <= radius) { 63 psF32 squareDis = (psF32) (((col-j)*(col-j)) + ((row-i)*(row-i))); 64 if (squareDis <= squareRadius) { 65 inMask->data.U8[i][j] |= maskVal; 66 } 67 } 68 } 69 return(true); 70 } 71 72 /****************************************************************************** 73 GetRadius(inImg, col, row, sat, growVal, grow): This private routine takes an 74 input image and pixel location and determines what radius that pixel must grow 75 by. 76 77 //XXX: Inline this or macro it for speed. 78 *****************************************************************************/ 79 static psS32 GetRadius( 80 psImage *inImg, 81 psS32 col, 82 psS32 row, 83 psF32 sat, 84 psU32 growVal, 85 psS32 grow) 86 { 87 psS32 growRadius = 0; 88 if (inImg->type.type == PS_TYPE_F32) { 89 if(inImg->data.F32[row][col] == growVal) { 90 growRadius = grow; 91 } 92 if (inImg->data.F32[row][col] > sat) { 93 growRadius = PS_MAX(growRadius+1, 2); 94 } 95 } else if (inImg->type.type == PS_TYPE_S32) { 96 if(inImg->data.S32[row][col] == growVal) { 97 growRadius = grow; 98 } 99 if (inImg->data.S32[row][col] > sat) { 100 growRadius = PS_MAX(growRadius+1, 2); 101 } 102 } else if (inImg->type.type == PS_TYPE_U16) { 103 if(inImg->data.U16[row][col] == growVal) { 104 growRadius = grow; 105 } 106 if (inImg->data.U16[row][col] > sat) { 107 growRadius = PS_MAX(growRadius+1, 2); 108 } 109 } else { 110 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 111 PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE, 112 inImg->type.type); 113 } 114 return(growRadius); 115 } 116 37 117 38 118 bool pmMaskBadPixels( 39 119 pmReadout *in, 40 const p sImage*mask,120 const pmReadout *mask, 41 121 unsigned int maskVal, 42 122 float sat, … … 44 124 int grow) 45 125 { 126 // XXX: Review this code then put all asserts at the top. 127 PS_ASSERT_PTR_NON_NULL(in, true); 128 PS_ASSERT_PTR_NON_NULL(in->image, false); 129 PS_WARN_PTR_NON_NULL(in->parent); 130 if (in->parent != NULL) { 131 PS_WARN_PTR_NON_NULL(in->parent->concepts); 132 } 133 PS_ASSERT_PTR_NON_NULL(mask, false); 46 134 int i = 0; 47 135 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 136 int totOffCol = 0; 56 137 int totOffRow = 0; 57 float r = 0.0f;58 138 psElemType inType; 59 139 psElemType maskType; 60 psImage *inImage = NULL;61 140 psImage *inMask = NULL; 62 141 63 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 } 72 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)); 142 // 143 // Determine trimmed image from metadata. 144 // 145 psImage *trimmedImg = p_psDetermineTrimmedImage(in); 146 if(in->mask == NULL) { 147 in->mask = psImageAlloc(trimmedImg->numCols, trimmedImg->numRows, PS_TYPE_MASK); 148 PS_IMAGE_SET_U8(in->mask, 0); 81 149 } 82 150 inMask = in->mask; 83 151 84 152 // Check input image and its mask are not larger than mask 85 if( inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) {153 if(trimmedImg->numRows > mask->image->numRows || trimmedImg->numCols > mask->image->numCols) { 86 154 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 87 155 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 88 inImage->numRows, inImage->numCols, mask->numRows, mask->numCols);89 return false; 90 } else if(inMask->numRows >mask->numRows || inMask->numCols>mask->numCols) {156 trimmedImg->numRows, trimmedImg->numCols, mask->image->numRows, mask->image->numCols); 157 return false; 158 } else if(inMask->numRows > mask->image->numRows || inMask->numCols > mask->image->numCols) { 91 159 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 92 160 PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE, 93 inMask->numRows, inMask->numCols, mask-> numRows, mask->numCols);161 inMask->numRows, inMask->numCols, mask->image->numRows, mask->image->numCols); 94 162 return false; 95 163 } 96 164 97 165 // Determine total offset based on image offset with chip offset 98 totOffCol = inImage->col0 + in->col0;99 totOffRow = inImage->row0 + in->row0;166 totOffCol = trimmedImg->col0 + in->col0; 167 totOffRow = trimmedImg->row0 + in->row0; 100 168 101 169 // Check that offsets are within image limits 102 if(totOffRow>=mask-> numRows || totOffCol>=mask->numCols) {170 if(totOffRow>=mask->image->numRows || totOffCol>=mask->image->numCols) { 103 171 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 104 172 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE, 105 totOffRow, totOffCol, mask-> numRows, mask->numCols);106 return false; 107 } else if(totOffRow>= inImage->numRows || totOffCol>=inImage->numCols) {173 totOffRow, totOffCol, mask->image->numRows, mask->image->numCols); 174 return false; 175 } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) { 108 176 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 109 177 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE, 110 totOffRow, totOffCol, inImage->numRows, inImage->numCols);178 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols); 111 179 return false; 112 180 } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) { … … 118 186 119 187 // Check for incorrect types 120 inType = inImage->type.type;121 maskType = mask-> type.type;188 inType = trimmedImg->type.type; 189 maskType = mask->image->type.type; 122 190 if(PS_IS_PSELEMTYPE_COMPLEX(inType)) { 123 191 psError( PS_ERR_BAD_PARAMETER_TYPE, true, … … 132 200 } 133 201 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; 168 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); 185 } 186 187 return false; 202 // 203 // This is the main loop which examines each pixel and masks pixels if 204 // A: The mask matches the maskValue 205 // B: The pixel is larger than the saturation value 206 // C: The pixel equals the grow value (in which case a circle is masked) 207 // 208 for(i=totOffRow; i<trimmedImg->numRows; i++) { 209 for(j=totOffCol; j<trimmedImg->numCols; j++) { 210 // 211 // A: Pixels which satisfy maskVal shall be masked 212 // 213 if (mask->image->data.U8[i][j] == maskVal) { 214 in->mask->data.U8[i][j] |= maskVal; 215 } 216 217 // 218 // We first determine how much we need to grow by and store this in 219 // growRadius. 220 // 221 psS32 growRadius = GetRadius(trimmedImg, j, i, sat, growVal, grow); 222 223 // 224 // Grow the pixel mask if necessary. 225 // 226 if (growRadius != 0) { 227 GrowPixel(in->mask, j, i, growRadius, maskVal); 228 } 229 } 230 } 231 232 return true; 188 233 } -
trunk/psModules/src/detrend/pmMaskBadPixels.h
r5170 r5516 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $22 * @date $Date: 2005- 09-28 20:43:52$21 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2005-11-15 20:09:03 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 36 } pmMaskValue; 37 37 38 // XXX: Use PS_MIN, PS_MAX 38 39 /** Macro to find maximum of two numbers */ 39 40 #define MAX(A,B)((A)>=(B)?(A):(B)) … … 53 54 bool pmMaskBadPixels( 54 55 pmReadout *in, ///< Readout containing input image data. 55 const p sImage *mask,///< Mask data to be added to readout mask data.56 const pmReadout *mask, ///< Mask data to be added to readout mask data. 56 57 unsigned int maskVal, ///< Mask value to determine what to add to input mask. 57 58 float sat, ///< Saturation limit to mask bad pixels. -
trunk/psModules/src/detrend/pmNonLinear.c
r5435 r5516 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-1 0-20 23:06:24$7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-11-15 20:09:03 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 23 23 #include "pmNonLinear.h" 24 #include "pmSubtractBias.h" 24 25 25 26 /****************************************************************************** … … 37 38 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 38 39 PS_ASSERT_PTR_NON_NULL(input1DPoly, NULL); 40 PS_WARN_PTR_NON_NULL(inputReadout->parent); 41 if (inputReadout->parent != NULL) { 42 PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts); 43 } 44 // 45 // Determine trimmed image from metadata. 46 // 47 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 39 48 40 psS32 i; 41 psS32 j; 42 43 for (i=0;i<inputReadout->image->numRows;i++) { 44 for (j=0;j<inputReadout->image->numCols;j++) { 45 inputReadout->image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, inputReadout->image->data.F32[i][j]); 49 for (psS32 i=0;i<trimmedImg->numRows;i++) { 50 for (psS32 j=0;j<trimmedImg->numCols;j++) { 51 trimmedImg->data.F32[i][j] = psPolynomial1DEval(input1DPoly, 52 trimmedImg->data.F32[i][j]); 46 53 } 47 54 } … … 68 75 PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL); 69 76 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 77 PS_WARN_PTR_NON_NULL(inputReadout->parent); 78 if (inputReadout->parent != NULL) { 79 PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts); 80 } 81 // 82 // Determine trimmed image from metadata. 83 // 84 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 85 70 86 psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0); 71 87 psS32 numLines = psLookupTableRead(tmpLT); … … 75 91 "WARNING: Lookup Table is too small. Returning original pmReadout.\n"); 76 92 } else { 77 for (psS32 i=0;i< inputReadout->image->numRows;i++) {78 for (psS32 j=0;j< inputReadout->image->numCols;j++) {79 psF64 tmpD = psLookupTableInterpolate(tmpLT, inputReadout->image->data.F32[i][j], 1);93 for (psS32 i=0;i<trimmedImg->numRows;i++) { 94 for (psS32 j=0;j<trimmedImg->numCols;j++) { 95 psF64 tmpD = psLookupTableInterpolate(tmpLT, trimmedImg->data.F32[i][j], 1); 80 96 if (!isnan(tmpD)) { 81 inputReadout->image->data.F32[i][j] = tmpD;97 trimmedImg->data.F32[i][j] = tmpD; 82 98 } else { 83 99 numPixels++;
Note:
See TracChangeset
for help on using the changeset viewer.
