21 #ifndef MIRTK_Histogram2D_H 22 #define MIRTK_Histogram2D_H 24 #include "mirtk/Math.h" 25 #include "mirtk/Object.h" 26 #include "mirtk/Histogram1D.h" 35 template <
class HistogramType>
42 typedef HistogramType BinType;
74 HistogramType **_bins;
85 Histogram2D(
double min_x,
double max_x,
double width_x,
86 double min_y,
double max_y,
double width_y);
95 void Initialize(
double min_x,
double max_x,
double width_x,
96 double min_y,
double max_y,
double width_y);
159 void GetMin(
double *,
double *)
const;
162 void GetMin(
double &,
double &)
const;
165 void PutMin(
double,
double);
168 void GetMax(
double *,
double *)
const;
171 void GetMax(
double &,
double &)
const;
174 void PutMax(
double,
double);
177 void GetWidth(
double *,
double *)
const;
180 void GetWidth(
double &,
double &)
const;
195 const HistogramType &
operator()(
int,
int)
const;
198 void Add(
int,
int, HistogramType = 1);
201 void Delete(
int,
int, HistogramType = 1);
204 void AddSample(
double,
double, HistogramType = 1);
207 void DelSample(
double,
double, HistogramType = 1);
258 double MeanX()
const;
261 double MeanY()
const;
321 double Kappa()
const;
324 void Read(
const char *);
327 void Write(
const char *)
const;
341 template <
class HistogramType>
350 template <
class HistogramType>
353 return _nbins_x * _nbins_y;
357 template <
class HistogramType>
364 template <
class HistogramType>
371 template <
class HistogramType>
378 template <
class HistogramType>
385 template <
class HistogramType>
392 template <
class HistogramType>
399 template <
class HistogramType>
406 template <
class HistogramType>
413 template <
class HistogramType>
420 template <
class HistogramType>
427 template <
class HistogramType>
434 template <
class HistogramType>
441 template <
class HistogramType>
448 template <
class HistogramType>
455 template <
class HistogramType>
463 template <
class HistogramType>
471 template <
class HistogramType>
474 int index =
static_cast<int>(round(_nbins_x * (val - _min_x - 0.5*_width_x) / (_max_x - _min_x)));
475 if (index < 0) index = 0;
476 if (index > _nbins_x-1) index = _nbins_x - 1;
481 template <
class HistogramType>
484 int index =
static_cast<int>(round(_nbins_y * (val - _min_y - 0.5*_width_y) / (_max_y - _min_y)));
485 if (index < 0) index = 0;
486 if (index > _nbins_y-1) index = _nbins_y - 1;
491 template <
class HistogramType>
494 return (i*(_max_x - _min_x)/_nbins_x + _min_x) + _width_x/2.0;
498 template <
class HistogramType>
501 return (i*(_max_y - _min_y)/_nbins_y + _min_y) + _width_y/2.0;
505 template <
class HistogramType>
514 template <
class HistogramType>
523 template <
class HistogramType>
526 return _bins[j][i] / (double) _nsamp;
530 template <
class HistogramType>
534 for (
int j = 0; j < _nbins_y; j++) {
537 return n / (double) _nsamp;
541 template <
class HistogramType>
545 for (
int j = 0; j < _nbins_x; j++) {
548 return static_cast<double>(n) / _nsamp;
552 template <
class HistogramType>
564 template <
class HistogramType>
578 #endif // MIRTK_Histogram2D_H void Write(const char *) const
Write histogram.
HistogramType * RawPointer()
Get raw pointer to histogram bins.
double VarianceX() const
Calculate variance.
int NumberOfBinsX() const
Get number of bins in x-direction.
void PutNumberOfBinsX(int)
Put number of bins in x-direction.
Histogram2D(const Histogram2D &)
Construct a histogram from another histogram.
double StandardDeviationX() const
Calculate standard deviation.
void Smooth()
Smooth histogram.
double Covariance() const
Calculate covariance.
double CrossCorrelation() const
Calculate cross correlation.
Histogram1D< HistogramType > HistogramY() const
Compute marginal histogram of Y.
Histogram2D & operator=(const Histogram2D &)
Assignment operator.
double WidthY() const
Get width of bins in histogram in y-direction.
void AddSample(double, double, HistogramType=1)
Add samples.
double ConditionalMeanYX(int) const
Calculate conditional mean.
void WriteAsImage(const char *) const
Write histogram as 2D image.
void PutNumberOfBinsY(int)
Put number of bins in x-direction.
void GetMin(double *, double *) const
Get minimum value in histogram.
double MutualInformation() const
Calculate mutual information.
double BinToValX(int bin) const
Convert bin index to sample value.
double JointEntropy() const
Calculate joint entropy.
double JointProbability(int, int) const
Calculate joint probability p(x, y)
double MinY() const
Get minimum value in histogram in y-direction.
void GetMax(double *, double *) const
Get maximum value in histogram.
~Histogram2D()
Destructor.
double ConditionalProbabilityXY(int, int) const
Calculate conditional probability p(x|y)
double MeanY() const
Calculate mean.
double LabelConsistency() const
Calcualate label consistency.
double MinX() const
Get minimum value in histogram in x-direction.
int ValToBinY(double val) const
Convert sample value to bin index.
int ValToBinX(double val) const
Convert sample value to bin index.
double MaxY() const
Get maximum value in histogram in y-direction.
double NormalizedMutualInformation() const
Calculate normalized mutual information.
Histogram2D< HistogramType > Transposed() const
Get transposed histogram with x and y direction exchanged.
void Delete(int, int, HistogramType=1)
Delete counts from bins.
double VarianceY() const
Calculate variance.
HistogramType & operator()(int, int)
Get number of samples in bin(i, j)
int NumberOfBins() const
Get total number of bins.
double SumsOfSquaredDifferences() const
Calculate sums of squared differences.
double EntropyX() const
Calculate marginal entropy.
double EntropyY() const
Calculate marginal entropy.
double MaxX() const
Get maximum value in histogram in x-direction.
double ConditionalMeanXY(int) const
Calculate conditional mean.
HistogramType NumberOfSamples() const
Get number of samples in histogram.
void Read(const char *)
Read histogram.
void Reset()
Clear and reset histogram.
double Kappa() const
Calcualate kappa statistic.
void GetNumberOfBins(int *, int *) const
Get number of bins in x- and y-direction.
int NumberOfBinsY() const
Get number of bins in x-direction.
void Initialize(double min_x, double max_x, double width_x, double min_y, double max_y, double width_y)
Construct a histogram for samples ranging from min to max and width.
void Log()
Log transform histogram.
void PutWidth(double, double)
Put width of bins in histogram.
double ConditionalProbabilityYX(int, int) const
Calculate conditional probability p(y|x)
void PutNumberOfBins(int, int)
Put number of bins in x- and y-direction.
double CorrelationRatioXY() const
Calculate correlation ratio.
double MeanX() const
Calculate mean.
void PutMax(double, double)
Put maximum value in histogram.
double StandardDeviationY() const
Calculate standard deviation.
void DelSample(double, double, HistogramType=1)
Delete samples.
double MarginalProbabilityX(int) const
Calculate marginal probability p(x)
double ConditionalVarianceXY(int) const
Calculate conditional variance.
void PutMin(double, double)
Put minimum value in histogram.
double WidthX() const
Get width of bins in histogram in x-direction.
double CorrelationRatioYX() const
Calculate correlation ratio.
Histogram2D< HistogramType > Smoothed(bool=false)
Get smoothed histogram, optionally with padded boundaries.
Histogram2D< HistogramType > & Transpose()
Transpose histogram in place with x and y direction exchanged.
double ConditionalVarianceYX(int) const
Calculate conditional variance.
void Add(int, int, HistogramType=1)
Add counts to bins.
double MarginalProbabilityY(int) const
Calculate marginal probability p(y)
void GetWidth(double *, double *) const
Get width of bins in histogram.
double BinToValY(int bin) const
Convert bin index sample value.
void Print() const
Print histogram.
Histogram1D< HistogramType > HistogramX() const
Compute marginal histogram of X.