Skip to content

Instantly share code, notes, and snippets.

@niorko
Created February 7, 2018 09:36
Show Gist options
  • Save niorko/fbd94905a8b1631c0279828c27c03d72 to your computer and use it in GitHub Desktop.
Save niorko/fbd94905a8b1631c0279828c27c03d72 to your computer and use it in GitHub Desktop.
ViBe C like gist
// fixed parameters for ViBe
// number of samples per pixel
Int N=20;
// radius of the sphere
Int R=20;
// number of close samples for being
// part of the background (bg)
Int ♯min=2;
// amount of random subsampling
Int ϕ=16;
// data
Int width, height;
// current image
byte image[width][height];
// background model
byte samples[width][height][N];
// background/foreground segmentation map
byte segMap[width][height];
// background and foreground identifiers
byte background=0;
byte foreground=255;
// for each pixel
for (int x=0;x<width;x++){
for (int y=0;y<height;y++){
// 1. Compare pixel to background model
Int count=0,index=0,dist=0;
while ((count<♯min)&&(index<N)){
// Euclidean distance computation
dist=EuclidDist(image[x][y]
samples[x][y][index]);
if (dist<R) {
count++;
}
index++;
}
// 2. Classify pixel and update model
if (count>=♯min){
// store that image[x][y] ∈ background
segMap[x][y]=background;
// 3. Update current pixel model
// get random number between 0 and ϕ−1
Int rand=getRandomNumber(0,ϕ−1);
if (rand==0){ // random subsampling
// replace randomly chosen sample
rand=getRandomNumber(0,N−1);
samples[x][y][rand] = image[x][y];
}
// 4. Update neighboring pixel model
rand=getRandomNumber(0,ϕ−1);
if (rand==0) { // random subsampling
// choose neighboring pixel randomly
Int xNG,yNG;
xNG= getRandomNeighbrXCoordinate(x);
yNG= getRandomNeighbrYCoordinate(y);
// replace randomly chosen sample
rand=getRandomNumber(0,N−1);
samples[xNG][yNG][rand]=image[x][y];
}
}
else {//count<♯min
// store that image[x][y] ∈ foreground
segMap[x][y] = foreground;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment