3、ray(f0);%图像灰度化imshow(g);g2=imnoise(g,'salt&pepper',0.05);%加淑盐噪声figure(3);imshow(g2);g3=medfilt2(g2,[3,3],'symmtric');%以3*3窗口中值滤波figure(4);imshow(g3);g1=im2bw(g);%图像二值化figure(2);imshow(g1);程序3%“高速公路汽车阴影”视屏的阴影去除的方法clc;clearall;closeall;%打开视频文件对话框h1=figure('toolbar','name','Shado
4、wRemoval');[FileName.PathName]=uigetfile({'*.avi','avi(*.avi)','*.*','AllFiles(*.*)'},'Openvideosequence');ifisequal([FileName,PathName],[0,0])returnelsepic_path=fullfile(PathName,FileName);mov=aviread(pic_path);endn=100;%读取视频帧数s=1;%起始为1e=n;%结束为nfori=s:emov_gray(i).image=mov(i
5、).cdate;%mov_gray(i).image为第i帧图像end[ih,iw,id]=size(mov_gray(1).image);%取得视频帧的大小%计算1到第n帧的各个像素的均值fori=s:eu=mov_gray(i).image;h=u(:)';t(i,:)=h(:);endtmp=median(t);%对t数组各列取均值mean=reshape(tmp,ih,iw,id);%将n帧均值图像恢复成h*w*d的图像矩阵,得到背景figure,imshow(uint8(mean));title('背景图像');fn=18;ok=mean
6、;tmp(1:3)=0;di=20;th=ones(1,1,3)*di;%预设阈值diff=double(ok)-double(mov_gray(fn).image);%计算第fn帧图像与背景的差值diff1=abs(diff);forai=1:ihforbi=1:iwifabs(diff(ai,bi,1:3))>=th(1,1,:)ok(ai,bi,1:3)=mov_gray(fn).image(ai,bi,1:3);elseok(ai,bi,1:3)=0;diff1(ai,bi,1:3)=0;endendendfigure,imshow(uin
7、t8(ok));title('前景图像');impixelinfo;g=rgb2hsv(mean);%将背景图像由RGB格式转为HSV格式figure,imshow(g);title('背景图像的hsv格式');impixelinfo;figure,imtooi(g);g1=rgb2hsv(ok);%将前景图像由RGB格式转为HSV格式figure,imshow(g1);title('前景图像的hsv格式');impixelinfo;figure,imtooi(g1);%阈值分割%这个地方的阈值选取是手动的,根据经验得到的!forci=1:ihif
8、(g1(ci,di,3)/g(ci,di,3)>=0.4)&&(g1(ci,di,3)/g(ci,di,3)<=0.5)&