Changeset 12456
- Timestamp:
- Mar 15, 2007, 2:32:06 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmNonLinear.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmNonLinear.c
r9617 r12456 25 25 } 26 26 27 // set the bin closest to the corresponding value. 28 #define PS_BIN_FOR_VALUE(RESULT, VECTOR, VALUE) { \ 29 psVectorBinaryDisectResult result; \ 30 psScalar tmpScalar; \ 31 tmpScalar.type.type = PS_TYPE_F32; \ 32 tmpScalar.data.F32 = (VALUE); \ 33 RESULT = psVectorBinaryDisect (&result, VECTOR, &tmpScalar); \ 34 switch (result) { \ 35 case PS_BINARY_DISECT_PASS: \ 36 break; \ 37 case PS_BINARY_DISECT_OUTSIDE_RANGE: \ 38 numPixels ++; \ 39 break; \ 40 case PS_BINARY_DISECT_INVALID_INPUT: \ 41 case PS_BINARY_DISECT_INVALID_TYPE: \ 42 psAbort ("programming error"); \ 43 break; \ 44 } } 27 45 28 46 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, const psVector *inFlux, const psVector *outFlux) … … 50 68 51 69 psImage *image = inputReadout->image; // Input image 52 psScalar x; // Value at pixel, for p_psVectorBinDisect53 x.type.type = PS_TYPE_F32;54 70 int numPixels = 0; // Number of pixels outside the range 71 int binNum; 55 72 56 73 for (int i = 0; i < image->numRows; i++) { 57 74 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 value75 float value = image->data.F32[i][j]; 76 PS_BIN_FOR_VALUE(binNum, inFlux, value); 60 77 61 if (binNum == -2) { 62 // We get here if x is below the table lookup range. 63 image->data.F32[i][j] = outFlux->data.F32[0]; 64 numPixels++; 65 } else if (binNum == -1) { 66 // We get here if x is above the table lookup range. 67 image->data.F32[i][j] = outFlux->data.F32[tableSize-1]; 68 numPixels++; 69 } else if (binNum < -2) { 70 // We get here if there was some other problem. 71 psError(PS_ERR_UNKNOWN, true, 72 "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect(). " 73 "Returning inputReadout image."); 74 return inputReadout; 75 numPixels++; 76 } else { 77 // Perform linear interpolation. 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; 82 } 78 // Perform linear interpolation. 79 // XXX this will result in non-sensical results if inFlux contains equal-value 80 // bins. either enforce d(inFlux)/d(binNum) > 0 or see psStats.c PS_BIN_INTERPOLATE 81 float slope = 82 (outFlux->data.F32[binNum + 1] - outFlux->data.F32[binNum]) / 83 (inFlux->data.F32[binNum + 1] - inFlux->data.F32[binNum]); 84 image->data.F32[i][j] = slope*(value - inFlux->data.F32[binNum]) + outFlux->data.F32[binNum]; 83 85 } 84 86 }
Note:
See TracChangeset
for help on using the changeset viewer.
