Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qgar::Histogram Class Reference
[Histograms]

#include <qgarlib/Histogram.H>

List of all members.


Detailed Description

General representation of a histogram.

A histogram records frequencies of samples in a vector of cells. A sample is a value in the range [ lowerBnd, upperBnd ]. Bounds may be negative. A cell records the frequency of samples included in [ sample, sample + samplingRate [; the default sampling rate is 1. For example, the cell at the lower bound records the frequency of samples in [ lowerBnd, lowerBnd + samplingRate [.

Warning:
Frequencies may be negative. Function qgar::Histogram::minus, that decrements a frequency, does not perform any check about the value of the resulting frequency.
Author:
Gérald Masini, from previous work by karl Tombre
Date:
December 5, 2003 14:58
Since:
Qgar 2.1.1

Definition at line 87 of file Histogram.H.

Public Member Functions

Constructors
 Histogram ()
 Default constructor.
 Histogram (const Histogram &aHistg)
 Copy constructor.
 Histogram (int aLowerBnd, int anUpperBnd, unsigned int aSampRate=1) throw (QgarErrorDomain)
 Construct from lower and upper bounds, and a sampling rate.
 Histogram (const GreyLevelImage &anImg, int aLowerBnd=0, int anUpperBnd=255, unsigned int aSampRate=1) throw (QgarErrorDomain)
 Construct from a grey-level image.
Destructor
virtual ~Histogram ()
 Virtual destructor.
Access
int lowerBnd () const
 Get lower bound.
int upperBnd () const
 Get upper bound.
int samplingRate () const
 Get cell width.
Frequencies
void plus (int aSample, unsigned int anIncr=1)
 Add a given value (default 1) to the frequency of a sample.
void minus (int aSample, unsigned int aDecr=1)
 Subtract a given value (default 1) to the frequency of a sample.
int maxSample ()
 Get sample with maximum frequency.
int maxSample (int aBnd)
 Get sample with maximum frequency in [aBnd, upperBnd].
int minSample ()
 Get sample with minimum frequency.
int minSample (int aBnd)
 Get sample with minimum frequency in [aBnd, upperBnd].
Operators
int & operator[] (int aSample) throw (QgarErrorDomain)
 Return the frequency of a sample.
Histogramoperator= (const Histogram &aHistg)
 Assignment.
Histogram transformations
void partialSum ()
 Transform into an accumulated histogram.
void smooth (unsigned int aWidth) throw (QgarErrorDomain)
 Smooth by computing a simple average on a window of given size.

Protected Attributes

Representation of a histogram
int _samplingRate
 Sampling rate.
int _lowerBnd
 Lower (non-sampled) bound.
int _upperBnd
 Upper (non-sampled) bound.
std::vector< int > _cells
 Vector of cells.

Private Member Functions

Access to the cell vector
int sampIdx (int aSample) const throw (QgarErrorDomain)
 Index (in the cell vector) corresponding to a sample.


Constructor & Destructor Documentation

qgar::Histogram::Histogram  ) 
 

Default constructor.

Sampling rate is set to 1, lower and upper bounds to 0, and the vector of cells is empty.

Definition at line 63 of file Histogram.C.

qgar::Histogram::Histogram const Histogram aHistg  ) 
 

Copy constructor.

Parameters:
aHistg a histogram

Definition at line 76 of file Histogram.C.

qgar::Histogram::Histogram int  aLowerBnd,
int  anUpperBnd,
unsigned int  aSampRate = 1
throw (QgarErrorDomain)
 

Construct from lower and upper bounds, and a sampling rate.

All cells are set to 0.

Parameters:
aLowerBnd lower bound
anUpperBnd upper bound
aSampRate sampling rate, i.e. cell width (default 1)
Exceptions:
qgar::QgarErrorDomain (sampling rate is 0; lower bound greater than upper bound)

Definition at line 90 of file Histogram.C.

qgar::Histogram::Histogram const GreyLevelImage anImg,
int  aLowerBnd = 0,
int  anUpperBnd = 255,
unsigned int  aSampRate = 1
throw (QgarErrorDomain)
 

Construct from a grey-level image.

Parameters:
anImg a grey-level image
aLowerBnd lower bound (default 0)
anUpperBnd upper bound (default 255)
aSampRate sampling rate, i.e. cell width (default 1)
Exceptions:
qgar::QgarErrorDomain (sampling rate is 0; lower bound greater than upper bound)

Definition at line 132 of file Histogram.C.

qgar::Histogram::~Histogram  )  [virtual]
 

Virtual destructor.

Definition at line 192 of file Histogram.C.


Member Function Documentation

int qgar::Histogram::lowerBnd  )  const [inline]
 

Get lower bound.

