25 #ifndef CLIP_MIN_MAX_HH_
26 #define CLIP_MIN_MAX_HH_
28 namespace ost {
namespace img {
namespace alg {
39 bool cbigger<Complex>(
Complex& v,
Real rv,
const Complex& cv) {
return std::abs(v)>=std::abs(cv);}
44 return static_cast<Real>(v)>=rv;
53 T get_t(
Real rv,
const Complex& cv){
return static_cast<T
>(rv);}
55 struct ClipMinMaxFnc {
56 explicit ClipMinMaxFnc() { set_rl(0.0); set_ru(1.0); }
57 explicit ClipMinMaxFnc(
Real l,
Real u) {set_rl(l);set_ru(u);}
58 explicit ClipMinMaxFnc(
const Complex& l,
const Complex& u) {set_cl(l);set_cu(u);}
60 void SetThresholds(
Real l,
Real u) {set_rl(l);set_ru(u);}
61 void SetThresholds(
const Complex& l,
const Complex& u) {set_cl(l);set_cu(u);}
63 template <
typename T,
class D>
64 void VisitState(ImageStateImpl<T,D>& isi)
const {
65 for(T* p = isi.Data().GetData(); p<isi.Data().GetEnd();++p) {
66 (*p)= cbigger<T>(*p,r_tl_,c_tl_)? (cbigger<T>(*p,r_tu_,c_tu_)? get_t<T>(r_tu_,c_tu_) :(*p)) :get_t<T>(r_tl_,c_tl_) ;
70 static String GetAlgorithmName() {
return "ClipMinMax";}
78 void set_rl(
Real f) {r_tl_=f; c_tl_=Val2Val<Real,Complex>(f);}
79 void set_ru(
Real f) {r_tu_=f; c_tu_=Val2Val<Real,Complex>(f);}
in-place modifying image state const visitor plus ip algorithm
std::complex< Real > Complex
ImageStateConstModIPAlgorithm< ClipMinMaxFnc > ClipMinMax
Real Val2Val< Complex, Real >(const Complex &c)