20 #ifndef MIRTK_Histogram1D_H 21 #define MIRTK_Histogram1D_H 23 #include "mirtk/Object.h" 24 #include "mirtk/Memory.h" 25 #include "mirtk/Math.h" 34 template <
class HistogramType>
143 void Add(
int, HistogramType = 1);
146 void Delete(
int, HistogramType = 1);
149 void AddSample(
double, HistogramType = 1);
152 void DelSample(
double, HistogramType = 1);
191 Array<double>
Modes()
const;
206 void Read(
const char *);
209 void Write(
const char *)
const;
220 template <
class HistogramType>
227 template <
class HistogramType>
234 template <
class HistogramType>
241 template <
class HistogramType>
254 template <
class HistogramType>
261 template <
class HistogramType>
269 template <
class HistogramType>
276 template <
class HistogramType>
283 template <
class HistogramType>
291 template <
class HistogramType>
298 template <
class HistogramType>
305 template <
class HistogramType>
312 template <
class HistogramType>
319 template <
class HistogramType>
326 template <
class HistogramType>
333 template <
class HistogramType>
341 template <
class HistogramType>
349 template <
class HistogramType>
352 if (x < _min || x >
_max)
return;
354 if (index < 0 ) index = 0;
361 template <
class HistogramType>
364 if (x < _min || x >
_max)
return;
366 if (index < 0 ) index = 0;
373 template <
class HistogramType>
380 template <
class HistogramType>
384 return (index < 0 ? 0 : (index >=
_nbins ?
_nbins - 1 : index));
388 template <
class HistogramType>
395 template <
class HistogramType>
402 template <
class HistogramType>
409 template <
class HistogramType>
412 if (
_nsamp == .0)
return .0;
414 for (
int j = 0; j <= i; ++j) {
421 template <
class HistogramType>
428 template <
class HistogramType>
431 if (p < .0 || p > 1.0) {
432 cerr <<
"Histogram1D<HistogramType>::CDFToBin: Must be between 0 and 1" << endl;
437 for (i = 0; i <
_nbins; ++i) {
438 sum +=
static_cast<double>(
_bins[i]);
439 if (sum /
_nsamp >= p)
return i;
445 template <
class HistogramType>
454 #endif // MIRTK_Histogram1D_H void Log()
Log transform histogram.
Array< double > Modes() const
Return sorted modal values.
void Delete(int, HistogramType=1)
Delete counts from bin.
double GetMax() const
Get maximum value in histogram.
int NumberOfBins() const
Get number of bins in histogram.
int _nbins
Number of bins.
HistogramType & operator()(int)
Get number of samples in bin(i)
double Mean() const
Calculate mean.
void Print() const
Print histogram.
double _width
Width of bins.
HistogramType * RawPointer()
Get raw pointer to histogram bins.
void PutWidth(double)
Put width of bins in histogram.
double GetWidth() const
Get width of bins in histogram.
void Allocate(Type *&matrix, int n)
Allocate 1D array.
HistogramType _nsamp
Number of samples.
void Read(const char *)
Read histogram.
void Add(int, HistogramType=1)
Add counts to bin.
double _min
Min. value for samples, everything below is ignored.
double BinToPDF(int bin) const
Convert bin into probability density distributions.
double ValToPDF(double val) const
Convert sample value into probability density distributions.
void Deallocate(Type *&p)
Deallocate 1D array.
void DelSample(double, HistogramType=1)
Delete sample from bin.
void PutMin(double)
Put minimum value in histogram.
void PutMax(double)
Put maximum value in histogram.
double GetMin() const
Get minimum value in histogram.
void Smooth()
Smooth histogram.
Histogram1D & operator=(const Histogram1D &)
Assignment operator.
double Min() const
Get minimum value in histogram.
double Variance() const
Calculate variance.
void Reset()
Clear and reset histogram.
double ValToRange(double val) const
Convert sample value to continuous bin index.
void Write(const char *) const
Wrirte histogram.
double Mode() const
Return smallest modal value.
HistogramType NumberOfSamples() const
Get number of samples in histogram.
double ValToCDF(double val) const
Convert sample value into cumulative density distributions.
double CDFToVal(double p) const
Convert cumulative density distributions to sample value.
~Histogram1D()
Destructor.
MIRTKCU_API int iround(T x)
Round floating-point value and cast to int.
double _max
Max. value for samples, everything below is ignored.
Histogram1D(const Histogram1D &)
Construct a histogram from another histogram.
int CDFToBin(double p) const
Convert cumulative density distributions to bin value.
double StandardDeviation() const
Calculate standard deviation.
double BinToCDF(int bin) const
Convert bin into cumulative density distributions.
void AddSample(double, HistogramType=1)
Add sample to bin.
double Entropy() const
Calculate entropy.
HistogramType * _bins
Dynamic memory for bins.
double BinToVal(int bin) const
Convert bin index to sample value.
double Max() const
Get maximum value in histogram.
int ValToBin(double val) const
Convert sample value to bin index.
void PutNumberOfBins(int)
Put number of bins in histogram.