VIBE 算法
论文参考 ViBe: a universal background subtraction algorithm for video sequences
算法思想:
- 记录一系列历史像素背景的样本集
- 将当前像素与历史像素比较,得出相近的数目count
- 用阈值与count比较,分类得出前景与背景
- 随机更新背景与背景邻域
算法常量:
- N=20, 每个像素的抽样数
- R=20, 球的半径
-
#min
=2, 成为背景的相近样本数,在算法代码中记为$#_min=$
-
ϕ
=16, 随机二次抽样数,在算法代码中记为$\phi$
算法变量:
- width,height 输入图像的宽和高
- image[width][height] 当前图像
- samples[width][height][N] 样本背景模型
- segMap[width][height] 前景分割地图
代码常量
- background=0
- foreground=255
算法核心伪代码
for(x=0;x<width;x++){
for(y=0;y<height;y++){
//逐像素处理,count记录相近样本数,index为样本索引,dist为欧式距离
int count=0,index=0,dist=0;
while((count<$#_min$)&&(index<N)){
dist=EuclidDist(image[x][y],samples[x][y][index]);
if(dist<R){
count++;
}
index++;
}
//当接进的样本数超过预定阈值$#_min$时,将当前像素置为背景
if(count>=$#_min$){
segMap[x][y]=backgournd;
int rand=getRandomNumber(0,$\phi$-1);
if(rand==0){
//随机更新样本背景模型
rand=getRandomNumber(0,N-1);
samples[x][y][rand]=image[x][y];
}
rand=getRandomNumber(0,$\phi$-1)
//随机更新邻域中的像素
if(rand==0){
int xna,yna;
xna=getRandomNeighbrxCoordinate(x);
yna=getRandomNeighbrYcoordinate(y);
//同样随机更新样本前景模型
rand=getRandomNumber(0,N-1);
samples[xna][yna][rand]=image[x][y];
}
}
else{
//当接近样本数没有达到阈值$#_min$时,将当前样本置为前景
segMap[x][y]=foreground;
}
}
}
衍生算法: PBAS