版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、functionMovingTargetDetectionByMMI()%Moving Target Detection%Based on Maximun Mutual Information%EDIT BY PSLCSU%QQ:%Email:%2012-06-01%读文件Im1=imread(001.jpg);Im2=imread(002.jpg);Im3=imread(003.jpg);Im1=rgb2gray(Im1);Im2=rgb2gray(Im2);Im3=rgb2gray(Im3);tic;d12=GetDifferenceImg(Im2,Im1)
2、;d23=GetDifferenceImg(Im2,Im3);d=d12.*d23;se =;for i=1:4d = imfilter(d,se);endfor i=1:2d = medfilt2(d,);end%d=abs(d12-d23).0.7);d=uint8(d/max(max(d)*255);level = graythresh(d);BW = im2bw(d,level);s=regionprops(BW,BoundingBox);figure(1)subplot(2,2,1);imshow(uint8(d12/max(max(d12)*255);title(参考帧与前一帧的差
3、值)subplot(2,2,2);imshow(uint8(d23/max(max(d23)*255);title(参考帧与后一帧的差值)subplot(2,2,3);imshow(BW);title(由前后帧得出的差值)subplot(2,2,4);imshow(Im2);%imshow(d);rectangle(Position,s(1).BoundingBox,Curvature,LineWidth,2,LineStyle,-,EdgeColor,r)title(参考帧与检测结果)%求相邻两帧重合部分差值主函数function outImg=GetDifferenceImg(R,F)=d
4、wt2(R,db1);=dwt2(F,db1);CA1=uint8(CA1);CA2=uint8(CA2);fprintf(n-PSO startn);=PSO(CA1,CA2);while mi0.01 mi_old=mi; =powell(R,F,pa);endfprintf(-Powell endnn);time=toc;fprintf(tx:%.4fty:%.4fang:%.2f mi:%fn,pa(1),pa(2),pa(3),mi);fprintf(time:%fn,time);outImg=GetDifference(pa(1),pa(2),pa(3),R,F);%figure(
5、6);imshow(outImg);%求相邻两帧重合部分差值function outImg=GetDifference(tx,ty,ang,R,F)=size(R);%R=im2double(R);F=im2double(F);theta=ang*pi/180; %旋转角度转弧度cx=floor(n/2); %旋转的中心点cy=floor(m/2);outImg=zeros(m,n);for j=1:m for i=1:n %参考图像在浮动图像平移后的对应点 % x=i-tx;%列 % y=j-ty;% x=(i-cx)*cos(theta)-(j-cy)*sin(theta)+cx-tx;
6、y=(i-cx)*sin(theta)+(j-cy)*cos(theta)+cy-ty; x1=floor(x); y1=floor(y); rval=R(j,i); %图像重合部分求差 if(x1=1&x1=1&y1=1&x1=1&y1m) dy=y1-y;dx=x1-x; %双线性插值 fval=(F(y1+1,x1)-F(y1,x1)*dy+(F(y1,x1+1)-F(y1,x1)*dx+(F(y1+1,x1+1)+F(y1,x1)-F(y1,x1+1)-F(y1+1,x1)*dy*dx+F(y1,x1); hist(fval,rval)=hist(fval,rval)+1; end e
7、ndend%下面求边缘概率密度for i=1:256 ha(i)=sum(hist(i,: ); hb(i)=sum(hist(:,i);end%调用互信息函数out=MI(hist,ha,hb);%下面是求互信息的函数function mi=MI(hist,ha,hb)%hsum = sum(sum(hist);index = find(hist=0);p=hist/hsum;Hab=sum(sum(-p(index).*log(p(index); %联合熵hsum = sum(sum(ha);index = find(ha=0);p = ha/hsum;Ha = sum(sum(-p(in
8、dex).*log(p(index);%边缘熵hsum = sum(sum(hb);index = find(hb=0);p = hb/hsum;Hb = sum(sum(-p(index).*log(p(index);%边缘熵mi = Ha+Hb-Hab;%粒子群算法function =PSO(R,F)%粒子群算法%初始化D=3; %维数ps=30; %种群规模VRmin=ones(D,1)*-20;%最小速度VRmax=ones(D,1)*20; %最大速度VR=;%minmax = 1;pos=40*rand(ps,D)-20;%随机产生初始位置vel=8*rand(ps,D)-4; %
9、产生随机速度% ps=15; %种群规模% VRmin=ones(D,1)*-10;%最小速度% VRmax=ones(D,1)*10; %最大速度% VR=;% %minmax = 1;% pos=20*rand(ps,D)-10;%随机产生初始位置% vel=4*rand(ps,D)-2; %产生随机速度%一些参数maxinterations=20; %最大迭代次数iw=1; %固定权重iw1 = 0.9; % 最大惯性权重iw2 = 0.4;iwe = 15;ac1=2;ac2=2;flagg=1;% ergrd=1e-5;% ergrdep=5; % mv=4;%ergrd=1e-4;
10、ergrdep=5; %mv=4;%初始个体极值pbest=pos;%求初始全局极值for i=1:ps p=pos(i,: ); %第i个粒子位置 out(i)=BI_mi(p(1),p(2),p(3),R,F);%求函数值endpbestval=out; %每个粒子当前函数值=max(pbestval); %全局最优函数值gbest=pbest(idx,: ); %全局极值tr(1)=gbestval; %保存当前全局最优函数值% start PSO iterative procedurescnt=0; % counter used for updating display accordi
11、ng to df in the optionscnt2=0; % counter used for the stopping subroutine based on error convergence%开始迭代for i=1:maxinterations for j=1:ps if flagg=1 % randomization control, one random set for each particle at each epoch rannum1=rand(1); rannum2=rand(1); end p=pos(j,: ); %第i个粒子位置 out(j)=BI_mi(p(1),
12、p(2),p(3),R,F);%求函数值 e(j)=out(j); %更新pbest if pbestval(j)=e(j);%= pbestval(j)=e(j); pbest(j,: )=pos(j,: ); end %更新gbest =max(pbestval); if gbestval=iterbestval %= gbestval=iterbestval; gbest=pbest(idx1,: ); end tr(i+1)=gbestval; te=i; % %更新速度,位置 % if imv vel(j,dimcnt)=mv; end if vel(j,dimcnt)=VR(dim
13、cnt,2) pos(j,dimcnt)=VR(dimcnt,2); end if pos(j,dimcnt)ergrd cnt2=0; elseif tmp1=ergrdep break end endend %迭代结束fprintf(total interations:%dn,i);%OUT=;pa=gbest;mi=gbestval;%POWELL优化算法function =powell(R,F,x)len=5; %搜索区间itmax=30; %最大循环次数e=1e-3; %允许误差%方向矢量矩阵存放d1,d2,d3三个方向矢量D=;%起始点%x0=;x0=x;fx0=BI_mi(x0(
14、1),x0(2),x0(3),R,F);%fx0=pv_mi(x0(1),x0(2),-x0(3),R,F);%循环搜索for k=0:itmax %从起始点出发,沿d1方向搜索,得到最大值fx1,对应点x1 d1=D(1,: ); =oneDimSearch(R,F,x0,d1,len); fprintf(%f,%f,%f,%fn,x1(1),x1(2),x1(3),fx1); %从x1出发,沿d2方向搜索 d2=D(2,: ); =oneDimSearch(R,F,x1,d2,len); fprintf(%f,%f,%f,%fn,x2(1),x2(2),x2(3),fx2); %从x2出发
15、,沿d3方向搜索 d3=D(3,: ); =oneDimSearch(R,F,x2,d3,len); %加速方向 dn=x3-x0; y=sum(dn.*dn); fprintf(%fn,y); fprintf(%f,%f,%f,%fn,x3(1),x3(2),x3(3),fx3); if y=e%满足结束条件,退出循环 %= pa=x3; mi=fx3; return; end %调整搜索方向 %计算目标值下降最多的那个方向 cha=; =max(cha); % xe=2*x3-x0; fe=BI_mi(xe(1),xe(2),xe(3),R,F); %fe=pv_mi(xe(1),xe(2
16、),-xe(3),R,F); %这里求极大值 if (fe= (fx0-fe)*(fx0-fe)*maxcha) %不引入新的方向 %= x0=x3; %下次搜索的新起点 fx0=fx3; else %引进新的方向 %以xn为起点沿dn进行搜索,得到下次搜索的新起点 =oneDimSearch(R,F,x3,dn,len); %替换方向 D(4,: )=dn; for i=j0:3 D(i,: )=D(i+1,: ); end endend%end forpa=x3;mi=fx3;%一维搜索。从-len到len,找出最大值的点function =oneDimSearch(R,F,X,direc
17、tion,len)%一维brent搜索求函数最小值CGOLD =0.;a=-len;b=len;%a=a0;%b=b0;tol=0.01;e=0.0;ITMAX=100;v=a+CGOLD*(b-a);Xv=X+direction*v;%fv=pv_mi(Xv(1),Xv(2),-Xv(3),R,F);fv=BI_mi(Xv(1),Xv(2),Xv(3),R,F);w=v;x=v;fw=fv;fx=fv;for k=0:ITMAX xm=0.5*(a+b); %中点 tol1=tol*abs(x); tol2=2*tol1; %if abs(x-xm)=tol; if abs(x-xm) to
18、l1) r=(x-w)*(fx-fv); q=(x-v)*(fx-fw); p=(x-v)*q-(x-w)*r; %分子 q=2*(q-r); %分母 if (q0) p=-p; end q=abs(q); etemp=e; e=d; if (abs(p) = abs(0.5*q*etemp) | p= q*(b-x) %使用黄金分割 %= if x = xm e=a-x; else e=b-x; end d=CGOLD*e; else %抛物线内插 d=p/q; u=x+d; %u if(u-atol2)%u靠近边界= %= if x xm; d=-abs(tol1); else d=abs
19、(tol1); end end end else %使用黄金分割 if x = xm e=a-x; else e=b-x; end d=CGOLD*e; end%if (abs(e) tol1) if abs(d)=tol1 u=x+d; else if d=0 u=x+abs(tol1); else u=x-abs(tol1); end end Xu=X+direction*u; % fu=pv_mi(Xu(1),Xu(2),-Xu(3),R,F); %函数值 fu=BI_mi(Xu(1),Xu(2),Xu(3),R,F); %函数值 %更新参数if fu=fx if u=x a=x; el
20、se b=x; end v=w;w=x;x=u; fv=fw;fw=fx;fx=fu;else if u=fw | w=x) v=w;w=u; fv=fw;fw=fu; elseif (fu=fv | v=x | v=w) v=u; fv=fu; endendend%end for/x/m)/m)用于检测的原始序列如下:前一帧 001.jpg参考帧 002.jpg后一帧 003.jpg运行结果如下:-PSO start6.,3.,-4.,1.3.,1.,-3.,1.2.,-0.,-2.,1.4.,1.,-0.,1.4.,1.,-0.,1.2.,0.,-0.,1.2.,0.,-0.,1.2.,0.,-0.,1.2.,0.,-0.,1.2.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.3.,0.,-0.,1.total interations:20tx:3.ty:0.ang:-0. mi:1.-PSO end-Powell start7.,0.,-0.,1.7.,1.,-0.,1.16.7.,1.,-0.,1.8.,2.,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年海洋声学监测技术实操考核试题及答案
- (2026年)换瓣手术中心搏骤停的处理课件
- 中国历史事件时间顺序排列试题及答案
- 2025年小学六年级物理光学基础与习题解析真题
- 机械设计制造工艺技术测试试卷
- 2026年体育技能:篮球基本技巧与训练方法考试及答案
- 幼小衔接精细操作能力测试方法试题及答案
- 线缆标准与检测技术
- 2026年中小学辅导员德育工作与教育创新检测试题及答案
- 2025浙江台州市温岭市市场集团有限公司招聘编外工作人员3人笔试参考题库附带答案详解
- 2025年律师事务所党支部书记年终述职报告
- 2025-2026 学年第一学期大一高等数学期末考试试卷
- 2025年高考(新高考Ⅱ卷)数学试题及答案
- 医院外联部主任述职报告
- 2025年广东省高考语文试卷(含标准答案)
- 2025年驾照三例测试题及答案
- 烟草行业消费者行为分析
- 《机械制图》 期末考试试题(附标准答案)
- new s-pro系列提案书海信日立空调营销股份
- 停课不停教隔空云教学
评论
0/150
提交评论