meanshift.m
来自「利用meanshift在MATLAB中实现目标检测和跟踪」· M 代码 · 共 51 行
M
51 行
function [ rowcenter colcenter M00 ] = meanshift(I, rmin, rmax, cmin,... cmax, probmap)%inputs% rmin, rmax, cmin, cmax are the coordiantes of the window% I is the image%outputs% colcenter rowcenter are the new center coordinates% Moo is the zeroth mean% **********************************************************************% initialize% **********************************************************************M00 = 0; %zeroth meanM10 = 0; %first moment for xM01 = 0; %first moment for yhistdim = (0:1:255); % dimensions of histogram... 0 to 255, increment by 1[rows cols] = size(I);cols = cols/3; % **********************8% **********************************************************************% Main code% **********************************************************************% determine zeroth momentfor c = cmin:cmax for r = rmin:rmax M00 = M00 + probmap(r, c); endend% determine first moment for x(col) and y(row)for c = cmin:cmax for r = rmin:rmax M10 = M10 + c*probmap(r,c); M01 = M01 + r*probmap(r,c); endend% determine new centroid% x is cols colcenter = M10/M00;% y is rows rowcenter = M01/M00;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?