40 void Setup(
const int& nBins,
const T& RangeMin,
const T& RangeMax);
43 void Setup(
const int& nBinsX,
const int& nBinsY,
const T& XRangeMin,
44 const T& XRangeMax,
const T& YRangeMin,
const T& YRangeMax);
47 void Setup(
const int& nBinsX,
const int& nBinsY,
const int& nBinsZ,
const T& XRangeMin,
48 const T& XRangeMax,
const T& YRangeMin,
const T& YRangeMax,
const T& ZRangeMin,
const T& ZRangeMax);
56 void Update(
const T& XVal,
const T& YVal);
58 void Read(
const std::string & file_name);
60 void Read(std::istream & ifs);
62 void Write(
const std::string & file_name)
const;
64 void Write(std::ostream & ofs)
const;
71 void SoftUpdate(
const T& XVal,
const T& YVal,
const float& Sigma);
80 void SoftUpdate3D(
const T& XVal,
const T& YVal,
const T& ZVal,
const float& Sigma);
104 float GetProb(
const T& XVal,
const T& YVal);
228 for(
unsigned int i = 0;
i < m_nBins;
i++)
230 pointer[
i] = m_pBins[
i];
237 for(
unsigned int i = 0;
i < m_nBins;
i++)
239 m_pBins[
i] = pointer[
i];
246 std::ifstream ifs(file_name.c_str());
271 assert(m_nBinsX == m_nBins);
275 assert( (m_nBinsX*m_nBinsY) == m_nBins);
280 m_pBins =
new float[m_nBins];
283 for(
unsigned int i = 0;
i < m_nBins;
i++)
294 ofstream ofs(file_name.c_str());
302 ofs << m_nBins << std::endl;
303 ofs << m_nBinsX << std::endl;
304 ofs << m_nBinsY << std::endl;
305 ofs << m_XRangeMin << std::endl;
306 ofs << m_XRangeMax << std::endl;
307 ofs << m_YRangeMin << std::endl;
308 ofs << m_YRangeMax << std::endl;
309 ofs << m_XFactor << std::endl;
310 ofs << m_YFactor << std::endl;
311 for(
unsigned int i = 0;
i < m_nBins;
i++)
313 ofs << m_pBins[
i] <<
" ";
325 m_nBinsX = m_nBins = nBins;
336 m_pBins =
new float[m_nBins];
347 m_nBinsX = m_nBins = nBins;
349 m_XRangeMin = RangeMin;
350 m_XRangeMax = RangeMax;
354 const float Range = (float)(RangeMax-RangeMin);
355 m_XFactor = (float)(nBins-1)/Range;
357 m_pBins =
new float[m_nBins];
364 const T& XRangeMin,
const T& XRangeMax,
365 const T& YRangeMin,
const T& YRangeMax,
366 const T& ZRangeMin,
const T& ZRangeMax)
372 m_XRangeMin = XRangeMin;
373 m_XRangeMax = XRangeMax;
374 m_YRangeMin = YRangeMin;
375 m_YRangeMax = YRangeMax;
376 m_ZRangeMin = ZRangeMin;
377 m_ZRangeMax = ZRangeMax;
378 const float XRange = (float)(m_XRangeMax-m_XRangeMin);
379 const float YRange = (float)(m_YRangeMax-m_YRangeMin);
380 const float ZRange = (float)(m_ZRangeMax-m_ZRangeMin);
381 m_XFactor = (float)(nBinsX-1)/XRange;
382 m_YFactor = (float)(nBinsY-1)/YRange;
383 m_ZFactor = (float)(nBinsZ-1)/ZRange;
384 m_nBins = nBinsX*nBinsY*nBinsZ;
385 m_pBins =
new float[m_nBins];
392 const T& XRangeMin,
const T& XRangeMax,
393 const T& YRangeMin,
const T& YRangeMax)
399 m_XRangeMin = XRangeMin;
400 m_XRangeMax = XRangeMax;
401 m_YRangeMin = YRangeMin;
402 m_YRangeMax = YRangeMax;
405 const float XRange = (float)(m_XRangeMax-m_XRangeMin);
406 const float YRange = (float)(m_YRangeMax-m_YRangeMin);
407 m_XFactor = (float)(nBinsX-1)/XRange;
408 m_YFactor = (float)(nBinsY-1)/YRange;
409 m_nBins = nBinsX*nBinsY;
410 m_pBins =
new float[m_nBins];
420 assert(Val >= m_XRangeMin);
421 assert(Val <= m_XRangeMax);
422 (*(m_pBins+
F2I((
float)(Val-m_XRangeMin)*m_XFactor)))++;
429 assert(XVal >= m_XRangeMin);
430 assert(XVal <= m_XRangeMax);
431 assert(YVal >= m_YRangeMin);
432 assert(YVal <= m_YRangeMax);
434 const int X =
F2I((
float)(XVal-(
float)m_XRangeMin)*m_XFactor);
435 const int Y =
F2I((
float)(YVal-(
float)m_YRangeMin)*m_YFactor);
436 (*(m_pBins+Y*m_nBinsX+X))++;
459 assert(XVal >= m_XRangeMin);
460 assert(XVal <= m_XRangeMax);
461 assert(YVal >= m_YRangeMin);
462 assert(YVal <= m_YRangeMax);
467 const float RealX = (XVal-m_XRangeMin)*m_XFactor;
468 const float RealY = (YVal-m_YRangeMin)*m_YFactor;
473 const int xw_center =
F2I(RealX);
474 const int yw_center =
F2I(RealY);
480 const int Rad =
F2I(3.0f*Sigma);
482 const float RecipSigmaSqr = 1.0f/
SQR(Sigma);
483 for (
int yw = -Rad; yw <= Rad; yw++) {
484 for (
int xw = -Rad; xw <= Rad; xw++) {
485 const int binXcoord = xw_center+xw;
486 const int binYcoord = yw_center+yw;
487 if ((binXcoord >= 0) && (binXcoord < m_nBinsX) &&
488 (binYcoord >= 0) && (binYcoord < m_nBinsY)) {
489 const float DeltaX = RealX-(float)binXcoord;
490 const float DeltaY = RealY-(float)binYcoord;
491 const float SquaredSum =
SQR(DeltaX)+
SQR(DeltaY);
492 const float Weight = exp(-SquaredSum*RecipSigmaSqr);
493 const int iBin = binYcoord*m_nBinsX+binXcoord;
494 m_pBins[iBin] += Weight;
510 assert(XVal >= m_XRangeMin);
511 assert(XVal <= m_XRangeMax);
516 const float RealX = (XVal-m_XRangeMin)*m_XFactor;
521 const int xw_center =
F2I(RealX);
527 const int Rad =
F2I(3.0f*Sigma);
529 const float RecipSigmaSqr = 1.0f/Sigma;
530 for (
int xw = -Rad; xw <= Rad; xw++) {
531 const int binXcoord = xw_center+xw;
532 if ((binXcoord >= 0) && (binXcoord < m_nBinsX)) {
533 const float DeltaX = RealX-(float)binXcoord;
534 const float SquaredSum =
SQR(DeltaX);
535 const float Weight = exp(-SquaredSum*RecipSigmaSqr);
536 const int iBin = binXcoord;
537 m_pBins[iBin] += Weight;
553 assert(XVal >= m_XRangeMin);
554 assert(XVal <= m_XRangeMax);
555 assert(YVal >= m_YRangeMin);
556 assert(YVal <= m_YRangeMax);
557 assert(ZVal >= m_ZRangeMin);
558 assert(ZVal <= m_ZRangeMax);
563 const float RealX = (XVal-m_XRangeMin)*m_XFactor;
564 const float RealY = (YVal-m_YRangeMin)*m_YFactor;
565 const float RealZ = (ZVal-m_ZRangeMin)*m_ZFactor;
570 const int xw_center =
F2I(RealX);
571 const int yw_center =
F2I(RealY);
572 const int zw_center =
F2I(RealZ);
578 const int Rad =
F2I(3.0f*Sigma);
581 const float RecipSigmaSqr = 1.0f/pow((
double) Sigma,1.0/3.0);
582 for (
int yw = -Rad; yw <= Rad; yw++) {
583 for (
int xw = -Rad; xw <= Rad; xw++) {
584 for (
int zw = -Rad; zw <= Rad; zw++) {
585 const int binXcoord = xw_center+xw;
586 const int binYcoord = yw_center+yw;
587 const int binZcoord = zw_center+zw;
588 if ((binXcoord >= 0) && (binXcoord < m_nBinsX) &&
589 (binYcoord >= 0) && (binYcoord < m_nBinsY) &&
590 (binZcoord >= 0) && (binZcoord < m_nBinsZ)) {
591 const float DeltaX = RealX-(float)binXcoord;
592 const float DeltaY = RealY-(float)binYcoord;
593 const float DeltaZ = RealZ-(float)binZcoord;
594 const float SquaredSum =
SQR(DeltaX)+
SQR(DeltaY)+
SQR(DeltaZ);
595 const float Weight = exp(-SquaredSum*RecipSigmaSqr);
596 const int iBin = m_nBinsZ*(binYcoord*m_nBinsX) + (binXcoord)*m_nBinsZ + binZcoord;
597 m_pBins[iBin] += Weight;
630 assert(XVal >= m_XRangeMin);
631 assert(XVal <= m_XRangeMax);
632 assert(YVal >= m_YRangeMin);
633 assert(YVal <= m_YRangeMax);
638 const float RealX = (XVal-m_XRangeMin)*m_XFactor;
639 const float RealY = (YVal-m_YRangeMin)*m_YFactor;
644 const int xw_center =
F2I(RealX);
645 const int yw_center =
F2I(RealY);
654 float* pWindow = pGauss_Window->
pBuffer();
656 for (
int yw = -Rad; yw <= Rad; yw++) {
657 for (
int xw = -Rad; xw <= Rad; xw++, pWindow++) {
658 const int binXcoord = xw_center+xw;
659 const int binYcoord = yw_center+yw;
660 if ((binXcoord >= 0) && (binXcoord < m_nBinsX) &&
661 (binYcoord >= 0) && (binYcoord < m_nBinsY)) {
666 const int iBin = binYcoord*m_nBinsX+binXcoord;
667 m_pBins[iBin] += *pWindow;
682 *(m_pBins+iBin) += Val;
694 for (i = 0; i < m_nBins; i++, pBin++) {
695 assert(*pBin >= 0.0f);
696 EltSum += (float)*pBin;
701 const float Factor = Area/EltSum;
704 for (i = 0; i < m_nBins; i++, pBin++) {
705 *pBin = (T)((
float)*pBin*(float)Factor);
715 const float HistoMax =
Max(m_pBins, m_nBins);
716 const float Factor = NMax/HistoMax;
717 float *pBin = m_pBins;
718 for (
int i = 0;
i < m_nBins;
i++, pBin++)
728 return *(m_pBins+
F2I((
float)(Val-m_XRangeMin)*m_XFactor));
735 const int X =
F2I((
float)(XVal-m_XRangeMin)*m_XFactor);
736 const int Y =
F2I((
float)(YVal-m_YRangeMin)*m_YFactor);
737 return *(m_pBins+Y*m_nBinsX+X);
749 T *pBuf = InImg.
pROI();
750 float *pDistBuf = PDistImg.
pROI();
751 for (
int y = ystart; y < yend; y++, pBuf += sk, pDistBuf += sk)
752 for (
int x = xstart;
x < xend;
x++, pBuf++, pDistBuf++)
753 *pDistBuf = GetProb(*pBuf);
766 T *pBuf1 = InImg1.
pROI(), *pBuf2 = InImg2.
pROI();
767 float *pDistBuf = PDistImg.
pROI();
768 for (
int y = ystart; y < yend;
769 y++, pBuf1 += sk, pBuf2 += sk, pDistBuf += sk)
770 for (
int x = xstart;
x < xend;
771 x++, pBuf1++, pBuf2++, pDistBuf++)
772 *pDistBuf = GetProb(*pBuf1, *pBuf2);
780 memset(m_pBins, 0,
sizeof(
float)*m_nBins);
788 bool bIsEmpty =
true;
789 for (
int i = 0;
i < m_nBins;
i++) {
790 if (m_pBins[
i] != (T)0) {
804 for (
int i = 0;
i < m_nBins;
i++)
805 if (m_pBins[
i] > MaxVal)
815 float *pBin = m_pBins;
816 for (
int i = 0;
i < m_nBins;
i++, pBin++) {
818 if (*pBin < 0.0f) *pBin = 0.0f;
828 T *pOtherBin = OtherHisto.
m_pBins;
830 for (
int i = 0;
i < nElts;
i++, pBin++, pOtherBin++)
841 for (
int i = 0;
i < nElts;
i++, pBin++)
850 return (T)((float)(m_XRangeMax-m_XRangeMin)*(float)BinIndex/
851 (
float)m_nBinsX+(float)m_XRangeMin);
860 T *pOtherBin = OtherHisto->
m_pBins;
862 for (
int i = 0;
i < m_nBins;
i++, pBin++, pOtherBin++) {
863 float Val = (float)*pBin;
864 float OtherVal = (float)*pOtherBin;
865 float diffsqr = Val-OtherVal; diffsqr *= diffsqr;
866 float ValSum = Val+OtherVal;
867 if (ValSum != 0.0f) Sum += diffsqr/ValSum;
874 assert(Sum < 1.001f);
885 for(
int i = 0;
i < m_nBins;
i++)
887 double val1 = (float)m_pBins[
i];
888 double val2 = (float)OtherHisto->
m_pBins[
i];
889 double diff = fabs(val1 - val2);
int m_nBinsY
Definition: histogram.h:170
#define zap(x)
Definition: utils.h:137
T BinIndexToValue(const int &BinIndex)
Definition: histogram.h:848
float * m_pBins
Definition: histogram.h:179
void GetValues(float *pointer)
Definition: histogram.h:226
float GetProbOfBin(int iBin)
Definition: histogram.h:107
int m_nBinsZ
Definition: histogram.h:171
float Max(float *pBuf, int Size)
Definition: utils.cpp:90
T m_ZRangeMax
Definition: histogram.h:178
float m_ZFactor
Definition: histogram.h:182
float ChiSquareCompare(CHistogram< T > *OtherHisto)
Definition: histogram.h:857
float m_XFactor
Definition: histogram.h:180
T m_XRangeMin
Definition: histogram.h:173
#define F2I(x)
Definition: utils.h:111
int nBins()
Definition: histogram.h:163
int m_nBinsX
Definition: histogram.h:169
int ROIEndX()
Definition: img.h:163
Definition: histogram.h:21
int ROIEndY()
Definition: img.h:165
void SoftUpdate1D(const T &XVal, const float &Sigma)
Definition: histogram.h:501
void IncrementBin(const int &iBin, const T &Val)
Definition: histogram.h:680
int ROIStartY()
Definition: img.h:164
void SoftUpdate_fast(const T &XVal, const T &YVal, const int &Rad, const FloatCImgPtr pGauss_Window)
Definition: histogram.h:620
void SetROIVal(const T &Val)
Definition: img.h:1071
void Update(const T &Val)
Definition: histogram.h:418
void Display(CImg< BYTE > &InImg)
bool IsEmpty()
Definition: histogram.h:786
void Add(const CHistogram< T > &OtherHisto)
Definition: histogram.h:825
int ROISkipCols()
Definition: img.h:166
T m_YRangeMax
Definition: histogram.h:176
T m_YRangeMin
Definition: histogram.h:175
~CHistogram()
Definition: histogram.h:220
x
Definition: APPgetLargeConnectedEdges.m:100
void Normalize(const float &Area=1.0f)
Definition: histogram.h:688
float m_YFactor
Definition: histogram.h:181
#define CONST_MIN_FLOAT
Definition: utils.h:20
CHistogram< float > * FloatCHistogramPtr
TYPES.
Definition: histogram.h:189
float * pBins()
Definition: histogram.h:164
void Setup(const int &nBins)
Definition: histogram.h:321
CHistogram()
Definition: histogram.h:198
void Read(const std::string &file_name)
Definition: histogram.h:244
void ScalarMultiply(const float &Multiplier)
Definition: histogram.h:837
int m_nBins
Definition: histogram.h:172
float NormalCompare(CHistogram< T > *OtherHisto)
Definition: histogram.h:882
void Write(const std::string &file_name) const
Definition: histogram.h:291
int ROIStartX()
Definition: img.h:162
void GetProbDist(CImg< T > &InImg, CImg< float > &PDistImg)
Definition: histogram.h:743
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
CHistogram< long > * LongCHistogramPtr
Definition: histogram.h:191
#define SQR(x)
Definition: utils.h:99
void NormalizeToMax(const float &Max=255.0f)
Definition: histogram.h:713
void SoftUpdate3D(const T &XVal, const T &YVal, const T &ZVal, const float &Sigma)
Definition: histogram.h:543
void Zero()
Definition: histogram.h:778
T m_XRangeMax
Definition: histogram.h:174
T m_ZRangeMin
Definition: histogram.h:177
void SoftUpdate(const T &XVal, const T &YVal, const float &Sigma)
Definition: histogram.h:449
float MaxBinVal()
Definition: histogram.h:801
float GetProb(const T &Val)
Definition: histogram.h:726
CHistogram< int > * IntCHistogramPtr
Definition: histogram.h:190
T * pBuffer()
Definition: img.h:148
void AdjustDown(const float &Value)
Definition: histogram.h:813
T * pROI()
Definition: img.h:151
void SetValues(float *pointer)
Definition: histogram.h:235