Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CondensHisto.hh
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 Sredistribute 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 #ifndef _HISTO_CONDENSATION__HH_
27 #define _HISTO_CONDENSATION__HH_
28 
29 #include <bias_config.h>
30 
31 // BIAS
32 #include <StateEstimator/Condensation.hh>
33 #include <Base/Image/Image.hh>
34 #include <Base/Math/Vector2.hh>
35 #include <Base/Math/Vector3.hh>
36 #include <Image/ColorHistogram.hh>
37 #include <Image/IntegralHistogram.hh>
38 
39 #define D_COND_INT (1<<6)
40 
41 namespace BIAS{
42 
43  /**
44  @class CondensHisto
45  @ingroup g_stateestimation
46  @brief class for tracking an object in an image
47 
48  This class is able to handle "normal" ColorHistograms, and
49  MultiColorHistograms.
50  Just Set a MultiColorHistogram in SetReferenceHistogram() and
51  the whole process switches to multiHistogram processing
52 
53  You have to call:
54  - SetActiveImage(imgHSL) with an HSL image;
55  - SetReferenceHistogram(chist); (colorHistogram or ColorMultiHistogram)
56  - SetArea(Vector3<double>(0,0,0.5), Vector3<double>(width,height,1.5));
57 
58  - Init(*nsamples);
59  - InitPrior(); //to set samples for first frame
60 
61  then just call these functions in every turn
62  - SetActiveImage(imgHSL)
63  - PredictNewSamplePositions()
64  - Process();
65  @author Ingo Schiller, March 2003, edited by grest
66  */
67  class BIASStateEstimator_EXPORT CondensHisto : public Condensation{
68  public:
69  /**
70  Set the state dimension in the constructor
71  */
72  CondensHisto();
73 
74  virtual void InitModelDefaults();
75 
76  virtual void InitPriorPositions(unsigned int nrOfInitSamples);
77 
78  virtual void EvaluateObservationDensities();
79 
80  // virtual void EvaluateImportanceWeights();
81 
82  void UseIntegralHistogram(bool bIntHisto);
83 
84  /**
85  Checks the image Quality by checking the luminance
86  of the image.
87  the shutter and gain of the camera has to be set
88  by the returned shutter and gain in params
89  @param percent = the allowed percentage of pixels, below minsat in
90  light and dark regions
91  @param shutter = the shutter the camera has to be set to
92  @param gain = the gain ------------ ------------
93  */
94  void CheckImageQuality(double percent, int &shutter, int &gain);
95 
96  /** The area for the initial uniform distribution.
97  3-dim case
98  */
99  void SetArea(Vector3<double> min, Vector3<double> max);
100 
101  /**
102  Sets the minimum weight each sample is assigned,
103  when < lower minWeight_
104  */
105  inline void SetMinWeight(double min)
106  {minWeight_ = min;}
107 
108  /**
109  Sets the scale for the diffusion,
110  diffusi0nSigma = diffScale_*areaMax_
111  example value would be 0.05
112  */
113  inline void SetDiffScale(double diff)
114  {
115  diffScale_ = diff;
116  diffusionSigma_[0] = diffScale_*areaMax_[0];
117  diffusionSigma_[1] = diffScale_*areaMax_[1];
118  }
119 
120  /**
121  Sets the scale for the diffusion for the size
122  of the histogram ,
123  diffusionSigma[stateDim_-1] = diffScaleSize_*areaMax_[stateDim-1]
124  example value would be 0.05
125  */
126  inline void SetDiffScaleSize(double diff)
127  {
128  diffScaleSize_= diff;
129  diffusionSigma_[stateDim_-1]= diffScaleSize_*areaMax_[stateDim_-1];
130  }
131 
132 
133  /**
134  Sets the scale for the second order prediction,
135  valid values are 0.0000..1 - 1.0
136  */
137  inline void SetSecondOrderScale(double scale)
138  {
139  if(scale > 1.0)
140  scale = 1.0;
141  else if(scale < 0)
142  scale = 0.0;
143  secondOrderScale_ = scale;
144  processSecondOrderScale_.Set(secondOrderScale_);
145  }
146 
147  /**
148  Sets the scale for the first order prediction,
149  valid values are 0.0000..1 - 1.0
150  */
151  inline void SetFirstOrderScale(double scale)
152  {
153  if(scale > 1.0)
154  scale = 1.0;
155  else if(scale < 0)
156  scale = 0.0;
157  firstOrderScale_ = scale;
158  processFirstOrderScale_.Set(firstOrderScale_);
159  }
160 
161 
162 
163  /** sets the present picture to compare and create new observation */
165  {img_ = &img;}
166 
167  /** sets the reference colorhistogram */
168  inline
170  {
171  if(img_ != NULL){
172  refHisto_=refHisto;
173  m_dMaxRefHistoSize = double(img_->GetWidth() * img_->GetHeight())/
174  double(refHisto.GetHeightROI() * refHisto.GetWidthROI());
175  chist_.SetBinSize(refHisto_.GetBinSize(), refHisto_.GetBinSizeSat());
176  useMultiHistogram_ = false;
177  // cout<<"Using Normal Histogram"<<endl;
178  }
179  else{
180  BIASERR("No actual image, can not net reference histogram.")
181  }
182  }
183 
184  /** sets if Multihistogram is used or not, default is false */
185  inline
186  void SetMultiHistogram(bool multi)
187  {useMultiHistogram_ = multi;}
188 
189 
190 
191 
192  /* at every (rounded) sample position, the sampleImg is set
193  to UCHAR_MAX */
194  void GetSamplePositions(Image<float> &sampleImg);
195 
196  /*
197  @returns the actual position of the mean value
198  @author Ingo Schiller
199  @modified 03. August 2004
200  */
201  void GetMeanValue(Vector<double> &mean);
202 
203 
204  /*
205  @returns the actual position of the sample, with max weight
206  @author Ingo Schiller
207  @modified 29.11.04
208  */
209  void GetMaxValue(Vector<double> &max);
210 
211  /**
212  @param meanVar= MeanVariance is a vector of struct:
213  [varPosx, varPosy, varSize, varWeight]
214  */
215  void GetMeanVariance(Vector<double> &meanVar);
216 
217  /**
218  @param maxVar= MaxVariance is a vector of struct:
219  [varPosx, varPosy, varSize, varWeight]
220  */
221  void GetMaxVariance(Vector<double> &maxVar);
222 
223 
224  /**
225  @return = the maximum weight of all samples;
226  @param index = the index of which maxWeight is found
227  */
228  double GetMaxWeight(int &index);
229 
230 
231  /**
232  @returns the aktual image on which the condensation is
233  doing it's job
234  @author Ingo Schiller
235  */
236  Image<unsigned char> GetAktImage();
237 
238 
239  /**
240  this draws the Sizes of the Histogram
241  as arrows at their x position
242  @author Ingo Schiler
243  */
244  void DrawHistoSizes(Image<unsigned char> &img);
245 
246  /** this draws the sample weights as circles
247  */
248  virtual void DrawSamples(Image<unsigned char> &img);
249 
250  /**
251  this draws the sample weights as retangeles with greyvalues
252  on white base
253  */
254  virtual void DrawSamplesWhite(Image<unsigned char> &img);
255 
256  /** this draws the samples,
257  histogram sizes as rects and weights as grey values
258  @author grest / schiller
259  */
260  void DrawSamplesExt(Image<unsigned char> &img);
261 
262  /** this draws the samples as circles and the color indicates the
263  size of the histogram (the z-coordinate)
264  */
265  void DrawWeightedSamples(Image<float> &img);
266 
267  /** Draws the samples with their weight as greyvalue,
268  the weight is distributed to the 4 pixels around the sample postion.
269  Image has to be initialized with correct size and channelcount !
270  */
271  void DrawPosteriorDistribution(BIAS::Image<unsigned char> &img);
272 
273  /** same as above but float precision and
274  returns the maximum value also.
275  */
276  double DrawPosteriorDistribution(BIAS::Image<float> &img);
277 
278 
279  /** Draws the mean as a rectangle
280  which size is proportional to the histogram size
281  */
282  virtual void DrawMean(BIAS::Image<unsigned char> &img);
283 
284  protected:
285  // for better readablity of EvaluateObservationDensities()
286  void EvaluateFromIntegralHistoImage_();
287 
290 
291  // the current histogram for comparision with the old one
293 
294  //the integral Histogram image
296 
297  //reference ColorHistogram
300 
301  // needed for DrawPosteriorDistribution()
303  //basic weight of each sample to provide a wider spread of the samples
304  double minWeight_;
305  double diffScale_;
311 
312  //relative to first hist, unit is first hist size
314 
316  };
317 
318 
319 
320 }
321 #endif
void SetFirstOrderScale(double scale)
Sets the scale for the first order prediction, valid values are 0.0000..1 - 1.0.
IntegralHistogram intHisto_
Image< unsigned char > * img_
CONDENSATION (CONditional DENSity EstimATION) is a state estimator very similiar to the Kalman Filter...
Definition: Condensation.hh:81
ColorHistogram< unsigned char > refHisto2_
void SetSecondOrderScale(double scale)
Sets the scale for the second order prediction, valid values are 0.0000..1 - 1.0. ...
void SetReferenceHistogram(ColorHistogram< unsigned char > &refHisto)
sets the reference colorhistogram
ColorHistogram< unsigned char > refHisto_
void SetMinWeight(double min)
Sets the minimum weight each sample is assigned, when &lt; lower minWeight_.
ColorHistogram< unsigned char > chist_
int SetBinSize(int binsize)
set the binsize (must be divideable by 2pown)
void SetMultiHistogram(bool multi)
sets if Multihistogram is used or not, default is false
BIAS::Vector3< double > areaMin_
void SetActiveImage(Image< unsigned char > &img)
sets the present picture to compare and create new observation
class for tracking an object in an image
Definition: CondensHisto.hh:67
BIAS::Vector2< double > secondHistPos_
BIAS::Image< float > fImg_
This Class handels Integral Histograms on HSL Images It represents an integral image histogram and of...
void SetDiffScale(double diff)
Sets the scale for the diffusion, diffusi0nSigma = diffScale_*areaMax_ example value would be 0...
void SetDiffScaleSize(double diff)
Sets the scale for the diffusion for the size of the histogram , diffusionSigma[stateDim_-1] = diffSc...