Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCondensImg.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 /** @example ExampleCondensImg.cpp
26  @relates CondensImg
27  @ingroup g_examples
28  @ingroup g_stateestimation
29  @brief This example writes some images, which show the observations made
30  for each time step and the position and weights of the samples.
31  The observations are such that on the left a real observation,
32  where the random position of the Gauss on the right is like a
33  false measurement.
34  @author MIP
35 */
36 
37 
38 #include "../CondensImg.hh"
39 #include "Base/ImageUtils/ImageDraw.hh"
40 #include "Base/Image/ImageIO.hh"
41 
42 
43 using namespace BIAS;
44 using namespace std;
45 
46 
47 //int main(int argc, char** argv)
48 int main()
49 {
50  BIAS::Random random;
51 
52  // the CondensImg is just one example of the Condensation
53  // it is necessary to overload specific functions of Condensation
54  CondensImg condensation;
55 
56 
57  // condensation.SetDebugLevel(D_COND_WEIGHTS);
58  // condensation.SetDebugLevel(condensation.GetDebugLevel() | D_COND_INIT);
59  // condensation.SetDebugLevel(condensation.GetDebugLevel() | D_COND_PROCESS);
60 
61  Image<unsigned char> observation, drawImg;
62  observation.Init(320,240,1);
63  observation.SetColorModel(ImageBase::CM_Grey);
64  condensation.SetArea(Vector2<double>(0,0), Vector2<double>(320,240));
65  condensation.Init(500); // the nr. of samples
66 
67  condensation.InitPrior();
68 
69  // uncomment to use importance sampling:
70  // condensation.SetImportanceFraction(0.4);
71 
72  char fileName[255];
73  int n=0,iterations=20;
74  int x=50,y=50,x2=250,y2=200;
75  Vector<double> mean;
76  while (n<iterations) {
77  mean=condensation.GetMean();
78  cout<<"Iteration: "<<n<< "/"<<iterations
79  <<" Mean State: "<<mean[0]<<","<<mean[1]<<endl;
80 
81  condensation.PredictNewSamplePositions();
82 
83  observation.FillImageWithConstValue(5);
84  y2=random.GetUniformDistributedInt(50,200);
85  if (n<10 || n>13) { // three times no observation
87  x, y, 20, 100);
89  x2, y2, 20, 255);
90  }
91  y+=10;
92 
93  // the image 'observation' is the distribution p(Z|X)
94  // the observations can be modelled by any
95  condensation.SetObservation(observation);
96  sprintf(fileName,"observationImage_%04d",n);
97  //ImageIO::Save(fileName,observation);
98  ImageIO::Save(fileName,observation);
99 
100  condensation.DrawSamples(drawImg);
101  sprintf(fileName,"sampleImage_%04d",n);
102  //ImageIO::Save(fileName,drawImg);
103  ImageIO::Save(fileName,drawImg);
104 
105  // here ur overloaded functions are called
106  condensation.Process();
107  n++;
108  }
109 }
void DrawSamples(Image< unsigned char > &img, unsigned char value=255)
this draws the sample weights as circles
Definition: CondensImg.cpp:106
int InitPrior()
sets the sample positions for first time step
int Init(unsigned int nrSmaples)
Init the Condensation directly after constructor, with the desired amount of Samples, there more the better the approximation of the real densities.
gray values, 1 channel
Definition: ImageBase.hh:130
void Process()
This really does one iteration of Condensation.
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
int GetUniformDistributedInt(const int min, const int max)
get uniform distributed random variable including min/max
Definition: Random.cpp:139
Vector< double > GetMean()
returns the mean state of the density distribution
void SetArea(Vector2< double > min, Vector2< double > max)
The area for the initial uniform distribution.
Definition: CondensImg.cpp:94
void SetObservation(Image< unsigned char > &osbImg)
converts to Image&lt;float&gt; and calls the function above
Definition: CondensImg.cpp:101
static int RectangleCenterGreyFill(Image< StorageType > &im, const int x, const int y, const int size, const StorageType value)
Definition: ImageDraw.cpp:328
void FillImageWithConstValue(StorageType Value)
fill grey images
Definition: Image.cpp:456
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
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
example class for condensation with a 2-dim state vector.
Definition: CondensImg.hh:44
class for producing random numbers from different distributions
Definition: Random.hh:51