26 #include "CondensImg.hh"
27 #include <Base/ImageUtils/ImageDraw.hh>
35 processMean_=areaMax_ * 0.5;
39 processFirstOrderScale_.Set(0.99);
43 processSecondOrderScale_.Set(.9);
46 diffusionSigma_=0.01 * areaMax_;
48 importanceFraction_ = 0.0;
50 defaultInitFraction_=0.05;
57 for (
unsigned int n=0; n<nrOfInitSamples; n++)
58 for (
unsigned int d=0;d<stateDim_;d++) {
60 random_.GetUniformDistributed(areaMin_[d],areaMax_[d]);
68 for (
unsigned int n=0;n<Nsamples_;n++) {
71 if ((samplePosNew_[n][0]>0) &&
72 (samplePosNew_[n][0]<= (
double)obsImg_.GetWidth()) &&
73 (samplePosNew_[n][1]>0) &&
74 (samplePosNew_[n][1]<= (double)obsImg_.GetHeight()) ) {
76 (double)(obsImg_.GetImageDataArray()[(int)samplePosNew_[n][1]][(
int)samplePosNew_[n][0]]);
85 for (
unsigned int n=0; n<Nsamples_; n++)
86 if ( (samplePosOld_[n][0]>areaMin_[0]) &&
87 (samplePosOld_[n][1]>areaMin_[1]) &&
88 (samplePosOld_[n][0]<areaMax_[0]/2) &&
89 (samplePosOld_[n][1]<areaMax_[1]) )
90 sampleImportanceWeights_[n]=255;
91 else sampleImportanceWeights_[n]=0;
109 img.
Init(obsImg_.GetWidth(),obsImg_.GetHeight(),1);
113 unsigned char values[1];
114 for (
unsigned int i=0;i<Nsamples_;i++) {
116 radius = (
unsigned int)(sampleWeights_[i]* Nsamples_ /
117 sumOfWeights_ + 0.5);
120 if ( (samplePosOld_[i][0]-radius>0) && (samplePosOld_[i][1]-radius>0) &&
121 (samplePosOld_[i][0]+radius<img.
GetWidth()) &&
122 (samplePosOld_[i][1]+radius<img.
GetHeight()) )
124 (
unsigned int)samplePosOld_[i][0],
125 (
unsigned int)samplePosOld_[i][1],
136 double max = DrawPosteriorDistribution(fImg_);
140 pixel = fImg_.GetImageData();
143 for (
unsigned int i=0;i<size;i++) {
144 *data = (
unsigned char)(*pixel / max * 255.0);
160 for (
unsigned int i=0;i<Nsamples_;i++) {
161 x = samplePosOld_[i][0];
162 y = samplePosOld_[i][1];
164 if ( (x>0) && (y>0) &&
165 (x<width-1) && (y<height-1) ) {
168 dx = x - (double)floor(x); dy = y - (double)floor(y);
170 *pixel+= float((1-dx) * (1-dy) * sampleWeights_[i]);
171 if (*pixel>max) max=*pixel;
174 *pixel+= float((1-dy) * dx * sampleWeights_[i]);
175 if (*pixel>max) max=*pixel;
178 *pixel+= float(dx * dy * sampleWeights_[i]);
179 if (*pixel>max) max=*pixel;
182 *pixel+= float((1-dx) * dy * sampleWeights_[i]);
183 if (*pixel>max) max=*pixel;
194 for (
unsigned int n=0;n<Nsamples_;n++) {
195 diff = samplePosOld_[n] - mean_;
198 var /= sumOfWeights_;
201 (
int)(mean_[1]), (
int)(mean_[0]+var),
202 (
int)(mean_[1]),255);
204 (
int)(mean_[0]), (
int)(mean_[1] + var), 255);
T ScalarProduct(const Vector< T > &argvec) const
scalar product (inner product) of two vectors returning a scalr
void Release()
reimplemented from ImageBase
void DrawSamples(Image< unsigned char > &img, unsigned char value=255)
this draws the sample weights as circles
virtual void InitPriorPositions(unsigned int nrOfInitSamples)
The Prior condition is used to init the first sample positions.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
virtual void EvaluateObservationDensities()
most important function, here u have to calculate a probability for each sample position based on you...
void SetColorModel(EColorModel Model)
unsigned int GetWidth() const
virtual void InitModelDefaults()
Here u can specify the model and process defaults.
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
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 SetArea(Vector2< double > min, Vector2< double > max)
The area for the initial uniform distribution.
void SetObservation(Image< unsigned char > &osbImg)
converts to Image<float> and calls the function above
unsigned int GetHeight() const
void DrawMean(BIAS::Image< unsigned char > &img)
Draws the mean as a cross, which size is proportional to the variance.
static int LineGrey(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value)
faster algorithm for 1 channel images
void FillImageWithConstValue(StorageType Value)
fill grey images
virtual void EvaluateImportanceWeights()
If you want to use importance sampling, then overload this function, which is the importance function...
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
unsigned long int GetPixelCount() const
returns number of pixels in image
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase