emshift.m

来自「混合高斯概率密度模型,其参数估计可以通过期望最大化( EM) 迭代算法获得。」· M 代码 · 共 29 行

M
29
字号
function [xt,Vt]=EMShift(im0,xt,V,histO,K,beta,varargin)
%Calculate gradient step to maximize similarity between the target
%and the object histogram - Bhattacharayya coefficient
%The step is in both position and scale as described in 
%(original mean-shift does only position 
%- so if you do not use the resulting V you will get the standard meax-shift):
%Z.Zivkovic, B.Krose 
%An EM-like algorithm for color-histogram-based object tracking"
%IEEE Conference CVPR, June, 2004

%get target region
[data,rX,rY]=GetAffineRegion(im0,xt,V,K.rX,K.rY,K.sigmas);

%get histogram + mapping H pixels to bins
[histR]=ColorHist(data,histO.nBinsD,K.rK);
[riNonZero]=find(histR.data>0);%prevent divide by zero
rWeigths=(histR.H(:,riNonZero)*sqrt(histO.data(riNonZero)./histR.data(riNonZero))')'.*K.rK;
sumW=sum(rWeigths);
if (sumW>0) rQs=rWeigths/sumW;else rQs=rWeigths; end;
        
dx=[sum(rQs.*rX);sum(rQs.*rY)];
xt=xt+dx;
Vxy=sum(rQs.*rX.*rY);
Vt=beta*[sum(rQs.*rX.*rX),Vxy;Vxy,sum(rQs.*rY.*rY)];
%no convergence detection implemented here - uses fixed number of iterations

%clip
Vt(1,1)=max(Vt(1,1),1);Vt(2,2)=max(Vt(2,2),1);%clip to min 1

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?