00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef IMG_NORMALIZER_IMPL_H
00028 #define IMG_NORMALIZER_IMPL_H
00029
00030 #include <boost/shared_ptr.hpp>
00031
00032 #include <ost/img/image_state.hh>
00033 #include <ost/img/value_util.hh>
00034 #include "normalizer_fw.hh"
00035 #include <ost/img/module_config.hh>
00036 namespace ost { namespace img {
00037
00039
00045 class DLLEXPORT_OST_IMG_BASE NormalizeFnc {
00046 public:
00047 virtual ~NormalizeFnc() {}
00048 template <typename T, class D>
00049 void VisitState(ImageStateImpl<T,D>& s) const {
00050
00051 for(T* ptr = s.Data().GetData(); ptr<s.Data().GetEnd(); ++ptr) {
00052 *ptr = static_cast<T>(Convert(*ptr));
00053 }
00054 }
00055
00056
00057 virtual Real BackConvert(Real v) const = 0;
00058 virtual Complex BackConvert(Complex v) const = 0;
00059 virtual Real Convert(Real v) const = 0;
00060 virtual Complex Convert(Complex v) const = 0;
00061
00062 static String GetAlgorithmName() {return "Normalizer";}
00063 };
00064
00066 typedef ImageStateConstModIPAlgorithm<NormalizeFnc> NormalizerBase;
00067
00069 class NormalizerImpl: public NormalizerBase{
00070 public:
00071 virtual NormalizerImpl* Clone() const =0;
00072 };
00073
00075 class DLLEXPORT_OST_IMG_BASE NoOpNormalizer: public NormalizerImpl {
00076 public:
00077
00078 virtual Real BackConvert(Real v) const {return v;}
00079 virtual Complex BackConvert(Complex v) const {return v;}
00080 virtual Real Convert(Real v) const {return v;}
00081 virtual Complex Convert(Complex v) const {return v;}
00082 virtual NormalizerImpl* Clone() const {return new NoOpNormalizer((*this));}
00083 };
00084
00086 class RangeHandler
00087 {
00088 public:
00089 RangeHandler():min_(),max_(){}
00090 RangeHandler(Real min,Real max):min_(min),max_(max){}
00091 Real GetMinimum() const{return min_;}
00092 Real GetMaximum() const{return max_;}
00093 protected:
00094 Real Clip(Real val) const{return ClipMinMax(val,min_,max_);}
00095 Complex Clip(Complex val) const{return ClipMinMax(val,min_,max_);}
00096 Real ClipMinMax(Real val,Real minval,Real maxval) const{return std::max<Real>(std::min<Real>(val,maxval),minval);}
00097 Complex ClipMinMax(Complex val,Real minval,Real maxval) const {
00098 return (val == Complex(0.0)? 1.0 : val/std::abs(val))*std::max<Real>(std::min<Real>(std::abs(val),maxval),minval);
00099 }
00100 private:
00101 Real min_;
00102 Real max_;
00103 };
00104
00105 }}
00106
00107 #endif