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 #include <ost/img/image_state.hh>
00026 #include <ost/img/alg/module_config.hh>
00027
00028 namespace ost { namespace img { namespace alg {
00029
00030 namespace {
00031
00032 template<typename T>
00033 bool bigger(T& v, Real rv, const Complex& cv);
00034
00035 template<>
00036 bool bigger<Real>(Real& v, Real rv, const Complex& cv) {return v>=rv;}
00037
00038 template<>
00039 bool bigger<Complex>(Complex& v, Real rv, const Complex& cv) {return std::abs(v)>=std::abs(cv);}
00040
00041 template<typename T>
00042 bool bigger(T& v, Real rv, const Complex& cv)
00043 {
00044 return static_cast<Real>(v)>=rv;
00045 }
00046
00047 struct ThresholdFnc {
00048 explicit ThresholdFnc(): r_fv_(0.0) { set_rval(0.0); }
00049 explicit ThresholdFnc(Real f) {set_rval(f);}
00050 explicit ThresholdFnc(const Complex& f) {set_cval(f);}
00051
00052 void SetThreshold(Real f) {set_rval(f);}
00053 void SetThreshold(const Complex& f) {set_cval(f);}
00054
00055 template <typename T, class D>
00056 void VisitState(ImageStateImpl<T,D>& isi) const {
00057 static const T zero=T();
00058 static const T one=T(1);
00059 for(T* p = isi.Data().GetData(); p<isi.Data().GetEnd();++p) {
00060 (*p)= bigger<T>(*p,r_fv_,c_fv_)? one : zero ;
00061 }
00062 }
00063
00064 static String GetAlgorithmName() {return "Threshold";}
00065
00066 private:
00067 Real r_fv_;
00068 Complex c_fv_;
00069
00070 void set_rval(Real f) {r_fv_=f; c_fv_=Val2Val<Real,Complex>(f);}
00071 void set_cval(const Complex& f) {c_fv_=f; r_fv_=Val2Val<Complex,Real>(f);}
00072 };
00073
00074 }
00075
00076 typedef ImageStateConstModIPAlgorithm<ThresholdFnc> Threshold;
00077
00078 }
00079
00080 OST_IMG_ALG_EXPLICIT_INST_DECL(class, ImageStateModIPAlgorithm<alg::ThresholdFnc>)
00081
00082
00083 }}
00084
00085