Changeset 6872 for trunk/psModules/src/detrend
- Timestamp:
- Apr 17, 2006, 8:01:05 AM (20 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 added
- 8 edited
-
Makefile.am (modified) (1 diff)
-
pmFlatField.c (modified) (10 diffs)
-
pmFlatField.h (modified) (3 diffs)
-
pmFringeStats.c (added)
-
pmFringeStats.h (added)
-
pmMaskBadPixels.c (modified) (5 diffs)
-
pmMaskBadPixels.h (modified) (5 diffs)
-
pmMaskBadPixelsErrors.h (modified) (3 diffs)
-
pmNonLinear.c (modified) (5 diffs)
-
pmNonLinear.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/Makefile.am
r5170 r6872 3 3 libpsmoduledetrend_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) 4 4 libpsmoduledetrend_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 libpsmoduledetrend_la_SOURCES = pmFlatField.c \ 6 pmMaskBadPixels.c \ 7 pmNonLinear.c 5 libpsmoduledetrend_la_SOURCES = \ 6 pmFlatField.c \ 7 pmFringeStats.c \ 8 pmMaskBadPixels.c \ 9 pmNonLinear.c 8 10 9 11 psmoduleincludedir = $(includedir) 10 12 psmoduleinclude_HEADERS = \ 11 pmFlatField.h \ 12 pmFlatFieldErrors.h \ 13 pmMaskBadPixelsErrors.h \ 14 pmMaskBadPixels.h \ 15 pmNonLinear.h 13 pmFlatField.h \ 14 pmFlatFieldErrors.h \ 15 pmFringeStats.h \ 16 pmMaskBadPixelsErrors.h \ 17 pmMaskBadPixels.h \ 18 pmNonLinear.h 16 19 17 20 EXTRA_DIST = pmFlatFieldErrors.dat pmMaskBadPixelsErrors.dat -
trunk/psModules/src/detrend/pmFlatField.c
r5543 r6872 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 6 1 7 /** @file pmFlatField.c 2 8 * … … 18 24 * @author Ross Harman, MHPCC 19 25 * 20 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $21 * @date $Date: 200 5-11-18 19:43:14$26 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 22 28 * 23 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 36 #include<stdio.h> 31 37 #include<math.h> 32 #include <string .h>38 #include <strings.h> 33 39 34 40 #include "pslib.h" … … 36 42 #include "pmMaskBadPixels.h" 37 43 #include "pmFlatFieldErrors.h" 38 #include "pmSubtractBias.h"39 44 40 // XXX: This should be removed when the autoconf stuff handles psConstants.h correctly.41 #define PS_WARN_PTR_NON_NULL(NAME) \42 if ((NAME) == NULL) { \43 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \44 } \45 45 46 bool pmFlatField( 47 pmReadout *in, 48 const pmReadout *flat) 46 bool pmFlatField(pmReadout *in, const pmReadout *flat) 49 47 { 50 // XXX: Use the proper image and readout asserts.51 PS_ASSERT_PTR_NON_NULL(in, true);52 PS_ASSERT_PTR_NON_NULL(in->image, false);53 PS_ASSERT_PTR_NON_NULL(in->mask, false);54 PS_ASSERT_PTR_NON_NULL(flat, false);55 PS_ASSERT_PTR_NON_NULL(flat->image, false);56 if (in == NULL)57 printf("XXX: NULL\n");58 59 // XXX: Not sure if this is correct. Must consult with IfA.60 PS_ASSERT_PTR_NON_NULL(in->mask, false);61 62 PS_WARN_PTR_NON_NULL(in->parent);63 if (in->parent != NULL) {64 PS_WARN_PTR_NON_NULL(in->parent->concepts);65 }66 48 int i = 0; 67 49 int j = 0; … … 71 53 psElemType flatType; 72 54 psElemType maskType; 73 psImage *inMask = NULL;74 psImage *flatImage = NULL;75 55 76 // 77 // Determine trimmed image from metadata. 78 // 79 psImage *trimmedImg = p_psDetermineTrimmedImage(in); 80 flatImage = flat->image; 81 inMask = in->mask; 56 // Check for nulls 57 if (in == NULL) { 58 return true; // Readout may not have data in it 59 } else if(flat==NULL) { 60 psError( PS_ERR_BAD_PARAMETER_NULL, true, 61 PS_ERRORTEXT_pmFlatField_NULL_FLAT_READOUT); 62 return false; 63 } 64 65 psImage *inImage = in->image; // Input image 66 psImage *inMask = in->mask; // Mask for input image 67 psImage *flatImage = flat->image; // Flat-field image 68 69 // Offsets on the chip 70 int x0in = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.X0"); 71 int y0in = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.Y0"); 72 int x0flat = psMetadataLookupS32(NULL, flat->parent->concepts, "CELL.X0"); 73 int y0flat = psMetadataLookupS32(NULL, flat->parent->concepts, "CELL.Y0"); 74 75 if (inImage == NULL) { 76 psError( PS_ERR_BAD_PARAMETER_NULL, true, 77 PS_ERRORTEXT_pmFlatField_NULL_INPUT_IMAGE); 78 return false; 79 } else if(flatImage == NULL) { 80 psError( PS_ERR_BAD_PARAMETER_NULL, true, 81 PS_ERRORTEXT_pmFlatField_NULL_FLAT_IMAGE); 82 return false; 83 } 82 84 83 85 // Check input image and its mask are not larger than flat image 84 86 85 if (trimmedImg == NULL) 86 printf("XXX: 00\n"); 87 if (flatImage == NULL) 88 printf("XXX 01\n"); 89 90 if (trimmedImg->numRows>flatImage->numRows || trimmedImg->numCols>flatImage->numCols) { 87 if (inImage->numRows>flatImage->numRows || inImage->numCols>flatImage->numCols) { 91 88 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 92 89 PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE, 93 trimmedImg->numRows, trimmedImg->numCols, flatImage->numRows, flatImage->numCols);90 inImage->numRows, inImage->numCols, flatImage->numRows, flatImage->numCols); 94 91 return false; 95 92 } 96 if (inMask ->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols) {93 if (inMask && (inMask->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols)) { 97 94 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 98 95 PS_ERRORTEXT_pmFlatField_SIZE_MASK_IMAGE, … … 102 99 103 100 // Determine total offset based on image offset with chip offset 104 totOffCol = trimmedImg->col0 + in->col0;105 totOffRow = trimmedImg->row0 + in->row0;101 totOffCol = inImage->col0 + y0in - flatImage->col0 - y0flat; 102 totOffRow = inImage->row0 + x0in - flatImage->row0 - x0flat; 106 103 107 104 // Check that offsets are within image limits … … 111 108 totOffRow, totOffCol, flatImage->numRows, flatImage->numCols); 112 109 return false; 113 } else if(totOffRow>= trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {110 } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) { 114 111 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 115 112 PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE, 116 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);113 totOffRow, totOffCol, inImage->numRows, inImage->numCols); 117 114 return false; 118 } else if( totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {115 } else if(inMask && (totOffRow>=inMask->numRows || totOffCol>=inMask->numCols)) { 119 116 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 120 117 PS_ERRORTEXT_pmFlatField_OFFSET_MASK_IMAGE, … … 124 121 125 122 // Check for incorrect types 126 inType = trimmedImg->type.type;123 inType = inImage->type.type; 127 124 flatType = flatImage->type.type; 128 125 maskType = inMask->type.type; … … 137 134 flatType); 138 135 return false; 139 } else if( maskType != PS_TYPE_MASK) {136 } else if(inMask && inMask->type.type != PS_TYPE_MASK) { 140 137 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 141 138 PS_ERRORTEXT_pmFlatField_TYPE_MASK_IMAGE, … … 153 150 case PS_TYPE_##TYPE: \ 154 151 /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */ \ 155 for(j = totOffRow; j < trimmedImg->numRows; j++) { \156 for(i = totOffCol; i < trimmedImg->numCols; i++) { \152 for(j = totOffRow; j < inImage->numRows; j++) { \ 153 for(i = totOffCol; i < inImage->numCols; i++) { \ 157 154 if(flatImage->data.TYPE[j][i] <= 0.0) { \ 158 155 /* Negative or zero flat pixels shall be masked in input image as PM_MASK_FLAT */ \ 159 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT; \ 156 if (inMask) { \ 157 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT; \ 158 } \ 160 159 flatImage->data.TYPE[j][i] = 0.0; \ 161 160 } \ 162 161 } \ 163 162 } \ 164 for(j = totOffRow; j < trimmedImg->numRows; j++) { \165 for(i = totOffCol; i < trimmedImg->numCols; i++) { \166 if( !inMask->data.PS_TYPE_MASK_DATA[j][i]) {\163 for(j = totOffRow; j < inImage->numRows; j++) { \ 164 for(i = totOffCol; i < inImage->numCols; i++) { \ 165 if(inMask && !inMask->data.PS_TYPE_MASK_DATA[j][i]) { \ 167 166 /* Module shall divide the input image by the flat-fielded image */ \ 168 trimmedImg->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \167 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \ 169 168 } \ 170 169 } \ -
trunk/psModules/src/detrend/pmFlatField.h
r5435 r6872 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 6 1 7 /** @file pmFlatField.h 2 8 * … … 18 24 * @author Ross Harman, MHPCC 19 25 * 20 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $21 * @date $Date: 200 5-10-20 23:06:24$26 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 22 28 * 23 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 31 26 32 #include "pslib.h" 27 #include "pm Astrometry.h"33 #include "pmFPA.h" 28 34 29 35 -
trunk/psModules/src/detrend/pmMaskBadPixels.c
r5543 r6872 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.4 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 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 } -
trunk/psModules/src/detrend/pmMaskBadPixels.h
r5516 r6872 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.h 2 7 * … … 19 24 * @author Ross Harman, MHPCC 20 25 * 21 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $22 * @date $Date: 200 5-11-15 20:09:03$26 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 23 28 * 24 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 31 27 32 #include "pslib.h" 28 #include "pm Astrometry.h"33 #include "pmFPA.h" 29 34 30 35 /** Mask values */ … … 33 38 PM_MASK_BADCOL = 0x0002, ///< The pixel is a bad column. 34 39 PM_MASK_SAT = 0x0004, ///< The pixel is saturated. 35 PM_MASK_FLAT = 0x0008 ///< The pixel is non-positive in the flat-field. 40 PM_MASK_BAD = 0x0008, ///< The pixel is low 41 PM_MASK_FLAT = 0x0010 ///< The pixel is non-positive in the flat-field. 36 42 } pmMaskValue; 37 43 38 // XXX: Use PS_MIN, PS_MAX39 44 /** Macro to find maximum of two numbers */ 40 45 #define MAX(A,B)((A)>=(B)?(A):(B)) … … 54 59 bool pmMaskBadPixels( 55 60 pmReadout *in, ///< Readout containing input image data. 56 const p mReadout *mask,///< Mask data to be added to readout mask data.61 const psImage *mask, ///< Mask data to be added to readout mask data. 57 62 unsigned int maskVal, ///< Mask value to determine what to add to input mask. 58 63 float sat, ///< Saturation limit to mask bad pixels. -
trunk/psModules/src/detrend/pmMaskBadPixelsErrors.h
r5170 r6872 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 pmMaskBadPixelsErrors.h 2 7 * … … 7 12 * @author Ross Harman, MHPCC 8 13 * 9 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $10 * @date $Date: 200 5-09-28 20:43:52$14 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-04-17 18:01:05 $ 11 16 * 12 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 28 * $2 The error text (rest of the line in pmMaskBadPixelsErrors.h) 24 29 * $n The order of the source line in pmMaskBadPixelsErrors.h (comments excluded) 25 * 30 * 26 31 * DO NOT EDIT THE LINES BETWEEN //~Start and //~End! ANY CHANGES WILL BE OVERWRITTEN. 27 32 */ -
trunk/psModules/src/detrend/pmNonLinear.c
r5675 r6872 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 pmNonLinear.c 2 7 * … … 5 10 * @author GLG, MHPCC 6 11 * 7 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-12-05 20:49:40$12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 9 14 * 10 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 27 23 28 #include "pmNonLinear.h" 24 #include "pmSubtractBias.h"25 29 26 // XXX: Remove, autoconf must be27 #define PS_WARN_PTR_NON_NULL(NAME) \28 if ((NAME) == NULL) { \29 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \30 } \31 30 /****************************************************************************** 32 31 pmNonLinearityLookup(): This routine will take an pmReadout image as input 33 32 and a 1-D polynomial. For each pixel in the input image, the polynomial will 34 be evaluated at that pixels value, and the image pixel will then be set 35 to 33 be evaluated at that pixels value, and the image pixel will then be set to 36 34 that value. 37 *****************************************************************************/35 *****************************************************************************/ 38 36 39 pmReadout *pmNonLinearityPolynomial( 40 pmReadout *inputReadout, 41 const psPolynomial1D *input1DPoly) 37 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, 38 const psPolynomial1D *input1DPoly) 42 39 { 43 40 PS_ASSERT_PTR_NON_NULL(inputReadout, NULL); … … 45 42 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 46 43 PS_ASSERT_PTR_NON_NULL(input1DPoly, NULL); 47 PS_WARN_PTR_NON_NULL(inputReadout->parent);48 if (inputReadout->parent != NULL) {49 PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts);50 }51 44 52 // 53 // Determine trimmed image from metadata. 54 // 55 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 45 psS32 i; 46 psS32 j; 56 47 57 for (psS32 i=0;i<trimmedImg->numRows;i++) { 58 for (psS32 j=0;j<trimmedImg->numCols;j++) { 59 trimmedImg->data.F32[i][j] = psPolynomial1DEval(input1DPoly, 60 trimmedImg->data.F32[i][j]); 48 for (i=0;i<inputReadout->image->numRows;i++) { 49 for (j=0;j<inputReadout->image->numCols;j++) { 50 inputReadout->image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, inputReadout->image->data.F32[i][j]); 61 51 } 62 52 } … … 71 61 inFluxe, and the corresponding value in outFlux. The image pixel will then 72 62 be set to the value from outFlux. 73 74 XXX: Must assert that filename exists. This should probably happen in75 the lookup files.76 63 *****************************************************************************/ 77 pmReadout *pmNonLinearityLookup( 78 pmReadout *inputReadout, 79 const char *filename 80 ) 64 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, 65 const psVector *inFlux, 66 const psVector *outFlux) 81 67 { 82 68 PS_ASSERT_PTR_NON_NULL(inputReadout,NULL); 83 69 PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL); 84 70 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 85 PS_WARN_PTR_NON_NULL(inputReadout->parent); 86 if (inputReadout->parent != NULL) { 87 PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts); 71 PS_ASSERT_PTR_NON_NULL(inFlux,NULL); 72 if (inFlux->n < 2) { 73 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements. Returning inputReadout image."); 74 return(inputReadout); 88 75 } 89 // 90 // Determine trimmed image from metadata. 91 // 92 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 76 PS_ASSERT_PTR_NON_NULL(outFlux,NULL); 77 psS32 tableSize = inFlux->n; 78 if (inFlux->n != outFlux->n) { 79 tableSize = PS_MIN(inFlux->n, outFlux->n); 80 psLogMsg(__func__, PS_LOG_WARN, 81 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n); 82 } 83 PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL); 84 PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL); 93 85 94 psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0); 95 psS32 numLines = psLookupTableRead(tmpLT); 86 psS32 i; 87 psS32 j; 88 psS32 binNum; 89 psScalar x; 96 90 psS32 numPixels = 0; 97 if (numLines < 2) { 98 psLogMsg(__func__, PS_LOG_WARN, 99 "WARNING: Lookup Table is too small. Returning original pmReadout.\n"); 100 } else { 101 for (psS32 i=0;i<trimmedImg->numRows;i++) { 102 for (psS32 j=0;j<trimmedImg->numCols;j++) { 103 psF64 tmpD = psLookupTableInterpolate(tmpLT, trimmedImg->data.F32[i][j], 1); 104 if (!isnan(tmpD)) { 105 trimmedImg->data.F32[i][j] = tmpD; 106 } else { 107 numPixels++; 108 } 91 psF32 slope; 92 93 x.type.type = PS_TYPE_F32; 94 for (i=0;i<inputReadout->image->numRows;i++) { 95 for (j=0;j<inputReadout->image->numCols;j++) { 96 x.data.F32 = inputReadout->image->data.F32[i][j]; 97 binNum = p_psVectorBinDisect((psVector *)inFlux, &x); 98 99 if (binNum == -2) { 100 // We get here if x is below the table lookup range. 101 inputReadout->image->data.F32[i][j] = outFlux->data.F32[0]; 102 numPixels++; 103 104 } else if (binNum == -1) { 105 // We get here if x is above the table lookup range. 106 inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1]; 107 numPixels++; 108 109 } else if (binNum < -2) { 110 // We get here if there was some other problem. 111 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect(). Returning inputReadout image."); 112 return(inputReadout); 113 numPixels++; 114 } else { 115 // Perform linear interpolation. 116 slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) / 117 (inFlux->data.F32[binNum+1] - inFlux->data.F32[binNum]); 118 inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] + 119 ((x.data.F32 - inFlux->data.F32[binNum]) * slope); 109 120 } 110 121 } 111 if (numPixels > 0) {112 psLogMsg(__func__, PS_LOG_WARN,113 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);114 }115 122 } 116 123 if (numPixels > 0) { 124 psLogMsg(__func__, PS_LOG_WARN, 125 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels); 126 } 117 127 return(inputReadout); 118 128 } -
trunk/psModules/src/detrend/pmNonLinear.h
r5435 r6872 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 pmNonLinear.h 2 7 * … … 5 10 * @author GLG, MHPCC 6 11 * 7 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-10-20 23:06:24$12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 9 14 * 10 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 21 17 22 #include "pslib.h" 18 #include "pm Astrometry.h"23 #include "pmFPA.h" 19 24 20 pmReadout *pmNonLinearityPolynomial( 21 pmReadout *in, 22 const psPolynomial1D *coeff 23 ); 25 pmReadout *pmNonLinearityPolynomial(pmReadout *in, 26 const psPolynomial1D *coeff); 24 27 25 pmReadout *pmNonLinearityLookup( 26 pmReadout *in, 27 const char *filename 28 ); 28 pmReadout *pmNonLinearityLookup(pmReadout *in, 29 const psVector *inFlux, 30 const psVector *outFlux); 29 31 30 32 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