Definition at line 367 of file Histogram.H.

References _lowerBnd.

Referenced by qgar::MapleFile::MapleFile().

int qgar::Histogram::maxSample int  aBnd  ) 
 

Get sample with maximum frequency in [aBnd, upperBnd].

If several samples have the same (maximum) frequency, return the first sample starting from aBnd.

Parameters:
aBnd lower bound to start the search

Definition at line 218 of file Histogram.C.

References _cells, _lowerBnd, and _samplingRate.

int qgar::Histogram::maxSample  ) 
 

Get sample with maximum frequency.

If several samples have the same (maximum) frequency, return the first sample starting from the lower bound.

Definition at line 208 of file Histogram.C.

References _cells, _lowerBnd, and _samplingRate.

int qgar::Histogram::minSample int  aBnd  ) 
 

Get sample with minimum frequency in [aBnd, upperBnd].

If several samples have the same (minimum) frequency, return the first sample starting from aBnd.

Parameters:
aBnd lower bound to start the search

Definition at line 241 of file Histogram.C.

References _cells, _lowerBnd, and _samplingRate.

int qgar::Histogram::minSample  ) 
 

Get sample with minimum frequency.

If several samples have the same (minimum) frequency, return the first sample starting from the lower bound.

Definition at line 231 of file Histogram.C.

References _cells, _lowerBnd, and _samplingRate.

void qgar::Histogram::minus int  aSample,
unsigned int  aDecr = 1
 

Subtract a given value (default 1) to the frequency of a sample.

Parameters:
aSample a sample
aDecr value to be subtracted to the corresponding frequency
Warning:
The corresponding frequency may become negative: The function does not perfom any check about the value of the frequency after the subtraction.

Definition at line 359 of file Histogram.C.

References _cells, and sampIdx().

Histogram & qgar::Histogram::operator= const Histogram aHistg  ) 
 

Assignment.

Parameters:
aHistg a histogram

Definition at line 261 of file Histogram.C.

References _cells, _lowerBnd, _samplingRate, and _upperBnd.

int & qgar::Histogram::operator[] int  aSample  )  throw (QgarErrorDomain) [inline]
 

Return the frequency of a sample.

Parameters:
aSample a sample
Exceptions:
qgar::QgarErrorDomain (sample out of bounds)

Definition at line 398 of file Histogram.H.

void qgar::Histogram::partialSum  )  [inline]
 

Transform into an accumulated histogram.

Definition at line 415 of file Histogram.H.

References _cells.

void qgar::Histogram::plus int  aSample,
unsigned int  anIncr = 1
 

Add a given value (default 1) to the frequency of a sample.

Parameters:
aSample a sample
anIncr value to be added to the corresponding frequency

Definition at line 350 of file Histogram.C.

References _cells, and sampIdx().

int qgar::Histogram::sampIdx int  aSample  )  const throw (QgarErrorDomain) [private]
 

Index (in the cell vector) corresponding to a sample.

Parameters:
aSample a sample
Exceptions:
qgar::QgarErrorDomain (sample out of bounds)

Definition at line 375 of file Histogram.C.

Referenced by minus(), and plus().

int qgar::Histogram::samplingRate  )  const [inline]
 

Get cell width.

Definition at line 384 of file Histogram.H.

References _samplingRate.

Referenced by qgar::MapleFile::MapleFile().

void qgar::Histogram::smooth unsigned int  aWidth  )  throw (QgarErrorDomain)
 

Smooth by computing a simple average on a window of given size.

Parameters:
aWidth width of smoothing window
Exceptions:
qgar::QgarErrorDomain (bad window size)

Definition at line 285 of file Histogram.C.

int qgar::Histogram::upperBnd  )  const [inline]
 

Get upper bound.

Definition at line 376 of file Histogram.H.

References _upperBnd.

Referenced by qgar::MapleFile::MapleFile().


Member Data Documentation

std::vector<int> qgar::Histogram::_cells [protected]
 

Vector of cells.

Definition at line 321 of file Histogram.H.

Referenced by maxSample(), minSample(), minus(), operator=(), partialSum(), and plus().

int qgar::Histogram::_lowerBnd [protected]
 

Lower (non-sampled) bound.

Definition at line 311 of file Histogram.H.

Referenced by lowerBnd(), maxSample(), minSample(), and operator=().

int qgar::Histogram::_samplingRate [protected]
 

Sampling rate.

It is the ``width'' of a cell of the cell vector.

Definition at line 306 of file Histogram.H.

Referenced by maxSample(), minSample(), operator=(), and samplingRate().

int qgar::Histogram::_upperBnd [protected]
 

Upper (non-sampled) bound.

Definition at line 316 of file Histogram.H.

Referenced by operator=(), and upperBnd().


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