資源簡介
MATLAB程序,背景建模,高斯模型,等等
代碼片段和文件信息
clear?all
%?source?=?aviread(‘C:\Video\Source\traffic\san_fran_traffic_30sec_QVGA‘);
source?=?mmreader(‘E:\study\source\IndoorGTTest1.AVI‘);
frameQYT=get(source‘NumberOfframes‘);
%?-----------------------??frame?size?variables?-----------------------
fr?=?read(source1);???????????%?讀取第一幀作為背景
fr_bw?=?rgb2gray(fr);??????????%?將背景轉換為灰度圖像
fr_size?=?size(fr);?????????????%取幀大小
width?=?fr_size(2);
height?=?fr_size(1);
fg?=?zeros(height?width);
bg_bw?=?zeros(height?width);
%?---------------------?mog?variables?-----------------------------------
C?=?4;??????????????????????????????????%?組成混合高斯的單高斯數目?(一般3-5)
M?=?0;??????????????????????????????????%?組成背景的數目
D?=?2.5;????????????????????????????????%?閾值(一般2.5個標準差)
alpha?=?0.01;???????????????????????????%?learning?rate?學習率決定更新速度(between?0?and?1)?(from?paper?0.01)
thresh?=?0.75;??????????????????????????%?foreground?threshold?前景閾值(0.25?or?0.75?in?paper)
sd_init?=?6;????????????????????????????%?initial?standard?deviation?初始化標準差(for?new?components)?var?=?36?in?paper
w?=?zeros(heightwidthC);??????????????%?initialize?weights?array?初始化權值數組
mean?=?zeros(heightwidthC);???????????%?pixel?means?像素均值
sd?=?zeros(heightwidthC);?????????????%?pixel?standard?deviations?像素標準差
u_diff?=?zeros(heightwidthC);?????????%?difference?of?each?pixel?from?mean?與均值的差
p?=?alpha/(1/C);????????????????????????%?initial?p?variable?參數學習率(used?to?update?mean?and?sd)
rank?=?zeros(1C);??????????????????????%?rank?of?components?(w/sd)
%?------initialize?component?means?and?weights?初始化均值和權值----------
pixel_depth?=?8;????????????????????????%?8-bit?resolution?像素深度為8位
pixel_range?=?2^pixel_depth?-1;?????????%?pixel?range?像素范圍2的7次方0—255(#?of?possible?values)
for?i=1:height
????for?j=1:width
????????for?k=1:C
????????????
????????????mean(ijk)?=?rand*pixel_range;?????%?means?random?(0-255之間的隨機數)
????????????w(ijk)?=?1/C;?????????????????????%?weights?uniformly?dist
????????????sd(ijk)?=?sd_init;????????????????%?initialize?to?sd_init
????????????
????????end
????end
end
%-----?process?frames?-處理幀--,這里去第八幀????
??????n?=?8;
????fr?=?read(sourcen);???????%?read?in?frame?讀取幀
????fr_bw?=?rgb2gray(fr);???????%?convert?frame?to?grayscale?轉換為灰度圖像
????
????%?calculate?difference?of?pixel?values?from?mean?計算像素差值
????for?m=1:C
????????u_diff(::m)?=?abs(double(fr_bw)?-?double(mean(::m)));
????end
?????
????%?update?gaussian?components?for?each?pixel?更新每個像素的背景模型
????for?i=1:height
?????
- 上一篇:四元數法計算兩個物體之間的相對位姿參數
- 下一篇:matlab2014b
評論
共有 條評論