Changeset 1802 for trunk/psModules/src/pmFlatField.c
- Timestamp:
- Sep 13, 2004, 4:29:40 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/pmFlatField.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmFlatField.c
r1786 r1802 1 /** @file pmFlatField.c 1 /** @file pmFlatField.cS 2 2 * 3 * @brief Contains the definitions for ...3 * @brief Given an input image and a flat-field image, pmFlatField shall divide the input image by the flat-field image. 4 4 * 5 * @author Robert DeSonia, MHPCC 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 14 * 7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2004-09-10 23:42:18 $ 15 * @author Ross Harman, MHPCC 16 * 17 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2004-09-14 02:29:27 $ 9 19 * 10 20 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 26 17 27 #include<stdio.h> 28 #include<math.h> 18 29 19 30 #include "pmFlatField.h" 20 31 21 void pmFlatField(psVector* vector) 32 33 #define CHECK_NULL(STRUCT) \ 34 if (STRUCT == NULL) { \ 35 psAbort(__func__, " : Line %d - Null not allowed for %s", __LINE__, #STRUCT); \ 36 } \ 37 38 psReadout *pmFlatField(psReadout *in, psReadout *inMask, const psReadout *flat, const psReadout *flatMask) 22 39 { 23 if (vector == NULL) { 24 printf("Nothing to see here... move along.\n"); 25 return; 40 int i = 0; 41 int j = 0; 42 psElemType inType; 43 psElemType flatType; 44 psImage *inImage = NULL; 45 psImage *flatImage = NULL; 46 psImage *inMaskImage = NULL; 47 psImage *flatMaskImage = NULL; 48 49 CHECK_NULL(in); 50 CHECK_NULL(flat); 51 CHECK_NULL(inMask); 52 CHECK_NULL(flatMask); 53 54 inImage = in->image; 55 flatImage = flat->image; 56 inMaskImage = inMask->image; 57 flatMaskImage = flatMask->image; 58 59 CHECK_NULL(inImage); 60 CHECK_NULL(flatImage); 61 CHECK_NULL(inMaskImage); 62 CHECK_NULL(flatMaskImage); 63 64 if(inImage->numRows > flatImage->numRows) { 65 psError(__func__, " : Line %d - Input image exceeds flat image in number of rows. (%d vs %d).", 66 __LINE__, inImage->numRows, flatImage->numRows); 67 return NULL; 26 68 } 27 69 28 for (int lcv=0;lcv<vector->n;lcv++) { 29 printf("%f\n",vector->data.F32[lcv]); 70 if(inImage->numCols > flatImage->numCols) { 71 psError(__func__, " : Line %d - Input image exceeds flat image in number of columns. (%d vs %d).", 72 __LINE__, inImage->numCols, flatImage->numCols); 73 return NULL; 30 74 } 31 75 32 return; 76 if(inImage->row0 > flatImage->numRows-1) { 77 psError(__func__, " : Line %d - Input image row offset exceeds number of flat image rows. (%d vs %d).", 78 __LINE__, inImage->row0, flatImage->numRows); 79 return NULL; 80 } 33 81 82 if(inImage->col0 > flatImage->numCols-1) { 83 psError(__func__, " : Line %d - Input image column offset exceeds number of flat image columns. (%d vs %d).", 84 __LINE__, inImage->col0, flatImage->numCols); 85 return NULL; 86 } 87 88 inType = in->image->type.type; 89 flatType = flat->image->type.type; 90 if(inType != flatType) { 91 psError(__func__, " : Line %d - Input and flat image types don't agree. (%d vs %d).", 92 __LINE__, inType, flatType); 93 return NULL; 94 } 95 96 // Macro for all PS types 97 #define PM_FLAT_DIVISION(TYPE) \ 98 case PS_TYPE_##TYPE: \ 99 for(j = inImage->row0; j < inImage->numRows; j++) { \ 100 for(i = inImage->col0; i < inImage->numCols; i++) { \ 101 if(creal(flatImage->data.TYPE[j][i]) <= 0.0) { \ 102 /* Negative or zero flat pixels shall be masked in input image as PM_MASK_FLAT */ \ 103 inMaskImage->data.F64[j][i] = PM_MASK_FLAT; \ 104 } else if(flatMaskImage->data.TYPE[j][i]){ \ 105 /* Pixels masked in the flat shall be masked with same values in the output */ \ 106 inMaskImage->data.TYPE[j][i] = flatMaskImage->data.TYPE[j][i]; \ 107 } \ 108 if(creal(flatImage->data.TYPE[j][i]) < 0.0) { \ 109 /* Negative pixels in the flat may be set to zero */ \ 110 inImage->data.TYPE[j][i] = 0; \ 111 } else if(fabs(flatImage->data.TYPE[j][i]) < FLT_EPSILON) { \ 112 psError(__func__, " : Line %d - Divide by zero. Row: %d Col: %d",__LINE__, j, i); \ 113 } else { \ 114 /* Module shall divide the input image by the flat-fielded image */ \ 115 inImage->data.TYPE[j][i] = inImage->data.TYPE[j][i]/flatImage->data.TYPE[j][i]; \ 116 } \ 117 } \ 118 } \ 119 break; 120 121 switch(inType) { 122 PM_FLAT_DIVISION(U8); 123 PM_FLAT_DIVISION(U16); 124 PM_FLAT_DIVISION(U32); 125 PM_FLAT_DIVISION(U64); 126 PM_FLAT_DIVISION(S8); 127 PM_FLAT_DIVISION(S16); 128 PM_FLAT_DIVISION(S32); 129 PM_FLAT_DIVISION(S64); 130 PM_FLAT_DIVISION(F32); 131 PM_FLAT_DIVISION(F64); 132 PM_FLAT_DIVISION(C32); 133 PM_FLAT_DIVISION(C64); 134 default: 135 psError(__func__, "Unsupported image datatype (%d)", inType); 136 } 137 138 return in; 34 139 }
Note:
See TracChangeset
for help on using the changeset viewer.
