资源描述:
《杨宇明《数字图像处理》《数字图像处理》书中代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、例1-1m=uint8(zeros(128,128丄27));fori=l:27[m(:,:/:/i),map]=imread('mri.t讦:i);endmontage(m,map)例2-1a=imread('cameraman.tif);figure(l);imshow(a);bl=a+5O;figure(2);imshow(bl);b2=1.2*a;figure(3);imshow(b2)b3=0.65*a;%读入cameraman图像%bl=a+45图像灰度值增加45%b=1.2*a图像对比度增大%b=0.65*a图像对比度减少figure(4);imsho
2、w(b3);b4=-double(a)+255;%b4=-l*a+255,图像求补,注意把a的类型转换为doublefigure(5);imshow(uint8(b4));%再把double类型转换为unit8例2-2%读入lena图像a=imread('cameraman.tif');%读取原始图像figure(l);imshow(a);%显示原始图像xlabel('(a)原始图像');%显示函数J(x)的曲线图x=l:255;y=x+x.*(255-x)/255;figure(2);plot(x,y);xlabel('(b)函数J(x)的曲线图');bl=dou
3、ble(a)+0.006*double(a).*(255-double(a));figure⑶;imshow(uint8(bl));%显示非线性处理图像xlabel('(c)非线性处理效果');例2-3clear;%%读入图像a=imread('cameraman/df);imhist(a);title(源始cameraman图像的直方图');%%b=f(a)bl=1.25*double(a)+45;figure(2);imhist(uint8(bl));title('变换后的直方图J;例2-4clear;histgram=zeros(l,256);%生成直方图数组
4、cdf=zeros(l,256);[cm,map]=imread(,cameraman.t讦);[a,b]=size(cm);fori=l:aforj=l:bk=cm(i,j);histgram(k)=histgram(k)+l;endend%得到直方图cdf(l)=histgram(l);fori=2:256cdf(i)=cdf(i-l)+histgram(i);endfori=l:a%点运算fori=l:bk=cm(i,j);cm_equ(ij)=cdf(k)*25^(a*b);endendimshow(uint8(cm_equ));figure(2);imhi
5、st(uint8(cm_equ));例2-5l=imread('tire.tif');J=histeq(l);H=adapthisteq(l);figure⑴,imshow(l);xlabelf原始图像');figure(2),imshow(J);xlabelfhisteq均衡化');figure(3),imshow(H);xlabelfadapthisteq均衡化');例2-6a=imread('hill.jpg');s=size(a);b=double(a);c(:/:/l)=b(:/:/l)+b(:,:/2);c(:,:,2)=b(:,:,2);c(:,:,3
6、)=b(:,:,3)・b(:,:,2);fori=l:s(l)forj=l:s(2)fork=l:s(3)ifc(i,j,k)vOc(i,j,k)=O;endifc(ijk)>255c(ij,k)=255;endendendendc=uint8(c);subplot(121);imshow(a);xlabel('原始图像');subplot(122);imshow(c);xlabel('新图像');例2-7a=imread('eight.tif,);al=imnoise(a,'gaussian',0,0.006);%对原始图像加高斯噪声,共得到4幅图像a2=imno
7、ise(a,'gaussian',0,0.006);a3=imnoise(a,'gaussian',0,0.006);a4=imnoise(a,'gaussian'z0,0.006);k=imlincomb(0.25,al,0.25,a2,0.25,a3,0.25,a4);%线性组合subplot(131);imshow(a);subplot(132);imshow(al);subplot(133);imshow(k,[]);例2-8clear;a=imread('rice.png');%读取图像figure(l);imshow(a);%显示原始图像backgr