1 /* 2 * imagesource_modifiedgamma.h 3 * Applies Gamma correction to an image - but uses a modified gamma curve 4 * with a linear segment to avoid problems with infinite gradient at 0. 5 * 6 * The modified gamma curve is: 7 * Y = pow((X+offset)/(1.0+offset),gamma) if X > threshold 8 * and Y = K * X otherwise. 9 * 10 * offset is -0.02 by default 11 * 12 * Threshold is automatically calculated as the point at which the line segment 13 * has the same gradient as the gamma curve, which turns out to be 14 * offset / (gamma + offset*gamma - 1.0) 15 * 16 * 17 * Copyright (c) 2009 by Alastair M. Robinson 18 * Distributed under the terms of the GNU General Public License - 19 * see the file named "COPYING" for more details. 20 * 21 */ 22 23 #ifndef IMAGESOURCE_MODIFIEDGAMMA_H 24 #define IMAGESOURCE_MODIFIEDGAMMA_H 25 26 #include "imagesource.h" 27 #include "lcmswrapper.h" 28 29 30 class ImageSource_ModifiedGamma : public ImageSource 31 { 32 public: 33 ImageSource_ModifiedGamma(ImageSource *source,double gamma,double offset=-0.02); 34 virtual ~ImageSource_ModifiedGamma(); 35 ISDataType *GetRow(int row); 36 static double FindGamma(double x,double y,double offset=-0.02); 37 static double ModifiedGamma(double x,double gamma,double offset=-0.02); 38 static double InverseModifiedGamma(double x, double gamma, double offset=-0.02); 39 private: 40 ImageSource *source; 41 double gamma; 42 double offset; 43 double threshold; 44 double slope; 45 }; 46 47 #endif 48