資源簡介
matlab 高斯背景建模 用于對視頻序列的背景建模,從而完成運動目標檢測
代碼片段和文件信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%高斯背景建模()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
close?all;??%clear?obj?removes?obj?from?the?MATLAB?workspace.
tic;%計時開始%取第一幅符合要求的背景圖、
%?-----------------------??frame?size?variables?-----------------------
File_name=‘E:\學習\背景—車\背景建模圖片\‘;
str?=?int2str(1);
T?=?STRCAT(File_namestr‘.jpg‘);%
I?=?imread(T‘JPG‘);
I=rgb2gray(I);
I=I(:350:1000);?
[mns]=size(I);
q=zeros(mn);
fg?=?q;??????????????%前景
bg_bw?=?q;???????????%背景
%?---------------------?mog?variables?-----------------------------------
C?=?3;??????????????????????????????????%?組成混合高斯的單高斯數目?(一般3-5)
M?=?3;??????????????????????????????????%?
D?=?2.5;????????????????????????????????%?閾值(一般2.5個標準差)
alpha?=?0.01;???????????????????????????%?learning?rate?學習率決定更新速度(between?0?and?1)?(from?paper?0.01)
thresh?=?0.25;??????????????????????????%?foreground?threshold?前景閾值(0.25?or?0.75?in?paper)
sd_init?=?6;????????????????????????????%?initial?standard?deviation?初始化標準差(for?new?components)?var?=?36?in?paper
w?=?zeros(mnC);??????????????%?initialize?weights?array?初始化權值數組
mean?=?zeros(mnC);???????????%?pixel?means?像素均值
sd?=?zeros(mnC);?????????????%?pixel?standard?deviations?像素標準差
u_diff?=?zeros(mnC);?????????%?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:m
????for?j=1:n
????????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?-處理幀----------------------------------
E=10;??%背景序列個數
for?k?=?1:E??%迭代法更新背景??
?????str?=?int2str(k);
?????T?=?STRCAT(File_namestr‘.jpg‘);%
?????It?=?imread(T‘JPG‘);
?????
?????fr_bw=rgb2gray(It);
?????fr_bw=fr_bw(:350:1000);?
?????%?calculate?difference?of?pixel?values?from?mean?計算像素差值
????for?l=1:C
????????u_diff(::l)?=?abs(double(fr_bw)?-?double(mean(::l)));
????end
????
????%?update?gaussi
- 上一篇:打靶法-求解邊值問題
- 下一篇:matlab實現霍夫曼壓縮與解壓縮
評論
共有 條評論