1、数字图像处理上机报告2 数字图像处理第一次实习报告指导老师:傅华明姓名:班级: 数字图像处理上机实习1-0、基本要求1,显示一个灰度图象(在p01-p10中选)和彩色图象(在p13-p14中选);2,观察灰度图象和彩色图象的数据矩阵和文件内容;3,熟悉灰度图象、二值图象、彩色图象和索引图象之间的变换。1,显示一个灰度图象(在p01-p10中选)和彩色图象(在p13-p14中选);用inread函数可以直接显示出灰度图像和彩色图像,过程如下:i=imread(P08.tif);j=imread(P13.tif);subplot(1,2,1);imshow(i)Subplot(1,2,2);ims
2、how(j)2,观察灰度图象和彩色图象的数据矩阵和文件内容;观察数据矩阵 观察文件内容imfinfo(P08.tif)ans = Filename: D:matlabP08.tif FileModDate: 16-六月-2007 14:29:40 FileSize: 65710 Format: tif FormatVersion: Width: 256 Height: 256 BitDepth: 8 ColorType: grayscale FormatSignature: 73 73 42 0 ByteOrder: little-endian NewSubFileType: 0 BitsPe
3、rSample: 8 Compression: Uncompressed PhotometricInterpretation: BlackIsZero StripOffsets: 8 SamplesPerPixel: 1 RowsPerStrip: 4.2950e+009 StripByteCounts: 65536 XResolution: 72 YResolution: 72 ResolutionUnit: None Colormap: PlanarConfiguration: Chunky TileWidth: TileLength: TileOffsets: TileByteCount
4、s: Orientation: 1 FillOrder: 1 GrayResponseUnit: 0.0100 MaxSampleValue: 255 MinSampleValue: 0 Thresholding: 1 Offset: 655443,熟悉灰度图象、二值图象、彩色图象和索引图象之间的变换。 将彩色图像转换为灰度、二值、索引图像figure(1);R=imread(p13.tif);imshow(R);figure(2);I=rgb2gray(R);X,map=rgb2ind(R,0.4);BW=im2bw(R,0.5);subplot(2,2,1);imshow(R);title
5、(彩色);subplot(2,2,2);imshow(I);title(灰度);subplot(2,2,3);subimage(X,map);title(索引);subplot(2,2,4);subimage(BW);title(二值);将索引图像转换为二值、灰度、彩色图像figure(1);R=imread(p13.tif);imshow(R);figure(2);BW=im2bw(X,map,0.4);I=ind2gray(X,map);RGB=ind2rgb(X,map);subplot(2,2,1);subimage(X,map);title(索引);subplot(2,2,2);su
6、bimage(BW);title(二值);subplot(2,2,3);subimage(I);title(灰度);subplot(2,2,4);subimage(RGB);title(彩色);将灰度图像转化为二值图象: i=imread(P08.tif);I=im2bw(i,0.5);subplot(211);imshow(i);title(原图)subplot(212);imshow(I);title(二值图像);1-1对图象p03计算其灰度的直方图I=imread(P08.tif); J=I; L=256; nk=zeros(L,1); r,c=size(I); n=r*c; for i
7、 = 1:r for j = 1:c h= double(I(i,j)+1; %获取像素点灰度级 nk(h) = nk(h)+1; end end %计算直方图概率估计 figure; subplot(2,1,1);imshow(J),title(原图); subplot(2,1,2),plot(nk),title(直方图); 用累加法获得各灰度级数量。可以看出灰度级在50和150附近比较集中1-2对图象p08实施指数变换(公式4.1.8)I=imread(P08.tif);M,N=size(I);g=zeros(M,N);I=double(I);g=double(g);k1=min(min(
8、I);k2=max(max(I);a=(k2-k1)/2;b=k2-80;c=k1-20;for i=1:Mfor j=1:Ng(i,j)=b(c*(I(i,j)-a)-1;endendfigure;subplot(121);imshow(I,);subplot(122);imshow(g, );指数变换使能对图像的高灰度区进行较大的拉伸计算公式为:g(i,j)=b(c*(I(i,j)-a)-1;代入公式可得到变换后的灰度级。1-3图象p08施加高斯噪声和椒盐噪声并实施中值滤波法(X字窗口)用imnoise函数施加噪声,实施中值滤波法I=imread(P08.tif);subplot(321)
9、,imshow(I);title(原图);J=imnoise(I,gaussian);subplot(323),imshow(J);title(加高斯噪声);G=imnoise(I,salt,0.01);subplot(325),imshow(G);title(加椒盐噪声);m,n=size(J); mid=zeros(m,n);mid=uint8(mid);a=zeros(5,1);b=zeros(1,1);for t=1:5for i=2:m-1 for j=2:n-1 a(1,1)=J(i-1,j-1);a(2,1)=J(i-1,j+1);a(3,1)=J(i,j); a(4,1)=J(
10、i+1,j-1);a(5,1)=J(i+1,j+1); for k=1:5 for l=k+1:5 if a(k,1)=a(l,1) b(1,1)=a(k,1);a(k,1)=a(l,1);a(l,1)=b(1,1); end end end mid(i,j)=a(3,1); endendJ=mid;endsubplot(324),imshow(J);title( gaussian中值滤波)m,n=size(G); mid=zeros(m,n);mid=uint8(mid);a=zeros(5,1);b=zeros(1,1);for t=1:5for i=2:m-1 for j=2:n-1 a
11、(1,1)=G(i-1,j-1);a(2,1)=G(i-1,j+1);a(3,1)=G(i,j); a(4,1)=G(i+1,j-1);a(5,1)=G(i+1,j+1); for k=1:5 for l=k+1:5 if a(k,1)=a(l,1) b(1,1)=a(k,1);a(k,1)=a(l,1);a(l,1)=b(1,1); end end end mid(i,j)=a(3,1); endendG=mid;endsubplot(326),imshow(G);title( salt中值滤波);中值滤波后图像变得比原图模糊了一点,但是比加了噪声的图像的效果好一些。1-4根据Isotrop
12、ic算子,按照公式4.3.10和公式4.3.11对图象p08实施空间锐化 I,map=imread(P08.tif);H,W=size(I);M=double(I);J=M;for i=2:H-1; for j=2:W-1 J(i,j)=abs(M(i-1,j+1)-M(i-1,j-1)+sqrt(2)*(M(i,j+1)-sqrt(2)*(M(i,j-1)+M(i+1,j+1)-. M(i+1,j-1)+abs(M(i+1,j-1)-M(i-1,j-1)+sqrt(2)*(M(i+1,j)-sqrt(2)*(M(i-1,j)+M(i+1,j+1)-. M(i-1,j+1); endendsu
13、bplot(1,2,1);imshow(I);title(原图);subplot(1,2,2);imshow(uint8(J);title(锐化处理后);Gx,Gy=gradient(J);G=sqrt(Gx.*Gx+Gy.*Gy);J4=I;K=find(G=30);J4(K)=255;J5=I;K=find(G=50);J5(Q)=255;figure,subplot(121);imshow(J4,map);title(第四种图像增强);subplot(122);imshow(J5,map);title(第五种图像增强);锐化处理使得图像轮廓更加突出,第四种图像增强方式将图像背景用指定的灰度级来表现,便于研究边缘灰度的变化。第五种图像增强方式使得图像变为二值图像,便于研究边缘所在的位置。可以看出,第五种方式处理的图像可以清晰的看出边缘的位置。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1