《Matlab图像处理实验指导书.docx》由会员分享,可在线阅读,更多相关《Matlab图像处理实验指导书.docx(27页珍藏版)》请在课桌文档上搜索。
1、生命科学与技术学院Eg8telSmog(pcEesatog7.,MM*4fxM1W9110上教学HKKM1) HkMa9Nt4VfefA!.HfliaARnatk“”HN为S3A“九nmBtau*M1.k“,世OJtamuik低鼻.3a11WitWttA6(nrjM.J4IYlK.MHAUfiMZt.ftCK11U4lH.Vkl力加afrfMJAlfcF*Xz*,4Mll1ffWU1aWi*AM11m*mOHAHX三*.dlfiil冷03MlWtHfrn*So*4BfmftNRmt*r.Hiir;CR!l,KtJ0tHaeKM.aIMtMK-4.i*t电IIf)K能,“,.tihwWMMMAt
2、lMRtro,0,,力A”阴It,:力,AthKtftHBACX(t*./K8Wl9力.ttaHer)cn八9Ma*t*ucctf,MQ打。仇国MUlt4ttRM.W4ltitMn6WM0W*1UWaSX串a.6UME,.SaWiniW,*M*Efl“IMtNgjQiflNMVn”B匕*和力0m知SJt4t,-4*BMItkiMMU,”勺*391MliSWilUU三BWWUMJMltCT*W匕入外,Mlkf44WWV*tf*ll*hWP*MfclF32*。3,外RHMIBWtWT”“,3,rt,IlKUW*wVtt*kimM*F,MwrONMW4tIHt科OHG#aJ0*AQtff3WnMJW
3、,MMi*4VXyO中,必*3M,:yH!3,liMr*Fnrrxf、5aW:BV*naz*umvu4一mvosff*w三tsww-ia三Mi“iWttif9r3Nr“5l79SXIW*H0l;V但93*VV-Crtt!7kttUlrVVliMJaiNMiMKV4MkUWMH41rrWhMt*4lkMA*Mm*rthMMW3XltViC*1*FWRUW.。用:.RAIQM4C.*XkiM.a.ntiaa.“(umA4tsa.iiMinan*wiarwif)4tMHm.fctm.第utF.H、,en.tfM.11-A.awtM-a4QSDS,|*Qf*-,HCfl-.,-Em7MtXMHe%2M
4、*ACMiau*.nntuUDnHM4!.mtad0n(ncr;nR,5.mtW4AXtI0!M*“余炳QluRjnjM.:*ru.u.vwRntuntt4NKSiItlS*b4mb!1汽“tin.amu,?,料的这,.9t.*%月Ul火ItlW、公HMC*mK45KihHM,MW2cftnnriHMi!ritRn-umtsw)tMer;*uNjn*jM*.I1I三d.IWMMbMMMi.tMMtitnOMR*n史*smk,tt*AAcfvn.aMtt*Mi49fNHKMCl*C2FffrftMTHMrt3.4CTCW*?.MMWHBSMf74M.W收罐H,JMt*RHVMh4Wttrt4lt
5、HWJJI入器外UlMS,MffMVMiyBR.tUCW.B*IRllMrltdllWtRtlAttlRAt-AtfM.9三Rflt-411WG1nlll*tH0三.ItHN今M44*NtBrA.ft三d*KC-*XHl*d*1tnmlC4Ofc.M1tfUMIHMVMtat14*K.E*tWHA4.0*MIatfdt(7*w*TUBi6t-WHt-4,lc,*HM腾,*774i/VVi*%AB-rn,l*H7,.tl7RVJ*图像除法运算3 .图像的几何运算A)变更图像的大小读入图像ic.lif.变更图像大小,分别将原图像放大1.5倍和缩小05倍.I=imread(ic.tif);J=imr
6、esize(I,l25);K=ImreSiZe(1,0.8);Imshow(I)figure,imshow(J)figure,imShoW(K)Y=imreslze(I,100,150);figure,imshow(Y)B)旋转一幅图像将上述图像照时针和逆时针枪转随意角度视察显示效果.I=imread(ic.tif);J=imrotate(1,30,bilinear);Jl=imrotate(1,30,bilinear,crop,);imshow(I)figure,imshow(J)figure,imshow(Jl)J2=imrotate(I,-15,bilinear);figure,imsh
7、ow(J2)C)图像酎切通过交互式操作,从一幅图像中剪切一个矩形区域.I=imread(,ic.ti);Imshow(I);Il=imcrop;figure,imshow(Il)12=imcrop(I,3060120160);figure,imshow(I2)4 .*图像的邻域操作读入图像tiEi*分别运用函数nlfiltcr和MkPrW对图像进行滑动邻域操作和分别邻城操作.I=imread(,tire.tif);f=inline(,max(x(:);%构造发合的数I2=nlfilter(I,33,f);%滑动邻域操作imshow(I)figure,imshow(I2)I=imread(tir
8、e.tif);f=inline(,uint8(round(mea2(x)*ones(size(x);%构造复合函数I2=blkproc(I,88,f);%;什动邻域愫作imshow(I)figure,imshow(I2)试验三图像变换与滤波器设计一、试睑目的1. 了解傅立叶变换、离散余弦变换及Radon变换在图像处理中的应用2. 了解MaUab线性泄波器的设计方法二、试睑内容1 .傅立叶变换A)绘制一个二侑图像矩阵.并将其傅立叶函数可视化.f=zeros(30,30);f(5:24,13:17)=1;imshow(notruesize)F=fft2(f);F2=log(abs(F);figur
9、e,imshow(F2,-l5,lnotruesize,)jcolormap(jet);F=fft2(f,256,256);%零填充为256256矩阵figure,imshow(log(abs(F),-l5/notruesize);colormap(jet);F2=fftshift(F);%将图像短谱中心由雄阵原点移至矩阵中心figure,imshow(log(abs(F2),-l5,notruesize);COlOrmaP(Jet);B)利用傅工叶变换分析两柏图像的相关性,定位图像特征,读入图像Yex1.lif,抽取其中的字母bw=imread(text.tif);a=bw(59:71,81
10、:91);imshow(bw);figure,imshow(八);C=real(ifft2(fft2(bw).*fft2(rot90(a,2),256,256);%求相关性figure,imshow(C,);thresh=ma(C(:);figure,imshow(Cthresh-10)figure,imshow(Cthresh-l5)2 .离散余弦变换(DCT)A)运用dct2对图像*autumn.tif,进行DCT变换.RGB=imread(autumn.tif,);Imshow(RGB)I=rgb2gray(RGB);%转换为灰度图像figure,imshow(I)J=dct2(I);f
11、igure,imshow(log(abs(J),),colormap(jet(64);colorbar;B)将上述DCT变换结果中肯定值小于10的系数舍弃,运用ifcl2虫相图像并与原图像比较。RGB=imread(autumn.tlf);I=rgb2gray(RGB);%转换为灰度图像J=dct2(I);figure,imshow(I)K=idct2(J);figure,imshow(K,0255)J(abs(J)10)=0;%舍弃系数K2=idct2(J);figure,imshow(K2,0255)O利用DCT变换进行图像压缩,I=imread(,cameraman.tif);l=im2
12、double(I);T=dctmtx(8);B=blkproc(I,8,8,Pl*x*P2T);11O100OOOOOO000OOOOOOOOOOOOOOOOOmask=l1110000OOO000OOO00000000000O;B2=blkproc(B,88,Pl.*,mask);12=blkproc(B2,88,Pl*P2,TzT);imshow(I)figure,imshow(I2)3 .Radon变换运用Radon逆变换曳建图像.P=phantom(256);%创建256灰度级大脑图imshow(P)%18个投影%36个投影%90个投影theta1=0:10:170;Rl,p=rado
13、n(Prthetal);theta2=0:5:175;R2,xp=radon(P,theta2);theta3=0:2:178;R3,xp=radon(P,theta3);figure,imagesc(theta3,xp,R3);colormap(hot);colorbar%,fRl近构图像%用R2咆构图像%用R3变构图像%运用逆变换取构图像Il=iradon(Rl,10);I2=iradon(R2,5);13=Iradon(R3,2);figure,imShoW(II)figure,imshow(I2)figure,imshow(I3)4 .*Malab线形泄波器设计采纳频率变换方式,通过一
14、堆最优水纹HR谑波器创建二维HR谑波器(p96hb=remez(10,(00.40.61,1100);%阶次,频率向礴对应的志向幅频响应h=ftrans2(b);Hrw=freqz(b,1,64,whole);colormap(jet(64)plot(wpl-l,fftshift(abs(三));%使釉取假0处时应曲线中心figure,freqz2(h,3232)试验四形态学操作与空间变换一、试睑目的1. 了解膨版和糕蚀的MaUab实现方法2. 驾驭图像膨张、腐蚀、开启、闭合等形态学操作函数的运用方法3. 了解二进制图像的形态学应用4. 了解空间变换函数及图像匹配方法二、试验内容1 .图像膨版
15、A)对包含掂形对蚊的二进制图像进行膨胀操作.BW=zeros(9,10);BW(4:6,4:7)=1;imshow(BW,notruesize)Se=Stre1(SqUare3);%正方形结构元素BW2=imdilate(BW,se);figure,imshow(BW2notruesize,)B)变更上述结构元素类型(如:IinC.diamond,disk等),重新进行膨胀操作.C)对图像*text.tif进行上述操作,视察不同结构元素膨胀的效果.BW3=imread(text.tlf);imshow(BW3)se2=strel(line,11,90);%戏里结构元素BW4=imdilate(
16、BW3,se2);figure,imshow(BW4)2 .图像粕蚀A)时图像circbw.if进行腐蚀操作。BWl=imread(lcircbw.tif);se=strel(,arbitrary,eye(5);BW2=imerode(BWl,se);imshow(BWl)figure,imshow(8W2)B)对图像4text.tif进行腐蚀操作.BW=imread(,text.tif,);se=strel(line,11,90);BW2=imerode(BW3,se);imshow(BW)figure,imshow(BW2)3 .膨眼与腐饨的粽合运用A)从原始图像circbw.tif中删除
17、电流线.仅保留芯片对象.方法-:先腐蚀(imerode),再膨胀(imdilate):BWl=imread(circbw.tif,);imshow(BWl)Se=StreICrectangIe,4030);%选择适当大小的电形结构元素BW2=imerode(BWlfse);%先腐蚀,删除较细的直线figure,imshow(BW2)BW3=imdilate(BW2,se);%再膨胀,更原矩形的大小figure,imshow(BW3)方法::运用形态开启函数(ImoPen).BWl=imread(,circbw.tif,);imshow(BWl)se=strel(,rectangle,4030)
18、;BW2=imoen(BWl,se);%开启操作figure,imshow(BW2)B)变更结构元素的大小,曳新进行开启操作,视察处理结果.Se=StreIcreCtangle,2010);se=strel(rectangle,5040);O过结构元素大小为431,同时视察形态开启(imopcn)与闭合QmcloSe)的效果.总结形态开启与闭合在图像处理W,的作用。I=imread(,circbw.tif);Imshow(I)se=strel(lrectangle,43);ll=imoen(I,se);%开启操作I2=imclose(I,se);%闭合操作figure,imShoW(II)fi
19、gure,imshow(I2)4 .“高帽与低布变换)读入图像pearlieiif,分别显示其高阳变换与低附变换结果,井与原图像比较”(设Se=SIrel(diskM:)。I=imread(,pearllte.tif);subplot(221),imshow(I)se=strel(,disk,5);J=imtophat(I,se);subplot(222),imshow(J)K=imbothat(I,se);subplot(223),imshow(K)1.=imsubtract(imadd(J,I),K);Subplot(224),imshow(1.)B)要求显示在一个窗口中.5 .图像极值的
20、处理方法A)对于下图所示的图像矩阵A,利用函数imrcgicnalmax找寻其局部极大自A=10101010101010101010;10131313101011101110;10131313101010111010;10131313101011101110;10101010101010101010;10111010101818181010;10101011101818181010;10101110101818181010;10111011101010101010;10101010101011101010;B=ImregionaIrnax(八)B)利用函数imexieledmax找寻像素伯大于
21、其邻域像素值2个单位的局部极大值。C=imetendedma(A,2)6.*创建一幅图像.求其距恩矩阵。bw=zeros(5,5);bw(2,2)=l;bw(4,4)=l;D=bwdist(bw)centerl=-10;center2=-centerl;dist=sqrt(2*(2*centerl)A2);radis=dlst2*1.4;lims=floor(centerl-1.2*radius)ceil(center2+1.2*radius);x,y=meshgrid(lims(l)Jims(2);bwl=sqrt(x-centerl).A2+(y-center2).A2)=radius;b
22、w2=sqrt(x-center2).2+(y-center2).2)=radius;bwl=sqrt(x-centerl),2+(y-centerl).2)=radius;bw=bwlbw2;imshow(bw)D=bwdist(bw);figure,imshow(D,)Dl=bwdist(bw);figure,imshow(Dl,)7.*运用伪彩色显示标记矩阵,BW=00000000;01100111;01100011;01100000;00011000;00011000;00011000;00000000=bwlabel(BW,4)RGB=label2rgb(X,jet,k);imsho
23、w(RGB,notruesize,)8.利用选择限制点实现图像匹配.Matlab图像匹汛的步骤:将标准图像和待匹配图像读入Mailab:指定图像中的眼制点对井保存;运用相互关性进一步协调限制点对(可选制定所需变换类盘并依据限制点对推断变换参数:变换未匹配的图像.%读入将匹配图像和标准图像unregistered=imread(westconcordaerial.png,);imshow(unregistered)orthophoto=imread(,westconcordorthophoto,png);figure,imshow(orthophoto)%选择图像中对应的限制点cpselect(
24、unregistered(:,1),orthophoto)%保存限制点时input_polntsbase_points%运用和关性iS步用调限制点对input_points_corr=cpcorr(input_points,base_points,unregistered(:,:,1),orthophoto);input_points_corr%依据限制点而推断空间变换参数mytform=cp2tform(input_points,base_points/projective);%变换未匹足的图像registered=imtransform(unregistered,mytform);figu
25、re,imshow(registered)试验五图像增加与夏原一、试睑目的:1 .了解灰度变换增加和空域泄波增加的MMab实现方法2 .驾驭宜方图灰慢变换方法3 .驾驭噪声模拟和图像泄波函数的运用方法4 ./解图像亚原的Matlab实现方法二、试验内容1 .灰度变换增加A)线段上像素灰度分布读入灰度图像FebyelJif,采纳交互式操作,用imptf11e绘制一条线段的灰度值。imshow(debyel.tif)improfile读入RGB图像flovee.tif,显示所选线段上红、绿、!&颜色Hi/的分布imshow(flowers.tif,)improfileB)官方图变换巴方图显示流入图
26、像FcSif.在一个窗口中显示灰度级n=64.128和256的图像直方图.I=imread(rice.tif);imshow(I)figure,imhist(1,64)figure,imhlst(I,128)宜方图灰度调整利用函数imadjus调解图像灰度范围,视察变换后的图像及其U方图的变更,I=imread(,rice.tif);imshow(I)figure,imhist(I)J=imadjust(I,0.150.9,01);figure,imhist(J)figure,imshow(J)l=imread(,cameraman.tlf);imshow(I)figure,imhist(I)
27、J=imadjust(I,O0.2,0.51);figure,imhlst(J)figure,imshow(J)在方图均衡化分别对图像,pouudf和tire.df,进疗直方图均衡化处理比较处理的后图像及直方图分布的变更.I=imread(pout.tif,);imshow(I)figure,imhist(I)J=histeq(l);figure,imhist(J)RgureJmshow(J)l=imread(,tire.tif);imshow(I)figure,imhist(I)Jhisteq(I);figure,imshow(J)figure,imhist(J)2 .空域谑波增加A)噪声模
28、拟利用函数imnoisc给图像eightm分别海加高斯(gaussian)噪声和椒盐(Salt&PepPer)噪声。I=imread(,eight.tif);Imshow(I)Il=imnoise(Igaussian,0,0.01);figure,imshow(Il)I2=imnoise(I,salt&pepper);figure,imshow(I2)B)空域巡波对上述噪声图像进行均值滤波和中值泄波,比较谑波效果,l=imread(eight.tif);J=imnoise(I,salt&pepper,0.02);Imshow(J)Kl=medfilt2(J,33);%3*3中值港波figure
29、,imshow(Kl)K2=filter2(fspecial(averagef5),J)255;figure,imshow(K2)总结均值谑波和中伤浊波的特点及运用场合,均值滤波器是一种最常用的线性低通平滑泄波器.可抑制图像中的噪声.但同时也使图像变得模糊中伯港波器是一种最常用的非规性平滑泄波器,可消退图像中孤立的噪声点,又可产生较少的模裾”对图愎HUm.tif采纳Iaplacian隔通滤波器进行蜕化漉波.I=imread(saturn.tif,);imshow(I)h=fspecial(laplacia,);12=filter2(h,I);figure,imshow(I2)3 .图像复原A)
30、模糊与噪声对图像flQwcN.tif分别采纳运动PSF和均值/波PSF进行模树.I=imread(flowers.tif);I=I(10+l:256,222+(1:256,:);t剪切图像Imshow(I)en=30;%运动位移theta=10;%运动角度PSF=fspedal(,motion,len,theta);burred=lmfilter(I,PSP,clrcuar,conv,);figure,imshow(blured)I=imread(flowers.tif);Imshow(I)H=fspecial(motion,50,45);%运动PSPmotionblur=imfilter(I
31、,H);figure,imshow(motionblur)H=fspedal(,disk,10);均值波波PSPaverageblur=imfilter(I,H);figure,imshow(averageblur)在上述模糊图像上再添加味声J=imnoise(motionblurf,salt&pepper);figure,imshow(J)B)维纳波波复原运用维纳谑波更原函数deonvwnr更原无噪声模相图像,len=30;theta=10;PSF=fspeclal(motlon,len,theta);blurred=imfilter(I,PScircular,conv,);figure,i
32、mshow(blurred)wnrl=deconvwnr(blurred,PSF);tJX实PSFfigure,imshow(wnrl)%非真实PSFwnr2=deconvwnr(b!urred,fspecial(motion,2*len,theta);figure,imshow(wnr2)%非真实PSFwnr3=deconvwnr(blurred,fspecial(,motion,len,2j,theta);figure,imshow(wnr3)”运用维纳灌波复原函数dcconvwnr显原模糊噪声图像.PSF=fspecial(,motion,len,theta);blurred=imfilter(I,PScircular,conv);noise=0.1*randn(size(I);BIurredNoisy=imadd(blurred,im2uint8(noise);figure,Smshow(BIurredNoisy)wnr4=decovwnr(BIurredNoisy1PSF);figure,imshow(wnr4)*设议信噪比和相关函数的维纳浊波配原(pl79图9.1