21 #ifndef GR_HISTOGRAM__H
22 #define GR_HISTOGRAM__H
44 typedef unsigned long sum_type ;
45 typedef unsigned char value_type ;
47 G_STATIC_ASSERT(
sizeof(value_type) == 1 ) ;
59 void add( value_type ) ;
67 value_type
map( value_type )
const ;
74 typedef std::vector<sum_type> Vector ;
78 template <
typename TValue,
typename TSum>
81 typedef TValue value_type ;
82 typedef TSum sum_type ;
84 Accumulator( sum_type & n_ ) : n(n_) {}
85 void operator()( sum_type & v ) { n += v ; v = n ; }
87 template <
typename TValue,
typename TSum>
90 typedef TValue value_type ;
91 typedef TSum sum_type ;
94 Scaler( value_type min_ , sum_type total_ ) : min(min_) , divisor(total_-min_) {}
95 void operator()( sum_type & v )
97 const sum_type n = ( v - min ) * ( N - 1 ) ;
98 v = (value_type)( n / divisor ) ;
125 m_data.assign( N , 0 ) ;
131 const Vector::iterator end = m_data.end() ;
132 Vector::iterator min_p = std::find_if( m_data.begin() , end , std::bind2nd(std::not_equal_to<value_type>(),0) ) ;
133 if( min_p == end ) return ;
135 std::for_each( m_data.begin() , end , Accumulator<value_type,sum_type>(n) ) ;
136 std::for_each( m_data.begin() , end , Scaler<value_type,sum_type>(*min_p,m_data.back()) ) ;
148 return !m_data.empty() ;
void compute()
Computes the equalisation map once all the pixels have been add()ed.
A class that does histogram equalisation for eight-bit samples.
void add(value_type)
Adds a pixel to the histogram.
void clear()
Clears the map.
bool active() const
Returns true if constructed as active.
value_type map(value_type) const
Does the equalisation mapping.