26 #include "HistogramImage.hh"
28 #include <Base/Image/ImageBase.hh>
29 #include <Base/ImageUtils/ImageDraw.hh>
31 #include <Base/Common/BIASpragma.hh>
41 HistogramImage::HistogramImage(
unsigned short int size)
43 ColorModel_ = ImageBase::CM_RGB;
45 InterleavedDataOrder_ =
true;
51 ScaleYToMaxEntry_=
true;
62 NewDebugLevel(
"D_HIST_BIN");
65 HistogramImage::~HistogramImage()
70 void HistogramImage::SetFactor(
unsigned short Factor)
73 InitHist(BinCount_, HistCount_);
76 void HistogramImage::SetColorModel()
78 BIASERR(
"HistogramImage::SetColorModel() not valid for HistogramImage");
82 void HistogramImage::SetBinCount(
unsigned int bincount)
84 if (bincount != BinCount_){
85 InitHist(bincount, HistCount_);
90 void HistogramImage::SetHistCount(
unsigned int histcount)
92 if (histcount != HistCount_){
93 InitHist(BinCount_, histcount);
97 int HistogramImage::InitHist(
unsigned int bincount ,
unsigned int histcount)
101 HistCount_ = histcount;
102 BinCount_ = bincount;
103 Hist_ =
new double*[HistCount_];
104 Color_ =
new unsigned char*[HistCount_];
105 MinBinVal_ =
new double[HistCount_];
106 MaxBinVal_ =
new double[HistCount_];
107 BinSize_ =
new double[HistCount_];
108 MaxHistEntry_ =
new double[HistCount_];
109 NumData_ =
new double[HistCount_];
110 Average_ =
new double[HistCount_];
111 for (
register unsigned int i = 0; i < HistCount_; i++){
112 Hist_[i] =
new double[BinCount_];
113 for (
register unsigned int j = 0; j < BinCount_; j++){
116 Color_[i] =
new unsigned char[3];
118 for (
register int j = 0; j < 3; j++){
121 MinBinVal_[i]=DBL_MAX;
122 MaxHistEntry_[i]=MaxBinVal_[i]=-DBL_MAX;
128 if (BinCount_ % 4 != 0)
129 bc = BinCount_ + 4 - (BinCount_ % 4);
132 if (HistSize_ % 4 != 0)
133 hs = HistSize_ + 4 - (HistSize_ % 4);
138 Init((bc + 2 * _uiBorder) * Factor_ , (hs + 2 * _uiBorder) * Factor_ , 3);
140 FillImageWithConstValue(255);
145 int HistogramImage::ReleaseHist()
148 for (
register int i =0; i < HistCount_; i++){
152 delete[] Hist_; Hist_=NULL;
155 if (Color_){
delete[] Color_; Color_=NULL; }
156 if (Average_){
delete[] Average_; Average_=NULL; }
157 if (MinBinVal_){
delete[] MinBinVal_; MinBinVal_=NULL; }
158 if (BinSize_){
delete[] BinSize_; BinSize_=NULL; }
159 if (MaxBinVal_){
delete[] MaxBinVal_; MaxBinVal_=NULL; }
160 if (MaxHistEntry_){
delete[] MaxHistEntry_; MaxHistEntry_ = NULL; }
161 if (NumData_){
delete[] NumData_; NumData_ = NULL; }
173 float HistogramImage::CalcShannonEntropy(
unsigned int hist)
176 if ( hist >= HistCount_){
177 BIASERR(
"HistogramImage::AddHist invalid hist "<<hist);
183 for(
unsigned int bin=0; bin < BinCount_-1;bin++)
185 if(Hist_[hist][bin] != 0.0)
187 entropy += (Hist_[hist][bin]/NumData_[hist])*
188 log((Hist_[hist][bin]/NumData_[hist]));
202 float HistogramImage::CalcRenyiEntropy(
unsigned int hist,
double alpha)
205 if ( hist >= HistCount_){
206 BIASERR(
"HistogramImage::AddHist invalid hist "<<hist);
211 for(
unsigned int bin=0; bin < BinCount_-1;bin++)
213 if(Hist_[hist][bin] != 0.0)
215 entropy += pow((Hist_[hist][bin]/NumData_[hist]),alpha);
218 return (1/(1-alpha))*log(entropy);
221 template <
class StorageType>
227 BIASERR(
"HistogramImage::AddHist only supports one channel images");
228 if ( hist >= HistCount_)
229 BIASERR(
"HistogramImage::AddHist invalid hist "<<hist);
231 BIASERR(
"HistogramImage::AddHist called with empty image");
234 StorageType min, max, diff;
238 MinBinVal_[hist]=(double)min;
239 MaxBinVal_[hist]=(double)max;
240 BinSize_[hist]=(MaxBinVal_[hist]-MinBinVal_[hist])/(
double)BinCount_;
241 BCDOUT(D_HIST_BIN,
"hist #"<<hist<<
": min/max pixel value: "
242 <<MinBinVal_[hist]<<
"/"<<MaxBinVal_[hist]<<endl);
244 for (
unsigned y=0; y<height; y++){
245 for (
unsigned x=0; x<width;x++){
246 if (ImageDataArray[y][x]==max){
251 bin=(
unsigned)floor((
double)BinCount_ * ((
double)ImageDataArray[y][x]-MinBinVal_[hist])/(
double)diff);
255 BIASERR(
"invalid index "<<bin);
259 if (bin>=(
int)BinCount_){
260 BIASERR(
"invalid index "<<bin<<
" "
261 <<ImageDataArray[y][x]<<
" "<<min<<
" "<<BinSize_[hist]<<
" "<<BinCount_);
267 if (Hist_[hist][bin]>MaxHistEntry_[hist])
268 MaxHistEntry_[hist]=Hist_[hist][bin];
277 template <> BIASImage_EXPORT
283 BIASERR(
"HistogramImage::AddHist only supports one channel images");
284 if ( hist >= HistCount_)
285 BIASERR(
"HistogramImage::AddHist invalid hist "<<hist);
287 BIASERR(
"HistogramImage::AddHist called with empty image");
291 for (
unsigned y=0; y<height; y++){
292 for (
unsigned x=0; x<width;x++){
293 if (Hist_[hist][BinCount_ * ImageDataArray[y][x] / 256] + 1 > MaxHistEntry_[hist] ){
294 MaxHistEntry_[hist] = Hist_[hist][BinCount_ * (ImageDataArray[y][x]) / 256]++;
298 Hist_[hist][BinCount_ * (ImageDataArray[y][x]) / 256]++;
303 MinBinVal_[hist]=0.0;
304 MaxBinVal_[hist]=255.0;
306 BinSize_[hist]=(MaxBinVal_[hist]-MinBinVal_[hist])/(
double)BinCount_;
311 template <
class DataType>
312 int HistogramImage::AddHist(
const vector<DataType>& data,
unsigned int hist)
314 typename vector<DataType>::const_iterator it;
315 DataType max=data.front(), min=data.front();
316 BIASCDOUT(D_HIST_VEC,
"data.size() = "<<data.size()<<endl);
317 for (it=data.begin(); it!=data.end(); it++){
318 if ((*it)>max) max=*it;
319 if ((*it)<min) min=*it;
320 BIASCDOUT(D_HIST_VEC, (*it)<<
" ");
322 BIASCDOUT(D_HIST_VEC,
"\nmin/max "<<min<<
"/"<<max);
323 return AddHist(data, min, max, hist);
326 template <
class DataType>
327 int HistogramImage::AddHist(
const vector<DataType>& data, DataType min, DataType max,
333 BIASERR(
"data has size 0");
336 if (hist>HistCount_){
337 BIASERR(
"hist="<<hist<<
" to big. HistCount_="<<HistCount_);
341 typename vector<DataType>::const_iterator it;
343 BIASCDOUT(D_HIST_VEC,
"data.size() = "<<data.size()<<endl);
345 BIASCDOUT(D_HIST_VEC,
"\nmin/max "<<min<<
"/"<<max);
346 MinBinVal_[hist]=(double)min;
347 MaxBinVal_[hist]=(double)max;
348 BIASCDOUT(D_HIST_VEC,
"MinBinVal_["<<hist<<
"]/MaxBinVal_["<<hist<<
"] "<<
349 MinBinVal_[hist]<<
"/"<<MaxBinVal_[hist]);
350 BinSize_[hist]=(MaxBinVal_[hist]-MinBinVal_[hist])/(
double)BinCount_;
351 BIASCDOUT(D_HIST_VEC,
"min: "<<MinBinVal_[hist]<<
" max: "<<MaxBinVal_[hist]
352 <<
" binsize: "<<BinSize_[hist]<<endl);
353 for (it=data.begin(); it!=data.end(); it++){
357 bin=(int)floor(
double((*it)-min)/BinSize_[hist]);
361 BIASERR(
"invalid index "<<bin<<
" data "<<(*it)<<
" min "<<min
362 <<
" binsize "<<BinSize_[hist]);
365 if (bin>=(
int)BinCount_){
366 BIASERR(
"invalid index "<<bin<<
" "
367 <<*it<<
" "<<min<<
" "<<BinSize_[hist]<<
" "<<BinCount_);
372 if (Hist_[hist][bin]>MaxHistEntry_[hist])
373 MaxHistEntry_[hist]=Hist_[hist][bin];
375 BIASCDOUT(D_HIST_VEC,
"MaxHistEntry_["<<hist<<
"] = "<<MaxHistEntry_[hist]
377 NumData_[hist]+=(double)data.size();
384 template <
class DataType>
385 int HistogramImage::AddWeightedHist(
const vector<DataType>& data,
const vector<double>& weight,
389 if (data.size() != weight.size()){
390 BIASERR(
"data and weight have different sizes "<<data.size()
391 <<
" "<<weight.size());
392 BIASASSERT(data.size() == weight.size());
395 typename vector<DataType>::const_iterator it;
396 vector<double>::const_iterator wit;
398 DataType max=data.front(), min=data.front();
399 for (it=data.begin(); it!=data.end(); it++){
400 if ((*it)>max) max=*it;
401 if ((*it)<min) min=*it;
403 MinBinVal_[hist]=(double)min;
404 MaxBinVal_[hist]=(double)max;
405 BinSize_[hist]=(MaxBinVal_[hist]-MinBinVal_[hist])/(
double)BinCount_;
407 for (it=data.begin(), wit=weight.begin(); it!=data.end(); it++, wit++){
411 bin=(int)floor(
double((*it)-min)/BinSize_[hist]);
416 BIASERR(
"invalid index "<<bin);
417 if (bin>=(
int)BinCount_)
418 BIASERR(
"invalid index "<<bin<<
" "
419 <<*it<<
" "<<min<<
" "<<BinSize_[hist]<<
" "<<BinCount_);
422 Hist_[hist][bin]+=(*wit);
423 if (Hist_[hist][bin]>MaxHistEntry_[hist])
424 MaxHistEntry_[hist]=Hist_[hist][bin];
427 NumData_[hist]+=(double)data.size();
432 template int HistogramImage::AddWeightedHist<double>(
const vector<double>& data,
const vector<double>& weight,
unsigned hist);
433 template int HistogramImage::AddWeightedHist<float>(
const vector<float>& data,
const vector<double>& weight,
unsigned hist);
434 template int HistogramImage::AddWeightedHist<int>(
const vector<int>& data,
const vector<double>& weight,
unsigned hist);
435 template int HistogramImage::AddWeightedHist<unsigned>(
const vector<unsigned>& data,
const vector<double>& weight,
unsigned hist);
437 int HistogramImage::CalcAverage_(
unsigned int hist)
439 Average_[hist] = 0.0;
440 for (
unsigned int i=0; i<BinCount_; i++)
441 Average_[hist] += Hist_[hist][i];
443 Average_[hist] /= BinCount_;
450 int HistogramImage::ZeroHist(
unsigned int hist)
452 MaxHistEntry_[hist]=0.0;
455 MaxBinVal_[hist]=MinBinVal_[hist]=BinSize_[hist]=0.0;
457 memset(Hist_[hist], 0, BinCount_ *
sizeof(
double));
458 FillImageWithConstValue(255);
463 int HistogramImage::RedrawHist_(
unsigned int hist)
465 return DeleteHist_(hist) + DrawHist_(hist);
469 int HistogramImage::DrawHist_(
unsigned int hist)
471 unsigned int BorderOffset = Factor_ * _uiBorder * GetChannelCount();
472 register unsigned char **ImageDataArray = GetImageDataArray();
473 unsigned start[2], end[2], st[2];
476 register int y, x, kk;
477 start[0]=Factor_ * _uiBorder;
478 start[1]=Factor_ * _uiBorder + Factor_ * (HistSize_-1);
479 double maxy=(ScaleYToMaxEntry_)?(MaxHistEntry_[hist]):(NumData_[hist]);
480 for (
register unsigned int i = 0; i < BinCount_ ; i++){
481 y = Factor_ * _uiBorder + Factor_ *
482 (((int)HistSize_-1)-(int)rint(((
int)HistSize_-1)*Hist_[hist][i] /
484 x = BorderOffset + Factor_ * 3 * i;
486 if (y<0 || y>=(
int)GetHeight()){
487 BIASERR(
"invalid y="<<y<<
" HistSize_="<<HistSize_<<
" Hist_["<<hist<<
"]["
488 <<i<<
"]="<<Hist_[hist][i]<<
" MaxHistEntry_="
489 <<MaxHistEntry_[hist]);
495 for (
register unsigned int k = 0; k < Factor_ ; k++){
497 for (
register unsigned int j = 0; j < Factor_ ; j++){
498 ImageDataArray[y + j][x + kk] = Color_[hist][0];
499 ImageDataArray[y + j][x + kk + 1] = Color_[hist][1];
500 ImageDataArray[y + j][x + kk + 2] = Color_[hist][2];
505 for (
register unsigned int k = 0; k < Factor_ ; k++){
507 for (
register unsigned int j = y;
508 j < GetHeight() - Factor_ * _uiBorder; j++){
509 ImageDataArray[j][x + kk] = Color_[hist][0];
510 ImageDataArray[j][x + kk + 1] = Color_[hist][1];
511 ImageDataArray[j][x + kk + 2] = Color_[hist][2];
516 for (
register unsigned int k = 0; k < Factor_ ; k++){
517 for (
register unsigned int j = 0; j < Factor_ ; j++){
531 y = Factor_ * (_uiBorder + (HistSize_ - 1) -
532 (
int)rint((HistSize_ - 1) * Average_[hist] /
536 for (
unsigned int j=BorderOffset;
537 j < (BinCount_ - 1) * Factor_ * 3 + BorderOffset;
539 ImageDataArray[y][j] = Color_[hist][0];
540 ImageDataArray[y][j+1] = Color_[hist][1];
541 ImageDataArray[y][j+2] = Color_[hist][2];
546 int HistogramImage::DrawHistLog_(
unsigned int hist)
548 unsigned int BorderOffset = Factor_ * _uiBorder * GetChannelCount();
549 register unsigned char **ImageDataArray = GetImageDataArray();
550 unsigned start[2], end[2], st[2];
553 register int y, x, kk;
554 start[0]=Factor_ * _uiBorder;
555 start[1]=Factor_ * _uiBorder + Factor_ * (HistSize_-1);
556 double maxy=(ScaleYToMaxEntry_)?(MaxHistEntry_[hist]):(NumData_[hist]);
557 for (
register unsigned int i = 0; i < BinCount_ ; i++){
558 y = Factor_ * _uiBorder + Factor_ *
560 (int)rint(((
int)HistSize_-1)*
561 log10((Hist_[hist][i]/maxy)*9.0+1.0)));
562 x = BorderOffset + Factor_ * 3 * i;
564 if (y<0 || y>=(
int)GetHeight()){
565 BIASERR(
"invalid y="<<y<<
" HistSize_="<<HistSize_<<
" Hist_["<<hist<<
"]["
566 <<i<<
"]="<<Hist_[hist][i]<<
" MaxHistEntry_="
567 <<MaxHistEntry_[hist]);
573 for (
register unsigned int k = 0; k < Factor_ ; k++){
575 for (
register unsigned int j = 0; j < Factor_ ; j++){
576 ImageDataArray[y + j][x + kk] = Color_[hist][0];
577 ImageDataArray[y + j][x + kk + 1] = Color_[hist][1];
578 ImageDataArray[y + j][x + kk + 2] = Color_[hist][2];
583 for (
register unsigned int k = 0; k < Factor_ ; k++){
585 for (
register unsigned int j = y;
586 j < GetHeight() - Factor_ * _uiBorder; j++){
587 ImageDataArray[j][x + kk] = Color_[hist][0];
588 ImageDataArray[j][x + kk + 1] = Color_[hist][1];
589 ImageDataArray[j][x + kk + 2] = Color_[hist][2];
594 for (
register unsigned int k = 0; k < Factor_ ; k++){
595 for (
register unsigned int j = 0; j < Factor_ ; j++){
609 y = Factor_ * (_uiBorder + (HistSize_ - 1) -
610 (
int)rint((HistSize_ - 1) * Average_[hist] /
614 for (
unsigned int j=BorderOffset;
615 j < (BinCount_ - 1) * Factor_ * 3 + BorderOffset;
617 ImageDataArray[y][j] = Color_[hist][0];
618 ImageDataArray[y][j+1] = Color_[hist][1];
619 ImageDataArray[y][j+2] = Color_[hist][2];
625 int HistogramImage::DeleteHist_(
unsigned int hist)
627 register unsigned char *r = GetImageData();
628 register unsigned char *g = r + 1;
629 register unsigned char *b = g + 1;
630 register unsigned char *end = r + GetChannelCount() * GetPixelCount();
633 if ( (*r == Color_[hist][0]) && (*g == Color_[hist][1]) &&
634 (*b == Color_[hist][2]) )
644 int HistogramImage::SetColor(
unsigned char R,
unsigned char G,
unsigned char B,
648 if (hist + 1 > HistCount_ )
649 BIASERR(
"HistogramImage::SetColor() invalid hist "<<hist);
659 int HistogramImage::Draw()
661 register unsigned char **ImageDataArray = GetImageDataArray();
663 for (
unsigned int i=0; i< Factor_ * _uiBorder; i++){
664 memset((
void *)(ImageDataArray[i]), _ucBorderColor, GetWidthStep() *
665 sizeof(
unsigned char));
666 memset((
void *)(ImageDataArray[GetHeight()-1-i]), _ucBorderColor,
667 GetWidthStep() *
sizeof(
unsigned char) );
668 for (
unsigned int j=Factor_ * _uiBorder; j<GetHeight()-Factor_ * _uiBorder;
670 for (
unsigned int c=0; c<GetChannelCount(); c++){
671 ImageDataArray[j][i*GetChannelCount()+c]=_ucBorderColor;
672 ImageDataArray[j][(GetWidth()-1-i)*GetChannelCount()+c]=_ucBorderColor;
676 for (
int i = 0; i < HistCount_; i++)
677 if (MaxHistEntry_[i]>0)
682 int HistogramImage::DrawLog()
684 register unsigned char **ImageDataArray = GetImageDataArray();
686 for (
unsigned int i=0; i< Factor_ * _uiBorder; i++){
687 memset((
void *)(ImageDataArray[i]), _ucBorderColor, GetWidthStep() *
688 sizeof(
unsigned char));
689 memset((
void *)(ImageDataArray[GetHeight()-1-i]), _ucBorderColor,
690 GetWidthStep() *
sizeof(
unsigned char) );
691 for (
unsigned int j=Factor_ * _uiBorder; j<GetHeight()-Factor_ * _uiBorder;
693 for (
unsigned int c=0; c<GetChannelCount(); c++){
694 ImageDataArray[j][i*GetChannelCount()+c]=_ucBorderColor;
695 ImageDataArray[j][(GetWidth()-1-i)*GetChannelCount()+c]=_ucBorderColor;
699 for (
int i = 0; i < HistCount_; i++)
704 double HistogramImage::GetBin(
unsigned int bin,
unsigned int hist)
706 if (bin < BinCount_ && hist < HistCount_)
return Hist_[hist][bin];
710 int HistogramImage::SetBin(
unsigned int bin,
double value,
unsigned int hist)
712 if (bin < BinCount_ && hist < HistCount_) {
713 Hist_[hist][bin] = value;
714 MaxHistEntry_[hist] =0.0;
716 for (
unsigned int i=0; i<BinCount_; i++)
717 if (MaxHistEntry_[hist] < Hist_[hist][i])
718 MaxHistEntry_[hist] = Hist_[hist][i];
726 void HistogramImage::Dump(ostream& os)
728 double *s=
new double[HistCount_];
729 memset((
void *)s, 0,
sizeof(
double)*HistCount_);
730 for (
int b=0; b<(int)BinCount_; b++){
731 os << setw(4) << b <<
": ";
732 for (
int h=0; h<(int)HistCount_; h++){
733 os << setw(8) << Hist_[h][b];
739 for (
int h=0; h<(int)HistCount_; h++){
740 os << setw(8) << s[h];
744 for (
int h=0; h<(int)HistCount_; h++){
745 os << setw(8) << Average_[h];
751 bool HistogramImage::IsEmpty()
754 for (
int h=0; h<(int)HistCount_; h++){
755 result = result && (MaxHistEntry_[h]==0);
760 int HistogramImage::WriteASCII(
const std::string& filename)
763 ofstream of(filename.c_str());
765 BIASERR(
"error opening "<<filename);
772 BIASERR(
"error writing "<<filename);
780 void HistogramImage::WriteASCII(ostream& os)
782 os <<
"# "<<HistCount_<<
" histogram(s) with "<<BinCount_<<
" bins"<<endl;
783 os <<
"# bin - number of the bin\n";
784 os <<
"# binb - binborders: [binb, binb+1)\n";
785 os <<
"# binv - number of values contained in bin\n";
786 os <<
"#"<<setw(7)<<
"bin";
787 double *bs=
new double[HistCount_];
788 for (
int h=0; h<(int)HistCount_; h++){
789 bs[h]=(MaxBinVal_[h]-MinBinVal_[h])/(
double)BinCount_;
790 os <<setw(15)<<
"binb"<<setw(12)<<
"binv";
793 for (
int b=0; b<(int)BinCount_; b++){
795 for (
int h=0; h<(int)HistCount_; h++){
796 os <<setw(15) << MinBinVal_[h]+b*bs[h] << setw(12) << Hist_[h][b];
803 void HistogramImage::CooTransf(
double datacoo[2],
double imcoo[2],
unsigned hist)
806 double maxy=(ScaleYToMaxEntry_)?(MaxHistEntry_[hist]):(NumData_[hist]);
808 d[0]=(datacoo[0]<MinBinVal_[hist])?(MinBinVal_[hist]):
809 ((datacoo[0]>MaxBinVal_[hist])?(MaxBinVal_[hist]):(datacoo[0]));
810 d[1]=(datacoo[1]<0.0)?(0.0):
811 ((datacoo[1]>maxy)?(maxy):(datacoo[1]));
814 ((double)_uiBorder+(d[0]-MinBinVal_[hist])/BinSize_[hist]);
815 imcoo[1]=Factor_ * ((double)_uiBorder+
double((
int)HistSize_-1)*
819 void HistogramImage::CooTransf(
double datacoo[2],
unsigned imcoo[2],
unsigned hist)
822 CooTransf(datacoo, d, hist);
823 imcoo[0]=(unsigned)rint(d[0]);
824 imcoo[1]=(unsigned)rint(d[1]);
831 Histogram2D::Histogram2D(
unsigned short int zoomfactor)
832 :
Image<unsigned char>()
852 BIASERR(
"Histogram2D::SetColorModel() not valid for Histogram");
887 (YBinCount_ + 2 *
_uiBorder) * Factor_ , 3);
892 template <
class DataType>
895 DataType maxx=xdata.front(), minx=xdata.front(), maxy=ydata.front(),
897 typename vector<DataType>::const_iterator itx, ity;
900 for (itx=xdata.begin(); itx!=xdata.end(); itx++){
901 if (*itx>maxx) maxx=*itx;
902 if (*itx<minx) minx=*itx;
904 for (ity=ydata.begin(); ity!=ydata.end(); ity++){
905 if (*ity>maxy) maxy=*ity;
906 if (*ity<miny) miny=*ity;
916 if (xdata.size()!=ydata.size()){
917 BIASERR(
"data vectors have different size "<<xdata.size()<<
" "
921 for (itx=xdata.begin(), ity=ydata.begin(); itx!=xdata.end(); itx++, ity++){
925 xbin=(int)floor(
double((*itx)-minx)/
XBinSize_);
930 ybin=(int)floor(
double((*ity)-miny)/
YBinSize_);
933 if (xbin<0 || ybin<0)
934 BIASERR(
"invalid index "<<xbin<<
" "<<ybin<<
" "<<
XBinCount_
937 BIASERR(
"invalid index "<<xbin<<
" "<<ybin<<
" "<<*itx<<
" "<<minx<<
" "
939 <<
" "<<maxy<<
" "<<
YBinSize_<<
" "<<YBinCount_);
960 BIASASSERT(
Hist_!=NULL);
966 BIASASSERT(
Hist_!=NULL);
968 unsigned mx, my, a, f3=3*
Factor_;
973 sizeof(
unsigned char));
990 if (
Hist_[y][x]==0.0){
996 BIASERR(
"error in drawing depth");
998 r=(a>=128)?255:(a*2);
999 g=(a>=128)?((255-a)*2):255;
1003 for (
int ro=0; ro<
Factor_; ro++){
1004 for (
unsigned c=0; c<f3; c+=3){
1006 ida[my+ro][mx+c+1]=g;
1007 ida[my+ro][mx+c+2]=b;
1016 BIASASSERT(
Hist_!=NULL);
1018 unsigned mx, my, a, f3=3*
Factor_;
1023 sizeof(
unsigned char));
1037 my=(_uiBorder+YBinCount_-1-y)*
Factor_;
1040 if (
Hist_[y][x]==0.0){
1046 BIASERR(
"error in drawing depth");
1048 r=(a>=128)?255:(a*2);
1049 g=(a>=128)?((255-a)*2):255;
1053 for (
int ro=0; ro<
Factor_; ro++){
1054 for (
unsigned c=0; c<f3; c+=3){
1056 ida[my+ro][mx+c+1]=g;
1057 ida[my+ro][mx+c+2]=b;
1069 <<
"# x, y - coo of bin\n"
1070 <<
"# xval, yval - the value of the entries of the bin\n"
1071 <<
"# count - number of entries in bin\n"
1073 <<
"# "<<setw(4)<<
"y"<<setw(15)<<
"yval"<<setw(6)<<
"x"<<setw(15)<<
"xval"
1074 <<setw(15)<<
"val"<<setw(6)<<
"x"<<setw(15)<<
"xval"<<setw(15)<<
"val"
1075 <<setw(6)<<
"x"<<setw(15)<<
"xval"<<setw(15)<<
"count"
1081 << setw(15) <<
Hist_[y][x];
1092 <<
"# x, y - coo of bin\n"
1093 <<
"# xval, yval - the value of the entries of the bin\n"
1094 <<
"# count - number of entries in bin\n"
1096 <<
"# "<<setw(6)<<
"y"<<setw(15)<<
"yval"<<setw(8)<<
"x"<<setw(15)<<
"xval"
1097 <<setw(15)<<
"count\n";
1102 << setw(15) <<
Hist_[y][x] << endl;
1104 os << endl << endl << endl;
1125 imcoo[0]=(unsigned)rint(d[0]);
1126 imcoo[1]=(unsigned)rint(d[1]);
1136 #define INST_ADDHIST(DataType)\
1137 template int BIASImage_EXPORT HistogramImage::AddHist<DataType>(const std::vector<DataType>& data, DataType min, DataType max, unsigned int hist ); \
1138 template int BIASImage_EXPORT HistogramImage::AddHist<DataType>(const std::vector<DataType>& data, unsigned int hist); \
1139 template void BIASImage_EXPORT Histogram2D::AddHist(const std::vector<DataType>& xdata,const std::vector<DataType>& ydata);
1141 INST_ADDHIST(
unsigned char)
1143 INST_ADDHIST(
double)
1145 INST_ADDHIST(
unsigned int)
1149 #define INST_ADDHIST_IMG(DataType)\
1150 template int BIASImage_EXPORT HistogramImage::AddHist<DataType>(const Image<DataType> &src, unsigned hist); \
1152 #ifdef BUILD_IMAGE_UCHAR
1153 INST_ADDHIST_IMG(
float)
1159 #ifdef BUILD_IMAGE_INT
1160 INST_ADDHIST_IMG(
int)
1162 #ifdef BUILD_IMAGE_CHAR
1163 INST_ADDHIST_IMG(
char)
1165 #ifdef BUILD_IMAGE_SHORT
1166 INST_ADDHIST_IMG(
short)
1168 #ifdef BUILD_IMAGE_USHORT
1169 INST_ADDHIST_IMG(
unsigned short)
1171 #ifdef BUILD_IMAGE_UINT
1172 INST_ADDHIST_IMG(
unsigned int)
1174 #ifdef BUILD_IMAGE_DOUBLE
1175 INST_ADDHIST_IMG(
double)
void Release()
reimplemented from ImageBase
class for handling different region of interest (ROI) representations...
void InitHist(unsigned xbincount=256, unsigned ybincount=256)
bool InterleavedDataOrder_
planar or interleaved: planar means we have several image planes, e.g.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
unsigned int GetWidthStep() const
returns the number of bytes per line
void Dump(std::ostream &os=std::cout)
void GetMinMaxPixelValue(StorageType &min, StorageType &max, unsigned short int channel=0, unsigned int *mincoo=NULL, unsigned int *maxcoo=NULL) const
returns the minimal and maximal pixel value in channel only Finds minimum and maximum pixel value in ...
unsigned int GetWidth() const
void SetColorModel()
dummy function to avoid swapping color model in this class
unsigned short int Factor_
ROI * GetROI()
Returns a pointer to the roi object.
bool IsInROI(const double &x, const double &y) const
ROI check if pixel position is inside the ROI.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
unsigned int GetHeight() const
void FillImageWithConstValue(unsigned charValue)
fill grey images
The image template class for specific storage types.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
void CooTransf(double datacoo[2], double imcoo[2])
transforms data coordinates to image coordinates automatic clipping of imcoo is performed ...
void WriteASCII(std::ostream &os=std::cout)
writes ascii data to stream, can be used later e.g. with gnuplot
unsigned char _ucBorderColor
drawing simple entities into the image like rectangles or lines As all functions are static they have...
void AddHist(const std::vector< DataType > &xdata, const std::vector< DataType > &ydata)
unsigned long int GetPixelCount() const
returns number of pixels in image
void SetFactor(unsigned short Factor)
sets the zoomfactor
enum EColorModel ColorModel_
the color model of the pixels
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase