Changeset 9617
- Timestamp:
- Oct 17, 2006, 12:57:27 PM (20 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
-
pmNonLinear.c (modified) (5 diffs)
-
pmNonLinear.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmNonLinear.c
r8669 r9617 1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the3 // one that was being worked on.4 //////////////////////////////////////////////////////////////////////////////////////////////////////////////5 6 /** @file pmNonLinear.c7 *8 * Provides polynomial or table lookup non-linearity corrections to readouts.9 *10 * @author GLG, MHPCC11 *12 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $13 * @date $Date: 2006-08-29 21:39:44 $14 *15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii16 *17 * XXX: The SDR is silent about image types. Only F32 was implemented.18 *19 */20 21 1 #if HAVE_CONFIG_H 22 2 #include <config.h> … … 24 4 25 5 #include <stdio.h> 26 #include <math.h>27 6 #include <pslib.h> 28 7 8 #include "pmFPA.h" 29 9 #include "pmNonLinear.h" 30 10 31 /****************************************************************************** 32 pmNonLinearityLookup(): This routine will take an pmReadout image as input 33 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 to 35 that value. 36 *****************************************************************************/ 37 38 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, 39 const psPolynomial1D *input1DPoly) 11 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, const psPolynomial1D *input1DPoly) 40 12 { 41 13 PS_ASSERT_PTR_NON_NULL(inputReadout, NULL); … … 44 16 PS_ASSERT_PTR_NON_NULL(input1DPoly, NULL); 45 17 46 psS32 i; 47 psS32 j; 48 49 for (i=0;i<inputReadout->image->numRows;i++) { 50 for (j=0;j<inputReadout->image->numCols;j++) { 51 inputReadout->image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, inputReadout->image->data.F32[i][j]); 18 psImage *image = inputReadout->image; // Image to correct 19 for (int i = 0; i < image->numRows; i++) { 20 for (int j = 0; j < image->numCols; j++) { 21 image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, image->data.F32[i][j]); 52 22 } 53 23 } 54 return (inputReadout);24 return inputReadout; 55 25 } 56 26 57 27 58 /****************************************************************************** 59 pmNonLinearityLookup(): This routine will take an pmReadout image as input 60 and two input vectors, which constitute a lookup table. For each pixel in 61 the input image, that pixels value will be determined in the input vector 62 inFluxe, and the corresponding value in outFlux. The image pixel will then 63 be set to the value from outFlux. 64 *****************************************************************************/ 65 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, 66 const psVector *inFlux, 67 const psVector *outFlux) 28 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, const psVector *inFlux, const psVector *outFlux) 68 29 { 69 PS_ASSERT_PTR_NON_NULL(inputReadout, NULL);70 PS_ASSERT_PTR_NON_NULL(inputReadout->image, NULL);30 PS_ASSERT_PTR_NON_NULL(inputReadout, NULL); 31 PS_ASSERT_PTR_NON_NULL(inputReadout->image, NULL); 71 32 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 72 PS_ASSERT_PTR_NON_NULL(inFlux, NULL);33 PS_ASSERT_PTR_NON_NULL(inFlux, NULL); 73 34 if (inFlux->n < 2) { 74 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements. Returning inputReadout image."); 35 psError(PS_ERR_UNKNOWN, true, 36 "pmNonLinearityLookup(): input vector less than 2 elements. Returning inputReadout image."); 75 37 return(inputReadout); 76 38 } … … 80 42 tableSize = PS_MIN(inFlux->n, outFlux->n); 81 43 psLogMsg(__func__, PS_LOG_WARN, 82 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%ld, %ld)\n", inFlux->n, outFlux->n); 44 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): " 45 "input vectors have different sizes (%ld, %ld)\n", 46 inFlux->n, outFlux->n); 83 47 } 84 48 PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL); 85 49 PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL); 86 50 87 psS32 i; 88 psS32 j; 89 psS32 binNum; 90 psScalar x; 91 psS32 numPixels = 0; 92 psF32 slope; 51 psImage *image = inputReadout->image; // Input image 52 psScalar x; // Value at pixel, for p_psVectorBinDisect 53 x.type.type = PS_TYPE_F32; 54 int numPixels = 0; // Number of pixels outside the range 93 55 94 x.type.type = PS_TYPE_F32; 95 for (i=0;i<inputReadout->image->numRows;i++) { 96 for (j=0;j<inputReadout->image->numCols;j++) { 97 x.data.F32 = inputReadout->image->data.F32[i][j]; 98 binNum = p_psVectorBinDisect((psVector *)inFlux, &x); 56 for (int i = 0; i < image->numRows; i++) { 57 for (int j = 0; j < image->numCols; j++) { 58 x.data.F32 = image->data.F32[i][j]; 59 int binNum = p_psVectorBinDisect((psVector *)inFlux, &x); // Bin below the value 99 60 100 61 if (binNum == -2) { 101 62 // We get here if x is below the table lookup range. 102 i nputReadout->image->data.F32[i][j] = outFlux->data.F32[0];63 image->data.F32[i][j] = outFlux->data.F32[0]; 103 64 numPixels++; 104 105 65 } else if (binNum == -1) { 106 66 // We get here if x is above the table lookup range. 107 i nputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1];67 image->data.F32[i][j] = outFlux->data.F32[tableSize-1]; 108 68 numPixels++; 109 110 69 } else if (binNum < -2) { 111 70 // We get here if there was some other problem. 112 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect(). Returning inputReadout image."); 113 return(inputReadout); 71 psError(PS_ERR_UNKNOWN, true, 72 "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect(). " 73 "Returning inputReadout image."); 74 return inputReadout; 114 75 numPixels++; 115 76 } else { 116 77 // Perform linear interpolation. 117 slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) /118 (inFlux->data.F32[binNum+1]- inFlux->data.F32[binNum]);119 i nputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] +120 ((x.data.F32 - inFlux->data.F32[binNum]) * slope);78 float slope = (outFlux->data.F32[binNum + 1] - outFlux->data.F32[binNum]) / 79 (inFlux->data.F32[binNum + 1] - inFlux->data.F32[binNum]); 80 image->data.F32[i][j] = outFlux->data.F32[binNum] + 81 (x.data.F32 - inFlux->data.F32[binNum]) * slope; 121 82 } 122 83 } … … 126 87 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels); 127 88 } 128 return (inputReadout);89 return inputReadout; 129 90 } -
trunk/psModules/src/detrend/pmNonLinear.h
r6872 r9617 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 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1 /// @file pmNonLinear.h 2 /// 3 /// @brief Perform non-linear correction through polynomial or table lookup 4 /// 5 /// @ingroup Detrend 6 /// 7 /// @author George Gusciora, MHPCC 8 /// @author Paul Price, IfA 9 /// 10 /// @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 11 /// @date $Date: 2006-10-17 22:57:27 $ 12 /// 13 /// Copyright 2004 Institute for Astronomy, University of Hawaii 14 /// 5 15 6 /** @file pmNonLinear.h 7 * 8 * Provides polynomial or table lookup non-linearity corrections to readouts. 9 * 10 * @author GLG, MHPCC 11 * 12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 14 * 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 * 17 */ 18 19 #if !defined(PM_NON_LINEAR_H) 16 #ifndef PM_NON_LINEAR_H 20 17 #define PM_NON_LINEAR_H 21 18 22 #include "pslib.h"19 #include <pslib.h> 23 20 #include "pmFPA.h" 24 21 25 pmReadout *pmNonLinearityPolynomial(pmReadout *in, 26 const psPolynomial1D *coeff); 22 /// Correct non-linearity through polynomial 23 /// 24 /// Applies a polynomial to the flux of each pixel in the input image to determine the corrected flux. 25 pmReadout *pmNonLinearityPolynomial(pmReadout *in, ///< Input image, to correct 26 const psPolynomial1D *coeff ///< Polynomial for non-linearity correction 27 ); 27 28 28 pmReadout *pmNonLinearityLookup(pmReadout *in, 29 const psVector *inFlux, 30 const psVector *outFlux); 29 /// Correct non-linearity through table lookup 30 /// 31 /// For each pixel in the input image, performs linear interpolation on the table (from the two vectors) to 32 /// determine the corrected flux. 33 pmReadout *pmNonLinearityLookup(pmReadout *in, ///< Input image, to correct 34 const psVector *inFlux, ///< Table column with input fluxes 35 const psVector *outFlux ///< Table column with output fluxes 36 ); 31 37 32 38 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
