Changeset 1822 for trunk/psModules/src/pmFlatField.c
- Timestamp:
- Sep 16, 2004, 2:49:04 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/pmFlatField.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmFlatField.c
r1815 r1822 1 /** @file pmFlatField.c S1 /** @file pmFlatField.c 2 2 * 3 * @brief Given an input image and a flat-field image, pmFlatField shall divide the input image by the flat-field image. 3 * @brief Given an input image and a flat field image, pmFlatField shall divide the input image by the flat 4 * field image. 4 5 * 5 * The input image, in, and the flat-field image, flat, need not be the same size, since the input image may already have 6 * been trimmed (following overscan subtraction), but the function shall use the offsets in the image (in->x0 7 * and in->y0) to determine the appropriate offsets to obtain the correct pixel on the flat-field. In the event that the flat 8 * image is too small (i.e., pixels on the input image refer to pixels outside the range of the flat image), the function shall 9 * generate an error. Pixels which are negative or zero in the flat shall be masked in the input image with the value PM_MASK_FLAT 10 * Negative pixels in the flat may be set to zero so that they are treated identically to zeroes. Any pixels masked in the flat 11 * shall be masked with corresponding values in the output. The function shall not normalize the flat; this responsibility is 12 * left to the caller. This function is basically equivalent to a divide (with psImageOp), but with care for the region that is 13 * divided, checking for negative pixels, and copying of the mask from the flat to the output. 6 * The input image, in, and the flat field image, flat, need not be the same size, since the input image may 7 * already have been trimmed (following overscan subtraction), but the function shall use the offsets in the 8 * image (in->x0 and in->y0) to determine the appropriate offsets to obtain the correct pixel on the flat 9 * field. In the event that the flat image is too small (i.e., pixels on the input image refer to pixels 10 * outside the range of the flat image), the function shall generate an error. Pixels which are negative or 11 * zero in the flat shall be masked in the input image with the value PM_MASK_FLAT. Negative pixels in the 12 * flat may be set to zero so that they are treated identically to zeroes. Any pixels masked in the flat 13 * shall be masked with corresponding values in the output. The function shall not normalize the flat; this 14 * responsibility is left to the caller. This function is basically equivalent to a divide (with psImageOp), 15 * but with care for the region that is divided, checking for negative pixels, and copying of the mask from 16 * the flat to the output. 14 17 * 15 18 * @author Ross Harman, MHPCC 16 19 * 17 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $18 * @date $Date: 2004-09-1 5 01:08:23$20 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 21 * @date $Date: 2004-09-17 00:49:04 $ 19 22 * 20 23 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 29 32 30 33 #include "pmFlatField.h" 34 #include "pmMaskBadPixels.h" 31 35 32 33 #define CHECK_NULL(STRUCT) \ 34 if (STRUCT == NULL) { \ 35 psError(__func__, " : Line %d - Null not allowed for %s", __LINE__, #STRUCT); \ 36 return false; \ 37 } \ 38 39 bool pmFlatField(psReadout *in, psReadout *inMask, const psReadout *flat) 36 bool pmFlatField(psReadout *in, const psReadout *flat) 40 37 { 41 38 int i = 0; … … 47 44 psElemType maskType; 48 45 psImage *inImage = NULL; 46 psImage *inMask = NULL; 49 47 psImage *flatImage = NULL; 50 psImage *maskImage = NULL;51 48 52 CHECK_NULL(in);53 CHECK_NULL(flat);54 CHECK_NULL(inMask);55 49 56 inImage = in->image; 57 flatImage = flat->image; 58 maskImage = inMask->image; 59 60 CHECK_NULL(inImage); 61 CHECK_NULL(flatImage); 62 CHECK_NULL(maskImage); 63 64 totOffCol = inImage->col0 + in->col0; 65 totOffRow = inImage->row0 + in->row0; 66 67 if(inImage->numRows > flatImage->numRows) { 68 psError(__func__, " : Line %d - Input image exceeds flat image in number of rows. (%d vs %d).", 69 __LINE__, inImage->numRows, flatImage->numRows); 50 // Check for nulls 51 if (in == NULL) { 52 psError(__func__, " : Line %d - Null not allowed for input readout", __LINE__); 53 return false; 54 } else if(flat==NULL) { 55 psError(__func__, " : Line %d - Null not allowed for flat readout", __LINE__); 70 56 return false; 71 57 } 72 58 73 if(inImage->numCols > flatImage->numCols) { 74 psError(__func__, " : Line %d - Input image exceeds flat image in number of columns. (%d vs %d).", 59 inImage = in->image; 60 inMask = in->mask; 61 flatImage = flat->image; 62 if (inImage == NULL) { 63 psError(__func__, " : Line %d - Null not allowed for input image", __LINE__); 64 return false; 65 } else if(flatImage) { 66 psError(__func__, " : Line %d - Null not allowed for flat image", __LINE__); 67 return false; 68 } else if(inMask == NULL) { 69 inMask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK); 70 } 71 72 // Check input image and its mask are not larger than flat image 73 if(inImage->numRows > flatImage->numRows) { 74 psError(__func__, " : Line %d - Input image exceeds mask image in number of rows. (%d vs %d).", 75 __LINE__, inImage->numRows, flatImage->numRows); 76 return false; 77 } else if(inImage->numCols > flatImage->numCols) { 78 psError(__func__, " : Line %d - Input image exceeds mask image in number of columns. (%d vs %d).", 79 __LINE__, inImage->numCols, flatImage->numCols); 80 return false; 81 } else if(inMask->numRows > flatImage->numRows) { 82 psError(__func__, " : Line %d - Input image mask exceeds mask image in number of rows. (%d vs %d).", 83 __LINE__, inImage->numRows, flatImage->numRows); 84 return false; 85 } else if(inMask->numCols > flatImage->numCols) { 86 psError(__func__, " : Line %d - Input image mask exceeds mask image in number of columns. (%d vs %d).", 75 87 __LINE__, inImage->numCols, flatImage->numCols); 76 88 return false; 77 89 } 78 90 91 // Determine total offset based on image offset with chip offset 92 totOffCol = inImage->col0 + in->col0; 93 totOffRow = inImage->row0 + in->row0; 94 95 // Check that offsets are within image limits 79 96 if(totOffRow > flatImage->numRows-1) { 80 psError(__func__, " : Line %d - Initial row offset exceeds that of flatimage. (%d vs %d).",97 psError(__func__, " : Line %d - Initial row offset exceeds that of mask image. (%d vs %d).", 81 98 __LINE__, totOffRow, flatImage->numRows); 99 return false; 100 } else if(totOffCol > flatImage->numCols-1) { 101 psError(__func__, " : Line %d - Initial column offset exceeds that of mask image. (%d vs %d).", 102 __LINE__, totOffCol, flatImage->numCols); 103 return false; 104 } else if(totOffRow > inImage->numRows-1) { 105 psError(__func__, " : Line %d - Initial row offset exceeds that of input image. (%d vs %d).", 106 __LINE__, totOffRow, inImage->numRows); 107 return false; 108 } else if(totOffCol > inImage->numCols-1) { 109 psError(__func__, " : Line %d - Initial column offset exceeds that of input image. (%d vs %d).", 110 __LINE__, totOffCol, inImage->numCols); 111 return false; 112 } else if(totOffRow > inMask->numRows-1) { 113 psError(__func__, " : Line %d - Initial row offset exceeds that of input image mask. (%d vs %d).", 114 __LINE__, totOffRow, inMask->numRows); 115 return false; 116 } else if(totOffCol > inMask->numCols-1) { 117 psError(__func__, " : Line %d - Initial column offset exceeds that of input image mask. (%d vs %d).", 118 __LINE__, totOffCol, inMask->numCols); 82 119 return false; 83 120 } 84 121 85 if(totOffCol > flatImage->numCols-1) { 86 psError(__func__, " : Line %d - Initial column offset exceeds that of flat image. (%d vs %d).", 87 __LINE__, totOffCol, flatImage->numCols); 88 return false; 89 } 90 91 if(totOffRow > inImage->numRows-1) { 92 psError(__func__, " : Line %d - Initial row offset exceeds that of input image. (%d vs %d).", 93 __LINE__, totOffRow, inImage->numRows); 94 return false; 95 } 96 97 if(totOffCol > inImage->numCols-1) { 98 psError(__func__, " : Line %d - Initial column offset exceeds that of input image. (%d vs %d).", 99 __LINE__, totOffCol, inImage->numCols); 100 return false; 101 } 102 122 // Check for incorrect types 103 123 inType = inImage->type.type; 104 124 flatType = flatImage->type.type; 105 maskType = maskImage->type.type; 106 125 maskType = inMask->type.type; 107 126 if(PS_IS_PSELEMTYPE_COMPLEX(inType)) { 108 psError(__func__, " : Line %d - Complex types not allowed for input image", __LINE__); 127 psError(__func__, " : Line %d - Complex types not allowed for input image. Type: %d", __LINE__, 128 inType); 109 129 return false; 110 } 111 112 if(PS_IS_PSELEMTYPE_COMPLEX(flatType)) { 113 psError(__func__, " : Line %d - Complex types not allowedfor flat image", __LINE__); 130 } else if(PS_IS_PSELEMTYPE_COMPLEX(flatType)) { 131 psError(__func__, " : Line %d - Complex types not allowed for flat image. Type: %d", __LINE__, 132 flatType); 114 133 return false; 115 } 116 117 if(PS_IS_PSELEMTYPE_COMPLEX(maskType)) { 118 psError(__func__, " : Line %d - Complex types not allowed for mask image", __LINE__); 134 } else if(maskType != PS_TYPE_MASK) { 135 psError(__func__, " : Line %d - Mask must be PS_TYPE_MASK type. Type: %d", __LINE__, maskType); 119 136 return false; 120 } 121 122 if(PS_IS_PSELEMTYPE_REAL(maskType)) { 123 psError(__func__, " : Line %d - Floating point types not allowed for mask image", __LINE__); 124 return false; 125 } 126 127 if(inType != flatType) { 128 psError(__func__, " : Line %d - Input and flat image types don't agree. (%d vs %d).", 129 __LINE__, inType, flatType); 137 } else if(inType != flatType) { 138 psError(__func__, " : Line %d - Input and flat image types differ. (%d vs %d)", __LINE__, inType, 139 flatType); 130 140 return false; 131 141 } … … 133 143 // Macro for all PS types 134 144 #define PM_FLAT_DIVISION(TYPE) \ 135 case PS_TYPE_##TYPE: \145 case PS_TYPE_##TYPE: \ 136 146 /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */ \ 137 147 for(j = totOffRow; j < inImage->numRows; j++) { \ … … 139 149 if(flatImage->data.TYPE[j][i] <= 0.0) { \ 140 150 /* Negative or zero flat pixels shall be masked in input image as PM_MASK_FLAT */ \ 141 maskImage->data.F64[j][i] = PM_MASK_FLAT;\151 inMask->data.PS_TYPE_MASK_DATA[j][i] = PM_MASK_FLAT; \ 142 152 } \ 143 153 } \ … … 145 155 for(j = totOffRow; j < inImage->numRows; j++) { \ 146 156 for(i = totOffCol; i < inImage->numCols; i++) { \ 147 if(! maskImage->data.F64[j][i]) {\157 if(!inMask->data.PS_TYPE_MASK_DATA[j][i]) { \ 148 158 /* Module shall divide the input image by the flat-fielded image */ \ 149 159 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \ … … 165 175 PM_FLAT_DIVISION(F64); 166 176 default: 167 psError(__func__, "Unsupported image datatype (%d)", inType);177 psError(__func__, "Unsupported image datatype. Type: %d", inType); 168 178 } 169 179 170 return in;180 return true; 171 181 }
Note:
See TracChangeset
for help on using the changeset viewer.
