Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CondensHisto.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #include "CondensHisto.hh"
27 #include "Base/ImageUtils/ImageDraw.hh"
28 
29 #include <Base/Common/BIASpragma.hh>
30 
31 using namespace BIAS;
32 using namespace std;
33 
34 //#define DEBUG true
35 
36 
38  stateDim_=3;
39  img_ = NULL;
40  diffScale_=0.05;
41  diffScaleSize_=0.05;
42  minWeight_=0.0;
43  useMultiHistogram_=false;
44  secondOrderScale_ = 0.01;
45  firstOrderScale_ = 0.99;
46  bIntegralHisto_=false;
47  m_dMaxRefHistoSize=DBL_MAX;
48  secondHistPos_[0]=0; secondHistPos_[1]=1;
49 }
50 
52 {
53  bIntegralHisto_ = bIntHisto;
54 }
55 
57 {
58 
59  // the process mean is the image center
60  processMean_=areaMax_ * 0.5;
61 
62  // this draws the sample to the image center a little
63  // its 99% the old position, 1% the mean
64  processFirstOrderScale_.Set(firstOrderScale_);
65 
66  // a second Order ARP, set scale to zero to have just a first order
67  // or set to 0.1 to have 10% second order and 90% first e.g.
68  processSecondOrderScale_.Set(secondOrderScale_);
69 
70  // and a diffusion
71  diffusionSigma_[0]= diffScale_ * areaMax_[0];
72  diffusionSigma_[1]= diffScale_ * areaMax_[1];
73 
74  diffusionSigma_[stateDim_-1] = diffScaleSize_ * areaMax_[stateDim_-1];
75 
76  //here set the percentage of pixels that are sampled
77  //with importanceFraction()
78  importanceFraction_ = 0.0;
79 }
80 
81 
82 
83 
84 //Here create uniform distribution of the samples
85 void CondensHisto::InitPriorPositions(unsigned int nrOfInitSamples)
86 {
87  // uniform distribution
88  for (unsigned int n=0; n<nrOfInitSamples; n++) {
89  for (unsigned int d=0;d<stateDim_;d++) {
90  samplePosNew_[n][d]=
91  random_.GetUniformDistributed(areaMin_[d],areaMax_[d]);
92  }
93  }
94 }
95 
97 {
98  double dist=0.0;
99  //here generate the Integral Histo Image
100  intHisto_.GenerateIntegralHistDiffBin(*img_,refHisto_.GetBinSize(),
101  refHisto_.GetBinSizeSat());
102 
103  BCDOUT(D_COND_INT,"in Integral EOD\n");
104  int width = (int)img_->GetWidth();
105  int height = (int)img_->GetHeight();
106 
107  int heightHalf = refHisto_.GetHeightROI()/2;
108  int widthHalf = refHisto_.GetWidthROI()/2;
109  //for each sample in samplePosNew_ compute the coords and
110  //CalcSimilarity between refHisto_ and IntegralHistoImage
111  int upperleftx,upperlefty,lowerrightx, lowerrighty;
112  int upperleftx2,upperlefty2,lowerrightx2, lowerrighty2;
113 
114  for(unsigned int x = 0; x<Nsamples_; x++){
115  BCDOUT(D_COND_PROCESS,"Sample Pos: "<<(int)samplePosNew_[x][0]<<
116  ","<<(int)samplePosNew_[x][1]<<std::endl);
117  //calculate coords for the comparison of the hists
118  //coord = pos - width-/heighthalf*sizefactor
119  upperleftx=
120  (int)rint(samplePosNew_[x][0]-widthHalf * samplePosNew_[x][2]);
121  upperlefty=
122  (int)rint(samplePosNew_[x][1]-heightHalf* samplePosNew_[x][2]);
123  lowerrightx=
124  (int)rint(samplePosNew_[x][0]+widthHalf* samplePosNew_[x][2]);
125  lowerrighty=
126  (int)rint(samplePosNew_[x][1]+heightHalf* samplePosNew_[x][2]);
127 
128  BCDOUT(D_COND_INT,"ROI: "<<upperleftx<<","<<upperlefty<<
129  ","<<lowerrightx<<","<<lowerrighty<<std::endl);
130 
131  // if coords out of image sample weight is 0
132  if((upperleftx>=width)||(upperleftx<0)||(upperlefty<0)
133  ||(upperlefty>=height)||(lowerrightx<0)
134  ||(lowerrightx>=width)||(lowerrighty<0)
135  ||(lowerrighty>=height) ||(samplePosNew_[x][2]<=0)
136  ||(samplePosNew_[x][2]> m_dMaxRefHistoSize)
137  ||(lowerrighty <= upperlefty)||(lowerrightx <= upperleftx)) {
138  sampleWeights_[x] = 0.0;
139  } else {
140  if (useMultiHistogram_) { // compute corners of second histogram
141  upperleftx2= upperleftx + int(secondHistPos_[0]*2)*widthHalf;
142  lowerrightx2=upperleftx2+ 2*widthHalf;
143  upperlefty2= upperlefty+ int(secondHistPos_[1]*2)*heightHalf;
144  lowerrighty2=upperlefty2+2*heightHalf;
145  }
146  if (useMultiHistogram_ &&
147  !((upperleftx2>=width)||(upperleftx2<0)||(upperlefty2<0)
148  ||(upperlefty2>=height)||(lowerrightx2<0)
149  ||(lowerrightx2>=width)||(lowerrighty2<0)
150  ||(lowerrighty2>=height)) )
151  dist=intHisto_.CalcSimilarity(refHisto_,upperleftx,upperlefty,
152  lowerrightx,lowerrighty,
153  refHisto2_,upperleftx2,upperlefty2,
154  lowerrightx2, lowerrighty2);
155  else
156  //compute similarity only from top histogram
157  dist=intHisto_.CalcSimilarity(refHisto_,upperleftx,upperlefty,
158  lowerrightx,lowerrighty);
159  }
160  BCDOUT(D_COND_PROCESS,"Distance of Histograms: "<<dist<<std::endl);
161  if(dist<minWeight_)
162  sampleWeights_[x] = minWeight_;
163  else
164  sampleWeights_[x] = dist;
165  }
166 }
167 
168 
169 /**
170  Here assign a weight to each sample. The weight must correspond
171  to the similarity of the histograms of the regions.
172 */
174 {
175  double dist = 0.0;
176 
177  std::vector<int> point;
178  point.assign(2,0);
179 
180  if(bIntegralHisto_){
181  EvaluateFromIntegralHistoImage_();
182  } else {
183  int heightHalf = refHisto_.GetHeightROI()/2;
184  int widthHalf = refHisto_.GetWidthROI()/2;
185 
186  //for each sample in samplePosNew_ generate a Histogram in the present
187  //picture and CalcSimilarity to the refHisto_
188  int upperleftx,upperlefty,lowerrightx, lowerrighty;
189  int upperleftx2,upperlefty2,lowerrightx2, lowerrighty2;
190  int width=img_->GetWidth();
191  int height=img_->GetHeight();
192  for(unsigned int x = 0; x<Nsamples_; x++){
193  BCDOUT(D_COND_PROCESS,"Sample Pos: "<<(int)samplePosNew_[x][0]<<
194  ","<<(int)samplePosNew_[x][1]<<std::endl);
195  //calculate coords for the comparison of the hists
196  //coord = pos - width-/heighthalf*sizefactor
197 
198  upperleftx=(int)(samplePosNew_[x][0]-widthHalf * samplePosNew_[x][2]);
199  upperlefty=(int)(samplePosNew_[x][1]-heightHalf* samplePosNew_[x][2]);
200  lowerrightx=(int)(samplePosNew_[x][0]+widthHalf* samplePosNew_[x][2]);
201  lowerrighty=(int)(samplePosNew_[x][1]+heightHalf* samplePosNew_[x][2]);
202 
203  BCDOUT(D_COND_DEBUG,"RIU: "<<upperleftx<<","<<upperlefty<<
204  ","<<lowerrightx<<","<<lowerrighty<<std::endl);
205  //if borders out of bounds, weight is zero
206  if ( upperleftx>=width || upperleftx<0 || upperlefty<0 ||
207  upperlefty>=height || lowerrightx<0 ||
208  lowerrightx>=width || lowerrighty<0 ||
209  lowerrighty>=height ) {
210  sampleWeights_[x] = 0;
211  } else {
212  if (useMultiHistogram_) { // compute corners of second histogram
213  upperleftx2= upperleftx + int(secondHistPos_[0]*2)*widthHalf;
214  lowerrightx2=upperleftx2+ 2*widthHalf;
215  upperlefty2= upperlefty+ int(secondHistPos_[1]*2)*heightHalf;
216  lowerrighty2=upperlefty2+2*heightHalf;
217  }
218  if (useMultiHistogram_ &&
219  !((upperleftx2>=width)||(upperleftx2<0)||(upperlefty2<0)
220  ||(upperlefty2>=height)||(lowerrightx2<0)
221  ||(lowerrightx2>=width)||(lowerrighty2<0)
222  ||(lowerrighty2>=height))
223  ) {
224  chist_.GenerateHist(*img_,upperleftx2, upperlefty2,
225  lowerrightx2, lowerrighty2);
226  dist = refHisto_.CalcSimilarity(chist_);
227  } else
228  dist=-1;
229  chist_.GenerateHist(*img_,upperleftx, upperlefty,
230  lowerrightx, lowerrighty);
231  if (dist<0) // only top histo
232  dist = refHisto_.CalcSimilarity(chist_);
233  else // compute for both histograms
234  dist = 0.5*dist+ 0.5*refHisto_.CalcSimilarity(chist_);
235  BCDOUT(D_COND_PROCESS,"Distance of Histograms: "<<dist<<std::endl);
236  }
237  if(dist<minWeight_)
238  sampleWeights_[x] = minWeight_;
239  else
240  sampleWeights_[x] = dist;
241  }//end for
242  }
243 
244 }//end function
245 
246 
247 //3-dim case
249 {
250  areaMin_=min;
251  areaMax_=max;
252 }
253 
254 void CondensHisto::CheckImageQuality(double percent, int &shutter, int &gain)
255 {
256 
257  int heightHalf = refHisto_.GetHeightROI()/2;
258  int widthHalf = refHisto_.GetWidthROI()/2;
259  unsigned int upperleftx,upperlefty,lowerrightx, lowerrighty;
260 
261  // histogram around mean, with mean size
262  upperleftx=(int)(mean_[0]-widthHalf * mean_[2]);
263  upperlefty=(int)(mean_[1]-heightHalf* mean_[2]);
264  lowerrightx=(int)(mean_[0]+widthHalf* mean_[2]);
265  lowerrighty=(int)(mean_[1]+heightHalf* mean_[2]);
266 
267 
268  if(!useMultiHistogram_)
269  {
270  BIASERR("Only implemented for Integral Histogram");
271  }
272  else if(bIntegralHisto_)
273  {
274  std::vector<int> roi;
275  roi.push_back(upperleftx);
276  roi.push_back(upperlefty);
277  roi.push_back(lowerrightx);
278  roi.push_back(lowerrighty);
279  Vector<int> hist = intHisto_.GetHistogram(upperleftx,upperlefty,
280  lowerrightx,lowerrighty);
281 
282  int nBinSat = intHisto_.GetBinSizeSat();
283  int nBinHue = intHisto_.GetBinSize();
284  int nLumStart = nBinSat * nBinHue;
285 
286  if(nBinHue == 8)
287  {
288 
289  double lowerLum =hist[nLumStart]+hist[nLumStart+1]+hist[nLumStart+2]+
290  hist[nLumStart+3];
291  double higherLum = hist[nLumStart+5]+hist[nLumStart+6]+
292  hist[nLumStart+7];
293  int numPixel = hist[nLumStart+8];
294  if(lowerLum / numPixel > percent)
295  {
296  cout<<"Luminance is low: increase!"<<endl;
297  shutter = 1;
298  }
299  else if(higherLum / numPixel > percent)
300  {
301  cout<<"Luminance is high: decrease!"<<endl;
302  shutter = -1;
303  }
304  }
305  else
306  {
307  BIASERR("Only implemented for binSizeHue==8");
308  }
309  }
310  else
311  {
312  BIASERR("Only implemented for Integral Histogram");
313  }
314 }
315 
316 
318 {
319  max.newsize(3);
320  int pos=0;
321  GetMaxWeight(pos);
322  max[0] = samplePosOld_[pos][0];
323  max[1] = samplePosOld_[pos][1];
324  max[2] = samplePosOld_[pos][2];
325 }
326 
327 
329 {
330  mean = mean_;
331 }
332 
333 /**
334  @param meanVar= MeanVariance is a vector of struct:
335  [varPosx, varPosy, varSize, varWeight]
336 */
338 {
339  meanVar.newsize(4);
340  double meanWeight = GetMeanWeight();
341  double varWeight=0.0, ddiff;
342 
343  Vector<double> diff, mVar;
344  mVar.newsize(3);
345  mVar.SetZero();
346  for(unsigned int i=0;i<Nsamples_;i++){
347  diff = samplePosOld_[i] - mean_;
348  mVar += diff.ElementwiseProduct(diff);
349  ddiff = (sampleWeights_[i]-meanWeight);
350  varWeight += (ddiff*ddiff);
351  }
352 
353  mVar/=double(Nsamples_-1);
354 
355  meanVar[0]=mVar[0];
356  meanVar[1]=mVar[1];
357  meanVar[2]=mVar[2];
358  meanVar[3]=varWeight/double(Nsamples_-1);
359 }
360 
361 /**
362  @return = the maximum weight of all samples
363  @param index = the index in samplePosNew_ where maxWeight is found
364 */
365 double CondensHisto::GetMaxWeight(int &index)
366 {
367  double maxWeight=0.0;
368  index = -1;
369  for(unsigned int i=0;i<Nsamples_;i++)
370  {
371  if(sampleWeights_[i] > maxWeight)
372  {
373  index = i;
374  maxWeight = sampleWeights_[i];
375  }
376  }
377  return maxWeight;
378 }
379 
380 
381 /**
382  @param maxVar= MaxVariance is a vector of struct:
383  [varPosx, varPosy, varSize, varWeight]
384 */
386 {
387  maxVar.newsize(4);
388  int index = 0;
389  double maxWeight = GetMaxWeight(index);
390  double varWeight=0.0, ddiff;
391 
392  Vector<double> max=samplePosOld_[index], var, diff;
393  var.newsize(3);
394  var.SetZero();
395  for(unsigned int i=0;i<Nsamples_;i++){
396  diff = samplePosOld_[i] - max;
397  var += diff.ElementwiseProduct(diff);
398  ddiff = (sampleWeights_[i]-maxWeight);
399  varWeight += (ddiff*ddiff);
400  }
401 
402  var/=double(Nsamples_-1);
403 
404  maxVar[0]=var[0];
405  maxVar[1]=var[1];
406  maxVar[2]=var[2];
407  maxVar[3]=varWeight/double(Nsamples_-1);
408 }
409 
410 
411 
412 
413 
414 //this returns the SamplePositions in an image!
415 //Does not overload GetSamplePositions() in Condensation.hh,
417 
418  float **imgData = sampleImg.GetImageDataArray();
419  unsigned int y,x;
420  for (unsigned int i =0;i<Nsamples_;i++){
421  y = (unsigned int)fabs(samplePosNew_[i][1]);
422  x = (unsigned int)fabs(samplePosNew_[i][0]);
423  imgData[y][x] = float(sampleWeights_[i]);
424  }
425 }
426 
427 /**
428  @return the active image in condensation algo
429 */
431 
432  return *img_;
433 }
434 
435 
437 {
438 
439  if (!img.IsEmpty()) img.Release();
440  img.Init(img_->GetWidth(),img_->GetHeight(),3);
441  // img.SetColorModel(ImageBase::CM_Grey);
442  img.FillImageWithConstValue((unsigned char)0);
443  unsigned int radius;
444  unsigned int histosize;
445  unsigned char values[1];//=new unsigned char[Nsamples_];
446  values[0]=255;
447  for (unsigned int i=0;i<Nsamples_;i++)
448  {
449 
450  histosize = 3*
451  (unsigned int)(samplePosNew_[i][2]*
452  sqrt(double(refHisto_.GetHeightROI()*
453  refHisto_.GetWidthROI())));
454 
455  radius = (unsigned int)(sampleWeights_[i]* Nsamples_ /
456  sumOfWeights_ + 0.5);
457 
458  if ( (samplePosNew_[i][0]-radius>0) && (samplePosNew_[i][1]-radius>0) &&
459  (samplePosNew_[i][0]+radius<img.GetWidth()) &&
460  (samplePosNew_[i][1]+radius<img.GetHeight()) )
462  (unsigned int)samplePosNew_[i][0],
463  img.GetHeight()-histosize,
464  radius, &values[0]);
465  }
466 
467 }
468 
469 
470 /**
471  draws the sample positions in the given image with the given value
472 */
474 {
475  if (img.IsEmpty()) {
476  img.Init(img_->GetWidth(),img_->GetHeight(),1);
478  }
479  unsigned char *values = new unsigned char[img.GetChannelCount()];
480  unsigned int size;
481  double maxWeight=0;
482 
483  for (unsigned int n=0;n<Nsamples_;n++)
484  if (sampleWeights_[n]>maxWeight) maxWeight=sampleWeights_[n];
485  for (unsigned int n=0;n<Nsamples_;n++) {
486  for (unsigned int c=0;c<img.GetChannelCount();c++)
487  values[c]=(unsigned char)(sampleWeights_[n]/maxWeight*255.0+0.5);
488 
489  size=(unsigned int)(samplePosNew_[n][2]*double(refHisto_.GetHeightROI()));
490  if (size<=0) size=5;
491  if ( (samplePosNew_[n][0]-size/2>0) &&
492  (samplePosNew_[n][1]-size/2>0) &&
493  (samplePosNew_[n][0]+size/2<img.GetWidth()) &&
494  (samplePosNew_[n][1]+size/2<img.GetHeight()) )
495  ImageDraw<unsigned char>::RectangleCenter(img,int(samplePosNew_[n][0]),
496  int(samplePosNew_[n][1]),
497  size, values);
498 
499  }
500  delete values;
501 }
502 
503 /**
504  draws the sample positions in the given image with the given value
505 */
507 {
508  if (img.IsEmpty()) {
509  img.Init(img_->GetWidth(),img_->GetHeight(),1);
511  }
512  img.FillImageWithConstValue(255);
513 
514  unsigned char *values = new unsigned char[img.GetChannelCount()];
515  unsigned int size;
516  double maxWeight=0;
517  unsigned int maxSampleIndex = 0;
518  for (unsigned int n=0;n<Nsamples_;n++)
519  {
520  if (sampleWeights_[n]>maxWeight){
521  maxSampleIndex = n;//save max sample index
522  maxWeight=sampleWeights_[n];
523  }
524  }
525  for (unsigned int n=0;n<Nsamples_;n++)
526  {
527  size= (unsigned int)(samplePosNew_[n][2]*double(refHisto_.GetHeightROI()));
528  if (size<=0) size=5;
529  if ( (samplePosNew_[n][0]-size/2>0) &&
530  (samplePosNew_[n][1]-size/2>0) &&
531  (samplePosNew_[n][0]+size/2<img.GetWidth()) &&
532  (samplePosNew_[n][1]+size/2<img.GetHeight()) )
533  {
534  if(n==maxSampleIndex)
535  {
536  values[0] = (unsigned char)0;
537  values[1] = (unsigned char)0;
538  values[2] = (unsigned char)0;
539  }
540  else{
541  values[0] = (unsigned char)100;
542  values[1] = (unsigned char)100;
543  values[2] = (unsigned char)100;
544  }
545  ImageDraw<unsigned char>::RectangleCenter(img,int(samplePosNew_[n][0]),
546  int(samplePosNew_[n][1]),
547  size, values);
548  }
549  }
550  //draw the last with max value again on top
551  values[0] = (unsigned char)0;
552  values[1] = (unsigned char)0;
553  values[2] = (unsigned char)0;
554  size= (unsigned int)(samplePosNew_[maxSampleIndex][2]*
555  double(refHisto_.GetHeightROI()));
557  int(samplePosNew_[maxSampleIndex][0]),
558  int(samplePosNew_[maxSampleIndex][1]),
559  size, values);
560  delete values;
561 }
562 
564 {
565  unsigned char *values = new unsigned char[img.GetChannelCount()];
566  unsigned int size;
567  double maxWeight=0;
568  for (unsigned int n=0;n<Nsamples_;n++)
569  if (sampleWeights_[n]>maxWeight) maxWeight=sampleWeights_[n];
570  for (unsigned int n=0;n<Nsamples_;n++) {
571  for (unsigned int c=0;c<img.GetChannelCount();c++)
572  values[c]=(unsigned char)(sampleWeights_[n]/maxWeight*255.0);
573  size= (unsigned int)(samplePosNew_[n][2]*refHisto_.GetHeightROI());
574  if (size<=0) size=5;
575  if ( (samplePosNew_[n][0]-size/2>0) &&
576  (samplePosNew_[n][1]-size/2>0) &&
577  (samplePosNew_[n][0]+size/2<img.GetWidth()) &&
578  (samplePosNew_[n][1]+size/2<img.GetHeight()) )
580  (unsigned int)samplePosNew_[n][0],
581  (unsigned int)samplePosNew_[n][1],
582  size, values);
583  }
584 
585  delete values;
586 }
587 
588 
589 
590 /**
591  draws the samples in the positions
592  and draws the weights of the samples as circles,
593  the bigger the circle the higher the weight
594  and the grey value indicates the size of the ROI of histogram
595 */
597 {
598  if (!img.IsEmpty()) img.Release();
599  img.Init(img_->GetWidth(),img_->GetHeight(),1);
601  img.FillImageWithConstValue((float)0);
602  unsigned int radius;
603  float *values=new float[Nsamples_];
604 
605  for (unsigned int i=0;i<Nsamples_;i++) {
606  //samplePosOld_[stateDim_-1] hold distance to object
607  values[i]=float(samplePosOld_[i][stateDim_-1]);
608  radius = (unsigned int)(sampleWeights_[i]* Nsamples_ /
609  sumOfWeights_ + 0.5);
610 
611  if ( (samplePosOld_[i][0]-radius>0) && (samplePosOld_[i][1]-radius>0) &&
612  (samplePosOld_[i][0]+radius<img.GetWidth()) &&
613  (samplePosOld_[i][1]+radius<img.GetHeight()) )
615  (unsigned int)samplePosOld_[i][0],
616  (unsigned int)samplePosOld_[i][1],
617  radius, &values[i]);
618  }
619  delete[] values;
620 }
621 
622 /**
623  draws the poserior distribution of the samples in the image
624 */
626 {
627  if (fImg_.IsEmpty())
628  fImg_.Init(img.GetWidth(), img.GetHeight(),1);
629 
630  double max = DrawPosteriorDistribution(fImg_);
631 
632  float *pixel;
633  // now copy values into result img.
634  pixel = fImg_.GetImageData();
635  unsigned char *data= img.GetImageData();
636  unsigned int size=img.GetPixelCount();
637  for (unsigned int i=0;i<size;i++) {
638  *data = (unsigned char)(*pixel / max * 255.0);
639  data++;
640  pixel++;
641  }
642 }
643 
644 
645 /**
646  same as above but in grey value picture
647 */
649 {
650  float max=0;
651  float *pixel;
652  double x,y,dx,dy;
653  int width=img.GetWidth() ,height=img.GetHeight();
654  img.FillImageWithConstValue((float)0);
655  for (unsigned int i=0;i<Nsamples_;i++) {
656  x = samplePosOld_[i][0];
657  y = samplePosOld_[i][1];
658 
659  if ( (x>0) && (y>0) &&
660  (x<width-1) && (y<height-1) ) {
661  pixel= (img.GetImageDataArray()[(int)y])+ (int)x;
662  // inverse bilinear interpolation
663  dx = x - (double)floor(x); dy = y - (double)floor(y);
664  // top left
665  *pixel+= float((1-dx) * (1-dy) * sampleWeights_[i]);
666  if (*pixel>max) max=*pixel;
667  // top right
668  pixel++;
669  *pixel+= float((1-dy) * dx * sampleWeights_[i]);
670  if (*pixel>max) max=*pixel;
671  // bottom right
672  pixel+=width;
673  *pixel+= float(dx * dy * sampleWeights_[i]);
674  if (*pixel>max) max=*pixel;
675  // bottom left
676  pixel--;
677  *pixel+= float((1-dx) * dy * sampleWeights_[i]);
678  if (*pixel>max) max=*pixel;
679  }
680  }
681  return max;
682 }
683 
684 /**
685  draws the mean value(mean position of all samples) in
686  the image, with the size of the rectangle indicating
687  the size of the histogram
688 */
690 {
691 #ifdef DEBUG
692  cout<<"Mean: "<<mean_[0]<<","<<mean_[1]<<","<<mean_[2]<<endl;
693 
694  std::vector<double> point;
695  refMultiHisto_.GetDistROIs(point);//now dist in point
696  point[0] = mean_[0]+point[0]*mean_[2];
697  point[1] = mean_[1]+point[1]*mean_[2];
698  cout<<"In Draw, Point: "<<point[0]<<","<<point[1]<<endl;
699 #endif
700  //draw first rectangle
701  int upperleftx,upperlefty,lowerrightx, lowerrighty;
702  int upperleftx2,upperlefty2,lowerrightx2, lowerrighty2;
703  float i=float(mean_[2]*((refHisto_.GetHeightROI()+
704  refHisto_.GetWidthROI())/2));
705  if (i<=0) return;
706 
707  int heightHalf = int(double(refHisto_.GetHeightROI())/2.0 * mean_[2] + 0.5);
708  int widthHalf = int(double(refHisto_.GetWidthROI())/2.0 * mean_[2] + 0.5);
709  upperleftx=
710  (int)rint(mean_[0]-widthHalf);
711  upperlefty=
712  (int)rint(mean_[1]-heightHalf);
713  lowerrightx=
714  (int)rint(mean_[0]+widthHalf);
715  lowerrighty=
716  (int)rint(mean_[1]+heightHalf);
717 
718  // cout<<"Image Dimensions in Draw: "<<img.GetWidth()<<","<<img.GetHeight()
719  // <<endl;
720 
721  if ((upperleftx>0) && (upperlefty>0) && (lowerrightx<(int)img.GetWidth()) &&
722  lowerrighty<(int)img.GetHeight())
723  {
724  ImageDraw<unsigned char>::RectangleCorners(img,upperleftx,upperlefty,
725  lowerrightx,lowerrighty);
726  ImageDraw<unsigned char>::RectangleCorners(img,upperleftx-1,upperlefty-1,
727  lowerrightx-1,lowerrighty-1);
728  ImageDraw<unsigned char>::RectangleCorners(img,upperleftx+1,upperlefty+1,
729  lowerrightx+1,lowerrighty+1);
730  }
731 
732  if(useMultiHistogram_){
733  upperleftx2= upperleftx + (int)(secondHistPos_[0]*2*widthHalf);
734  lowerrightx2=upperleftx2+ 2*widthHalf;
735  upperlefty2= upperlefty+ (int)(secondHistPos_[1]*2*heightHalf);
736  lowerrighty2=upperlefty2+2*heightHalf;
737 
738  //draw second rectangle
739  if ((upperleftx2>0) && (upperlefty2>0) &&
740  (lowerrightx2<(int)img.GetWidth()) &&
741  lowerrighty2<(int)img.GetHeight())
742  ImageDraw<unsigned char>::RectangleCorners(img,upperleftx2,upperlefty2,
743  lowerrightx2,lowerrighty2);
744  }
745 }
746 
void Release()
reimplemented from ImageBase
Definition: Image.cpp:1579
void UseIntegralHistogram(bool bIntHisto)
gray values, 1 channel
Definition: ImageBase.hh:130
virtual void DrawSamplesWhite(Image< unsigned char > &img)
this draws the sample weights as retangeles with greyvalues on white base
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
void ElementwiseProduct(const Vector< T > &arg, Vector< T > &dest) const
multiply this with arg elementwise and store the result in dest
Definition: Vector.hh:491
virtual void EvaluateObservationDensities()
Here assign a weight to each sample.
void GetMaxVariance(Vector< double > &maxVar)
void GetMeanVariance(Vector< double > &meanVar)
CondensHisto()
Set the state dimension in the constructor.
void DrawSamplesExt(Image< unsigned char > &img)
this draws the samples, histogram sizes as rects and weights as grey values
unsigned int GetWidth() const
Definition: ImageBase.hh:312
void SetZero()
equivalent to matrix call
Definition: Vector.hh:156
static int RectangleCorners(Image< StorageType > &im, const int minx, const int miny, const int maxx, const int maxy, const StorageType value[])
rectangles
Definition: ImageDraw.cpp:94
static int CircleCenter(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[]=NULL)
draws a circular line, either using Value or a good contrast value
Definition: ImageDraw.cpp:977
Vector< T > & newsize(Subscript N)
Definition: vec.h:220
void DrawWeightedSamples(Image< float > &img)
this draws the samples as circles and the color indicates the size of the histogram (the z-coordinate...
virtual void DrawMean(BIAS::Image< unsigned char > &img)
Draws the mean as a rectangle which size is proportional to the histogram size.
virtual void InitModelDefaults()
Here u can specify the model and process defaults.
void SetArea(Vector3< double > min, Vector3< double > max)
The area for the initial uniform distribution.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
Image< unsigned char > GetAktImage()
unsigned int GetHeight() const
Definition: ImageBase.hh:319
void FillImageWithConstValue(StorageType Value)
fill grey images
Definition: Image.cpp:456
static int RectangleCenter(Image< StorageType > &im, const int x, const int y, const int size, const StorageType value[])
Draws the rectangle around X, Y with Size and Value[i] in channel i.
Definition: ImageDraw.cpp:284
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
Definition: Image.cpp:421
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
void GetMeanValue(Vector< double > &mean)
virtual void InitPriorPositions(unsigned int nrOfInitSamples)
The Prior condition is used to init the first sample positions.
void DrawPosteriorDistribution(BIAS::Image< unsigned char > &img)
Draws the samples with their weight as greyvalue, the weight is distributed to the 4 pixels around th...
void GetMaxValue(Vector< double > &max)
double GetMaxWeight(int &index)
void EvaluateFromIntegralHistoImage_()
drawing simple entities into the image like rectangles or lines As all functions are static they have...
Definition: ImageDraw.hh:72
void DrawHistoSizes(Image< unsigned char > &img)
this draws the Sizes of the Histogram as arrows at their x position
unsigned long int GetPixelCount() const
returns number of pixels in image
Definition: ImageBase.hh:422
void CheckImageQuality(double percent, int &shutter, int &gain)
Checks the image Quality by checking the luminance of the image.
const std::vector< BIAS::Vector< double > > & GetSamplePositions()
virtual void DrawSamples(Image< unsigned char > &img)
this draws the sample weights as circles
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153