-
大小: 8.58MB文件類(lèi)型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-10-05
- 語(yǔ)言: Matlab
- 標(biāo)簽: Meansh??目標(biāo)跟蹤??
資源簡(jiǎn)介
該資源是包含代碼和樣例圖像序列,代碼附帶詳細(xì)的注釋?zhuān)钊霚\出幫助你理解Meanshift算法和目標(biāo)跟蹤的關(guān)系,巴適系數(shù)和meanshift向量的關(guān)系

代碼片段和文件信息
%%?從零基礎(chǔ)實(shí)現(xiàn)meanshift算法
close?all;
clear?all;
clc;
%%?根據(jù)一幅目標(biāo)全可見(jiàn)的圖像圈定跟蹤目標(biāo)
I=imread(‘0001.jpg‘);
figure(1);
imshow(I);
[target_image rect]???????????????=?imcrop(I);????????????%?(rect(1)rect(2))為目標(biāo)圖像左上角坐標(biāo)????????????????????????????????????????????????????????????
%??————→?x軸?(1到544)?對(duì)應(yīng)圖像的列?????????????????????%?rect(3)是目標(biāo)圖像的寬度(x軸)????????????????
%?|?????????????????????????????????????????????????????????%?rect(4)是目標(biāo)圖像的高度(y軸)?
%?|?????????????????????????????????????????????????????????%?目標(biāo)圖像右下角坐標(biāo)(rect(1)+rect(3),rect(3)+rect(4))
%?↓
%?y軸(1到960)?對(duì)應(yīng)圖像的行
[target_rowtarget_coltarget_dim]??=?size(target_image);???%?獲取目標(biāo)圖像行數(shù)?列數(shù)?維度
%%?計(jì)算目標(biāo)圖像的權(quán)值矩陣
target_center_x =?rect(1)?+?rect(3)/2;??????????????????????%?目標(biāo)圖像在原圖像中的?X軸中心坐標(biāo)??????
target_center_y =?rect(2)?+?rect(4)/2;??????????????????????%?目標(biāo)圖像在原圖像中的?Y軸中心坐標(biāo)
y(1)????????????=?target_row/2;?????????????????????????????%?目標(biāo)圖像在目標(biāo)圖像的?Y軸中心坐標(biāo)??????
y(2)????????????=?target_col/2;?????????????????????????????%?目標(biāo)圖像在目標(biāo)圖像的?X軸中心坐標(biāo)?
h???????????????=?(target_row/2)^2?+?(target_col/2)^2;??????%?帶寬?(對(duì)角線長(zhǎng)度/2)^2
weight??????????=?zeros(target_rowtarget_col);?????????????%?權(quán)值矩陣
for?i=1:target_row
????for?j=1:target_col
????????distance=(i-y(1))^2+(j-y(2))^2;?????????????????????%?計(jì)算每個(gè)點(diǎn)到中心坐標(biāo)的距離
????????weight(ij)=1-distance/h;???????????????????????????%?Epanechnikov?profile(距離越大,權(quán)值越小)
????end
end
C???????????????=?1?/?sum(sum(weight));?????????????????????%?歸一化系數(shù)?(?Tips?二維數(shù)組的求和?sum(sum(array))?)
%%?計(jì)算目標(biāo)權(quán)值直方圖qu
TargetHistogram?????=?zeros(14096);??????????????????????%?目標(biāo)的權(quán)值直方圖
for?i=1:target_row
????for?j=1:target_col
????????%?rgb顏色空間量化為16*16*16?bins
????????%?rgb的三個(gè)維度每一維都0~255?除16之后?每一維就降到了0~15
????????q_r?????=?fix(double(target_image(ij1))/16);??????%?fix為?下取整函數(shù)
????????q_g?????=?fix(double(target_image(ij2))/16);
????????q_b?????=?fix(double(target_image(ij3))/16);
????????q_temp =?q_r*256?+?q_g*16?+?q_b;???????????????????%?降維之后的16位的RGB空間可以把顏色分為?16*16*16=4096種顏色
????????????????????????????????????????????????????????????%?這里是計(jì)算目標(biāo)圖像的每一個(gè)像素點(diǎn)的顏色在直方圖的坐標(biāo)
????????%?計(jì)算得到坐標(biāo)是0~4095,因此數(shù)組系數(shù)要+1
????????TargetHistogram(q_temp+1)=?TargetHistogram(q_temp+1)+weight(ij);????????
????????????????????????????????????????????????????????????%?統(tǒng)計(jì)目標(biāo)的特征直方圖中每一種顏色的權(quán)重
????????????????????????????????????????????????????????????%?目標(biāo)圖像每一個(gè)像素點(diǎn)都會(huì)對(duì)應(yīng)直方圖中一種顏色
????????????????????????????????????????????????????????????%?之前根據(jù)距離目標(biāo)中心的距離也計(jì)算了每個(gè)像素點(diǎn)的權(quán)重的
????end
end
TargetHistogram?=?TargetHistogram*C;??
rect(3)=ceil(rect(3)); %?rect(3)是目標(biāo)圖像的寬度?ceil是上取整
rect(4)=ceil(rect(4));??%?rect(4)是目標(biāo)圖像的高度
bar(TargetHistogram0.5);
title(‘目標(biāo)特征直方圖‘);
?
%%?讀取序列圖像開(kāi)始跟蹤
ImageSequence =?dir(‘*.jpg‘);
SequenceLength =?length(ImageSequence);
%?%?驗(yàn)證序列順序是否正常
%?for?l=1:SequenceLength
%???????ImageSequence(l).name
%?end
IterationMaxNum?=?2;
for?l=1:SequenceLength
CurrentImage =?imread(ImageSequence(l).name);????
????IterationNum =?0;
????Y???????????????=?[22];
????while(?(Y(1
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
????.CA....?????41113??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0001.jpg
????.CA....?????38659??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0002.jpg
????.CA....?????40697??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0003.jpg
????.CA....?????40547??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0004.jpg
????.CA....?????43372??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0005.jpg
????.CA....?????40458??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0006.jpg
????.CA....?????41791??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0007.jpg
????.CA....?????41443??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0008.jpg
????.CA....?????45220??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0009.jpg
????.CA....?????41704??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0010.jpg
????.CA....?????43879??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0011.jpg
????.CA....?????43445??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0012.jpg
????.CA....?????46029??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0013.jpg
????.CA....?????42999??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0014.jpg
????.CA....?????43017??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0015.jpg
????.CA....?????39847??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0016.jpg
????.CA....?????45106??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0017.jpg
????.CA....?????42073??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0018.jpg
????.CA....?????42476??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0019.jpg
????.CA....?????42073??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0020.jpg
????.CA....?????46296??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0021.jpg
????.CA....?????44755??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0022.jpg
????.CA....?????47372??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0023.jpg
????.CA....?????47389??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0024.jpg
????.CA....?????49380??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0025.jpg
????.CA....?????46482??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0026.jpg
????.CA....?????47421??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0027.jpg
????.CA....?????46129??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0028.jpg
????.CA....?????51013??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0029.jpg
????.CA....?????48452??2019-03-21?14:31??Meanshift算法MATLAB實(shí)現(xiàn)\0030.jpg
............此處省略175個(gè)文件信息
評(píng)論
共有 條評(píng)論