degate  0.1.2
Public Member Functions | Protected Member Functions | Private Types | Private Attributes
degate::ImageHistogram< KeyType, ValueType > Class Template Reference

#include <ImageHistogram.h>

Inheritance diagram for degate::ImageHistogram< KeyType, ValueType >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ImageHistogram (double _from, double _to, double _class_width)
virtual ~ImageHistogram ()
virtual void add (KeyType k)
virtual ValueType get (KeyType k) const
virtual ValueType get_for_rgb (rgba_pixel_t) const =0
virtual void save_histogram (std::string const &path) const

Protected Member Functions

void check_bounding_box (BoundingBox const &bb, ImageBase_shptr img) const
KeyType to_class (ValueType v, ValueType from, ValueType to, ValueType class_width) const

Private Types

typedef std::map< KeyType,
ValueType > 
map_type

Private Attributes

map_type histogram
unsigned int counts
double from
double to
double class_width

Detailed Description

template<typename KeyType, typename ValueType>
class degate::ImageHistogram< KeyType, ValueType >

Definition at line 37 of file ImageHistogram.h.


Member Typedef Documentation

template<typename KeyType, typename ValueType>
typedef std::map<KeyType, ValueType> degate::ImageHistogram< KeyType, ValueType >::map_type [private]

Definition at line 40 of file ImageHistogram.h.


Constructor & Destructor Documentation

template<typename KeyType, typename ValueType>
degate::ImageHistogram< KeyType, ValueType >::ImageHistogram ( double  _from,
double  _to,
double  _class_width 
) [inline]

Definition at line 78 of file ImageHistogram.h.

                                                                  :
      counts(0),
      from(_from),
      to(_to),
      class_width(_class_width) {}
template<typename KeyType, typename ValueType>
virtual degate::ImageHistogram< KeyType, ValueType >::~ImageHistogram ( ) [inline, virtual]

Definition at line 84 of file ImageHistogram.h.

{}

Member Function Documentation

template<typename KeyType, typename ValueType>
virtual void degate::ImageHistogram< KeyType, ValueType >::add ( KeyType  k) [inline, virtual]

Definition at line 86 of file ImageHistogram.h.

                                {
      histogram[to_class(k, from, to, class_width)] += 1;
      counts++;
    }
template<typename KeyType, typename ValueType>
void degate::ImageHistogram< KeyType, ValueType >::check_bounding_box ( BoundingBox const &  bb,
ImageBase_shptr  img 
) const [inline, protected]

Definition at line 48 of file ImageHistogram.h.

                                                                              {

      if(std::max(bb.get_min_x(), bb.get_max_x()) >= (int)img->get_width() ||
         std::max(bb.get_min_y(), bb.get_max_y()) >= (int)img->get_height() ||
         std::min(bb.get_min_x(), bb.get_max_x()) < 0 ||
         std::min(bb.get_min_y(), bb.get_max_y()) < 0) {
        boost::format f("Error in add_area(). Defined region %1% is beyond image boundary.");
        f % bb.to_string();
        throw DegateRuntimeException(f.str());
      }

      if(bb.get_height() == 0 && bb.get_width() == 0)
        throw DegateRuntimeException("Bounding box has zero size");
    }
template<typename KeyType, typename ValueType>
virtual ValueType degate::ImageHistogram< KeyType, ValueType >::get ( KeyType  k) const [inline, virtual]

Definition at line 91 of file ImageHistogram.h.

                                           {
      if(counts == 0) return 0;

      else {
        typename map_type::const_iterator found = histogram.find(to_class(k, from, to, class_width));
        if(found == histogram.end()) return 0;
        else return (*found).second / (double)counts;
      }
    }
template<typename KeyType, typename ValueType>
virtual ValueType degate::ImageHistogram< KeyType, ValueType >::get_for_rgb ( rgba_pixel_t  ) const [pure virtual]
template<typename KeyType, typename ValueType>
virtual void degate::ImageHistogram< KeyType, ValueType >::save_histogram ( std::string const &  path) const [inline, virtual]

Definition at line 103 of file ImageHistogram.h.

                                                             {

      std::ofstream histogram_file;
      histogram_file.open(path.c_str());

      if(counts > 0)
        for(typename map_type::const_iterator iter = histogram.begin(); iter != histogram.end(); ++iter) {
          double frequency = (*iter).second / (double)counts;
          histogram_file << (*iter).first << " " << frequency << std::endl;
        }

      histogram_file.close();
    }
template<typename KeyType, typename ValueType>
KeyType degate::ImageHistogram< KeyType, ValueType >::to_class ( ValueType  v,
ValueType  from,
ValueType  to,
ValueType  class_width 
) const [inline, protected]

Definition at line 63 of file ImageHistogram.h.

Referenced by degate::ImageHistogram< double, double >::add(), and degate::ImageHistogram< double, double >::get().

                                                                                             {
      //unsigned int classes = (to - from) / class_width;
      //unsigned int class_num = v / class_width;
      //KeyType cl = v * class_width;

      unsigned int c = 0;
      for(ValueType i = from; i < to; i+= class_width, c++) {
        if(v >= (ValueType)c*class_width && v < (ValueType)(c+1)*class_width)
          return (ValueType)c*class_width;
      }

    }

Here is the caller graph for this function:


Member Data Documentation

template<typename KeyType, typename ValueType>
double degate::ImageHistogram< KeyType, ValueType >::class_width [private]
template<typename KeyType, typename ValueType>
unsigned int degate::ImageHistogram< KeyType, ValueType >::counts [private]
template<typename KeyType, typename ValueType>
double degate::ImageHistogram< KeyType, ValueType >::from [private]
template<typename KeyType, typename ValueType>
map_type degate::ImageHistogram< KeyType, ValueType >::histogram [private]
template<typename KeyType, typename ValueType>
double degate::ImageHistogram< KeyType, ValueType >::to [private]

The documentation for this class was generated from the following file: