数字图像处理第3章ppt课件

上传人:夏** 文档编号:570132716 上传时间:2024-08-02 格式:PPT 页数:48 大小:2.81MB
返回 下载 相关 举报
数字图像处理第3章ppt课件_第1页
第1页 / 共48页
数字图像处理第3章ppt课件_第2页
第2页 / 共48页
数字图像处理第3章ppt课件_第3页
第3页 / 共48页
数字图像处理第3章ppt课件_第4页
第4页 / 共48页
数字图像处理第3章ppt课件_第5页
第5页 / 共48页
点击查看更多>>
资源描述

《数字图像处理第3章ppt课件》由会员分享,可在线阅读,更多相关《数字图像处理第3章ppt课件(48页珍藏版)》请在金锄头文库上搜索。

1、3.1 3.1 3.1 3.1 背景知识背景知识背景知识背景知识第三章第三章 亮度变换与空间滤波亮度变换与空间滤波空间域技术直接对图像像素进行操作:g(x,y)=Tf(x,y)数字图像处理-第3章3.2 3.2 3.2 3.2 亮度变换函数亮度变换函数亮度变换函数亮度变换函数s=T(r)3.2.1 imadjust函数g=imadjust(f,low_in high_in, low_out high_out, gamma)3.2.1 imadjust函数g=imadjust(f,low_in high_in, low_out high_out, gamma)数字图像处理-第3章例3.1:使用函

2、数imadjust%使用函数 imadjust目的:突出我们感兴趣的亮度带压缩灰度级的低端并扩展灰度级的高端clcclearf=imread(Fig0303(a)(breast).tif);figureimshow(f)g1=imadjust(f,0,1,1,0);%=imcomplement(f)灰度反转 灰度负片figureimshow(g1)g2=imadjust(f,0.5,0.75,0,1);%突出我们感兴趣的亮度带figureimshow(g2)g3=imadjust(f,2);%压缩灰度级的低端并扩展灰度级的高端figureimshow(g3)数字图像处理-第3章数字图像处理-第

3、3章3.2.2 对数和对比度拉伸变换对数变换:gc*log(1+double(f)对比度拉伸:对比度拉伸的matlab实现:g1. /(1+(m./(double(f)+eps).E)数字图像处理-第3章例3.2:使用对数变换减少动态范围%例3.2使用对数变换减小动态范围经典的阈值函数clcclearf=imread(Fig0305(a)(spectrum).tif);figuresubplot(121),imshow(f),subplot(122),imhist(f),axistightg=im2uint8(mat2gray(log(1+double(f);figuresubplot(121

4、),imshow(g),title(使用对数变换减小动态范围)subplot(122),imhist(g),axistight%对比度拉伸变换m=5;E=10;h=im2uint8(mat2gray(1./(1+(m./(double(f)+eps).E);figuresubplot(121),imshow(h),title(对比度拉伸)subplot(122),imhist(h),axistight数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章3.2.3 亮度变换的一些使用M函数处理可变数量的输入和输出:输入:n=nargin输出:n=nargout亮度变换的第二个M函数:g=

5、changeclass(newclass,f)编写intrans格式化函数:intrans.m,程序略。例3.3:函数intrans.m的应用%例3.3P51intrans灰度变换的十项全能函数clcclearf=imread(Fig0306(a)(bone-scan-GE).tif);figureimshow(f)g=intrans(f,stretch,mean2(im2double(f),0.9);figureimshow(g)数字图像处理-第3章数字图像处理-第3章3.3 3.3 3.3 3.3 直方图处理与函数绘图直方图处理与函数绘图直方图处理与函数绘图直方图处理与函数绘图3.3.1:

6、生成并绘制函数的直方图直方图定义:图像中各灰度级的统计值,归一化直方图:Matlab核心函数:h=inhist(f,b)例3.4 计算并绘制图像直方图f=imread(Fig0303(a)(breast).tif);%读取原图像h=imhist(f);%直方图函数h1=h(1:10:256);horz=1:10:256;数字图像处理-第3章figuresubplot(121),imshow(f),subplot(122),imhist(f)%绘制原图和默认直方图数字图像处理-第3章figure%用bar函数绘制直方图并调整bar(horz,h1)axis(0255015000)set(gca,

7、xtick,0:50:255)set(gca,ytick,0:2000:15000)figure%用bar函数绘制直方图bar(horz,h1)数字图像处理-第3章figurestem(horz,h1,fill)%用stem函数绘制直方图axis(0255015000)set(gca,xtick,0:50:255)set(gca,ytick,0:2000:15000)figureplot(h)%用plot函数绘制直方图axis(0255015000)set(gca,xtick,0:50:255)set(gca,ytick,0:2000:15000)数字图像处理-第3章3.3.2:直方图均衡化对

8、输入图像执行如下变换,得到输出后的灰度级s:所以输出灰度级的概率密度是均匀的:使用直方图并调用直方图均衡化技术来处理离散灰度级时,因为变量的离散属性,处理后的图像直方图不再均匀,对应离散的灰度级,均衡变换采用求和方式变为:数字图像处理-第3章直方图均衡化的matlab函数为histeq:g=histeq(f,nlev)例3.5 直方图均衡化%例3.5直方图均衡化 默认为64clcclearf=imread(Fig0308(a)(pollen).tif);figure,subplot(121),imshow(f),subplot(122),imhist(f)ylim(auto)g=histeq(

9、f,256);figure,subplot(121),imshow(g),subplot(122),imhist(g)ylim(auto)g=histeq(f,128);figure,subplot(121),imshow(g),subplot(122),imhist(g)ylim(auto)g=histeq(f);%默认为64figure,subplot(121),imshow(g),subplot(122),imhist(g)ylim(auto)g=histeq(f,8);figure,subplot(121),imshow(g),subplot(122),imhist(g)ylim(au

10、to)数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章3.3.3:直方图归定化(匹配)已知输入图像灰度级的概率密度函数P(r),输出灰度级的概率密度函数p(z)(给定),则:得到均衡化后的概率密度函数p(s),定义一个变量z,满足:综合后得到:由输入图像得到T(r),只要找到 ,就可以使用上式得到变换后的灰度级z。Matlab工具箱中可用如下函数实现直方图归定化:g=histeq(f,hspec)数字图像处理-第3章例3.6:直方图归定化(匹配)对一幅火星卫星图像,直方图均衡化得不到好的处理效果:%例3.6直方图均衡化的缺陷 默认为64clcclearf=imr

11、ead(Fig0310(a)(MoonPhobos).tif);subplot(121),imshow(f),subplot(122),imhist(f)ylim(auto)gT=histeq(f,256);figure,subplot(121),imshow(g),subplot(122),imhist(g)ylim(auto)g=histeq(f);%默认为64figure,subplot(121),imshow(g),subplot(122),imhist(g)ylim(auto)g=histeq(f,8);figure,subplot(121),imshow(g),subplot(12

12、2),imhist(g)ylim(auto)%对应变换x=linspace(0,1,256);figure,plot(x,T)axis(0101)数字图像处理-第3章采用交互式直方图匹配,首先计算一个已归一化到单位区域的双峰值高斯函数:functionp=twomodegauss(m1,sig1,m2,sig2,A1,A2,k)%TWOMODEGAUSSGeneratesatwo-modeGaussianfunction.%P=TWOMODEGAUSS(M1,SIG1,M2,SIG2,A1,A2,K)generatesatwo-mode,%Gaussian-likefunctioninthei

13、nterval0,1.Pisa256-elementvectornormalized%sothatSUM(P)equals1.Themeanandstandarddeviationofthemodesare%(M1,SIG1)and(M2,SIG2),respectively.A1andA2aretheamplitudevaluesof%thetwomodes.Sincetheoutputisnormalized,onlytherelative%valuesofA1andA2areimportant.Kisanoffsetvaluethatraisesthefloorof%thefunctio

14、n.AgoodsetofvaluestotryisM1=0.15,S1=0.05,M2=0.75,S2=0.05,%A1=1,A2=0.07,andK=0.002.c1=A1*(1/(2*pi)0.5)*sig1);k1=2*(sig12);c2=A2*(1/(2*pi)0.5)*sig2);k2=2*(sig22);z=linspace(0,1,256);p=k+c1*exp(-(z-m1).2)./k1)+c2*exp(-(z-m2).2)./k2);p=p./sum(p(:);数字图像处理-第3章从键盘输入交互式信息,绘制高斯函数:functionp=manualhist%Agoodse

15、tofstartingvaluesis:(0.15,0.05,0.75,0.05,1,0.07,0.002).%Initialize.repeats=true;quitnow=x;%Computeadefaulthistogramincasetheuserquitsbeforeestimatingatleastonehistogram.p=twomodegauss(0.15,0.05,0.75,0.05,1,0.07,0.002);%Cycleuntilanxisinput.whilerepeatss=input(Enterm1,sig1,m2,sig2,A1,A2,kORxtoquit:,s

16、);ifs=quitnowbreakend数字图像处理-第3章%Converttheinputstringtoavectorofnumericalvaluesand%verifythenumberofinputs.v=str2num(s);ifnumel(v)=7disp(Incorrectnumberofinputs)continueendp=twomodegauss(v(1),v(2),v(3),v(4),v(5),v(6),v(7);%Startanewfigureandscaletheaxes.Specifyingonlyxlim%leavesylimonauto.figure,plo

17、t(p)xlim(0255)end数字图像处理-第3章调用函数,实现直方图归定化(匹配)%例3.6直方图匹配(交互方式)clcclearf=imread(Fig0310(a)(MoonPhobos).tif);p=manualhist;plot(p)figure,subplot(121),imshow(f),subplot(122),imhist(f),ylim(auto)g=histeq(f,p);figure,subplot(121),imshow(g),subplot(122),imhist(g),ylim(auto)数字图像处理-第3章输入交互参数:0.15,0.05,0.75,0.0

18、5,1,0.07,0.002(此处为默认,直接输入x同),得到双峰归定化直方图:数字图像处理-第3章运行后的归定化均衡效果:数字图像处理-第3章3.4空间滤波3.4.1线性空间滤波线性空间滤波也称为空间卷积运算,选取一适当的滤波模板MN,对图像中的每个像素依次进行卷积运算,其滤波原理如右图所示。数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章Matlab工具箱采用imfilter函数来实现线性空间滤波:g=imfilter(f,w,filtering_mode,boundary_options,size_options)在使用预先旋转的滤波器或者对称滤波器时,可以用两种方法实现卷积

19、运算:数字图像处理-第3章第一是采用如下语法实现:G=imfilter(f,w,conv,replicate)第二是采用函数rot90(w,2)将w旋转180度,然后使用函数:imfilter(f,w,replicate)来实现。例3.7使用函数imfilter%imfilter线性空间滤波(空间卷积)clcclearf=imread(Fig0315(a)(original_test_pattern).tif);f=im2double(f);figureimshow(f),title(原图象)w=ones(31);%设置滤波器数字图像处理-第3章gd=imfilter(f,w);figures

20、ubplot(221),imshow(gd,),title(使用默认零填充的结果)%figure%imshow(gd)gr=imfilter(f,w,replicate);%figuresubplot(222),imshow(gr,),title(选用replicate的结果)gc=imfilter(f,w,symmetric);subplot(223),imshow(gc,),title(选用symmetric的结果)gc=imfilter(f,w,circular);subplot(224),imshow(gc,),title(选用circular的结果)f8=im2uint8(f);%将

21、原图转换为unit8类型gr8=imfilter(f8,w,replicate);%转换为unit8类型后的replicate结果figure,imshow(gr8,),title(转换为unit8类型后的replicate结果)数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章Matlab工具箱中有两个非线性空间滤波函数nlfilter和colfilt。Nlfilter直接执行二维操作,colfilt以列的形式组织数据,且速度较快,在一般的非线性滤波中常用colfilt函数。语法:g=colfilt(f,m,n,sliding,fun,parameters)3.4.2非线性空间滤波

22、Matlab工具箱中有两个非线性空间滤波函数nlfilter和colfilt。Nlfilter直接执行二维操作,colfilt以列的形式组织数据,且速度较快,在一般的非线性滤波中常用colfilt函数。语法:g=colfilt(f,m,n,sliding,fun,parameters)在使用colfilt函数前,必须先用padarray函数执行边界填充:Fp=padarray(f,rc,method,direction)数字图像处理-第3章%padarrayclcclearf=1234frp=padarray(f,32,replicate,post)frb=padarray(f,32,repl

23、icate,both)%默认bothfrpre=padarray(f,32,replicate,pre)fsp=padarray(f,32,symmetric,post)fsb=padarray(f,56,symmetric,both)%默认bothfspre=padarray(f,32,symmetric,pre)fcp=padarray(f,32,circular,post)fcb=padarray(f,56,circular,both)%默认bothfcpre=padarray(f,32,circular,pre)数字图像处理-第3章3.5图像工具箱的标准空间滤波器3.5.1线性空间滤波

24、器生成滤波掩模函数fspecial:w=fspecial(type,parameters)数字图像处理-第3章数字图像处理-第3章例3.9使用函数imfilter对月球图像进行滤波%3.9fspecialP75产生各种线性空间滤波器 ( fspecial+imfilter)clcclearf=imread(Fig0316(a)(moon).tif);figuresubplot(221),imshow(f),title(原图)w=fspecial(laplacian,0);g1=imfilter(f,w,replicate);subplot(222),imshow(g1,),title(拉普拉斯

25、滤波后的unit8图像)f2=im2double(f);%imfinfoMy(f2)g2=imfilter(f2,w,replicate);subplot(223),imshow(g2,),title(拉普拉斯滤波后的double图像)g=f2-g2;subplot(224),imshow(g,),title(增强后的图像,即原图中减去double滤波后的图像)%figure,imshow(g),title(非参数定位滤波后的图像)数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章例3.10手工指定滤波器和增强技术的比较%3.10laplacianf=imread(Fig0316(a

26、)(moon).tif);figure,imshow(f),title(原图)w4=fspecial(laplacian,0);w8=111;1-81;111;f=im2double(f);g4=f-imfilter(f,w4,replicate);g8=f-imfilter(f,w8,replicate);figuresubplot(211),imshow(imfilter(f,w4,replicate)title(使用中心为-4的拉普拉斯滤波器增强后的图像)subplot(212),imshow(imfilter(f,w8,replicate)title(使用中心为-8的拉普拉斯滤波器增强

27、后的图像)figuresubplot(211),imshow(g4),title(使用中心为-4的拉普拉斯滤波器增强后的图像)subplot(212),imshow(g8),title(使用中心为-8的拉普拉斯滤波器增强后的图像)数字图像处理-第3章数字图像处理-第3章数字图像处理-第3章3.5.2非线性空间滤波器Matlab工具箱中可以利用函数ordfilt2来生成非线性空间滤波器,其响应基于对图像领域中所包含的像素进行排序,然后使用排序结果确定的值来替代领域中的中心像素值。ordfilt2的语法:g=ordfilt2(f,order,domain)实现大小为mn的最小滤波器,语法为:g=o

28、rdfilt2(f,1,ones(m,n)实现大小为mn的最大滤波器,语法为:g=ordfilt2(f,m*n,ones(m,n)数字图像处理中最著名的统计排序滤波器是中值滤波器,使用ordfilt2来创建一个中值滤波器:g=ordfilt2(f,median(1:m*n),ones(m,n)数字图像处理-第3章函数median的通用语法:v=median(A,dim)二维中值滤波函数:g=mmedfilt2(f,m,n,padopt)例3.11使用函数medfilt2进行中值滤波clcclearf=imread(Fig0318(a)(ckt-board-orig).tif);figuresubplot(221),imshow(f)fn=imnoise(f,salt&pepper,0.2);subplot(222),imshow(fn)gm=medfilt2(fn);subplot(223),imshow(gm)gms=medfilt2(fn,symmetric);subplot(224),imshow(gms)数字图像处理-第3章数字图像处理-第3章

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号