实验一:图像文件类型转换实验目的:理解数字图像文件的几种基本类型掌握在MATLAB中进行图象文件类型转换的方法观察图象转换前后的效果加深对图象文件类型的理解熟悉图象格式、颜色系统间的转换实验内容:1)灰度图像与索引图像的相互转换2)RGB图像与索引图像的相互转换3)将图像转换为二值化图像实验方法:利用MATLAB工具进行实验一、灰度图像到索引图像的转换clearinfo=imfinfo('rice.png')info=Filename:'rice.png'FileModDate:'26-Jan-200300:03:06'FileSize:44607Format:'png'FormatVersion:[]Width:256Height:256BitDepth:8ColorType:'grayscale'FormatSignature:[13780787113102610]Colormap:[]Histogram:[]InterlaceType:'none'Transparency:'none'SimpleTransparencyData:[]BackgroundColor:[]RenderingIntent:[]Chromaticities:[]Gamma:[]XResolution:[]YResolution:[]ResolutionUnit:[]XOffset:[]YOffset:[]OffsetUnit:[]SignificantBits:[]ImageModTime:'27Dec200219:57:12+0000'Title:[]Author:[]Description:'Ricegrains'Copyright:'CopyrightTheMathWorks,Inc.'CreationTime:[]Software:[]Disclaimer:[]Warning:[]Source:[]Comment:[]OtherText:[]RGB=imread('rice.png');figure(3);imshow(RGB);figure(1);[RGB1,map1]=gray2ind(RGB,128);imshow(RGB1,map1);figure(2);[RGB2,map2]=gray2ind(RGB,16);imshow(RGB2,map2);imwrite(RGB1,map1,'3.bmp');imwrite(RGB2,map2,'4.bmp');图3图1图2实验结果分析:从上述实验结果,我们可以看出灰度级不同,图像的亮度也不一样。这是因为图像的量化灰度级数是256,灰度取值范围一般从0~255,在人的视觉系统中,不同的灰度值人感觉到的亮度不一样。我们调用函数info=imfinfo('3.bmp'),info=imfinfo('4.bmp')来检查得到的图像是不是索引图像,发现他们都是ColorType:'indexed',这就说明以3.bmp或4.bmp命名的文件是索引图像。以下是索引图到灰度图的转化:clear[x,map]=imread('3.bmp');figure(1),imshow(x);I=ind2gray(x,map);figure(2),imshow(I);图1图2二、RGB图像到索引图像的转换info=imfinfo('1646063.jpg')info=Filename:'1646063.jpg'FileModDate:'23-Mar-201015:54:36'FileSize:60317Format:'jpg'FormatVersion:''Width:320Height:226BitDepth:24ColorType:'truecolor'FormatSignature:''NumberOfSamples:3CodingMethod:'Huffman'CodingProcess:'Sequential'Comment:{}RGB=imread('1646063.jpg');figure(1);imshow(RGB);figure(2);y=rgb2ind(RGB,256);imwrite(y,'1s.bmp');imshow(y);实验结果分析:通过把图像的数据赋予给RGB图像,然后利用转换语句y=rgb2ind(RGB,256)把彩色图像转换为索引图,我们调用函数info=imfinfo('1s.bmp')检查所得图像是不是索引图,发现ColorType:'indexed',这就说明以1s.bmp命名的文件是索引图。以下是索引图转换二值图:[x,map]=imread('3.bmp');figure(1),imshow(x);RGB=ind2rgb(x,map);figure(2),imshow(RGB);三、RGB图像到二值图像的转换clearinfo=imfinfo('20081228224116246.jpg')info=Filename:'20081228224116246.jpg'FileModDate:'23-Mar-201015:55:03'FileSize:55227Format:'jpg'FormatVersion:''Width:580Height:483BitDepth:24ColorType:'truecolor'FormatSignature:''NumberOfSamples:3CodingMethod:'Huffman'CodingProcess:'Sequential'Comment:{'CompressedwithJPEGOptimizer4.00,}RGB=imread('20081228224116246.jpg');figure(3);imshow(RGB);bw1=im2bw(RGB,0.5);bw2=im2bw(RGB,0.6);figure(1);imshow(bw1);figure(2);imshow(bw2);图3图1图2实验结果分析:从实验结果可以看出,阈值不同,图像的清晰度也不一样。阈值的取值范围在[0,1]之间,它相当一个门限,输入图像的像素大于这个门限时就可以输出。以下为灰度图转换为二值图:ClearI=imread('rice.png');figure(3);imshow(I);bw1=im2bw(I,0.5);bw2=im2bw(I,0.6);figure(1);imshow(bw1);figure(2);imshow(bw2);图3图1图2实验二:图像变换实验目的:掌握图像变换的方法,观察图象变换的效果,熟悉图像傅立叶变换。实验内容:快速卷积实验,对图像进行傅立叶变换;实验方法:利用MATLAB图像处理工具箱进行实验一、傅立叶变换实验A=magic(3);B=ones(3);A(8,8)=0;B(8,8)=0;C=ifft2(fft2(A).*fft2(B));C=C(1:5,1:5);C=real(C)C=8.00009.000015.00007.00006.000011.000017.000030.000019.000013.000015.000030.000045.000030.000015.00007.000021.000030.000023.00009.00004.000013.000015.000011.00002.0000C=conv2(A,B);C=C(1:5,1:5)C=891576111730191315304530157213023941315112clearfigure(1);RGB=imread('cameraman.tif');imshow(RGB);figure(2);B=fftshift(fft2(RGB));imshow(log(abs(B)),[]),colormap(jet(64)),colorbar;468101214clearA=zeros(128);A(60:68,60:68)=1;figure(1);imshow(A);figure(2);B=fft2(A);imshow(B);C=fftshift(fft2(A));figure(3),imshow(C);figure(4);imshow(log(abs(C)),[]),colormap(jet(64)),colorbar;-6-4-2024实验三:数字图像滤波及边缘检测(综合性实验)实验目的:1)综合运用图像处理的基本原理方法,解决实际问题;2)学会使用Matlab中值滤波函数和图像处理并了解适用范围;3)了解函数imnoise的基本功能和输入参数的特点;4)掌握线性平滑滤波器和非线性平滑滤波器(中值滤波)的性能。5)掌握图象边缘检测的基本算法。实验内容:平滑滤波,中值滤波,边缘检测实验方法:利用MATLAB图像处理工具箱进行实验一、图象平滑滤波1.均值滤波(线性滤波)clearI=imread('kids.tif');imshow(I)I1=imnoise(I,'gaussian',0,0.02);figure,imshow(I1)h=[111;111;111];h=h/9;J=conv2(I1,h);figure,imshow(J,[])clearI=imread('kids.tif');imshow(I)I1=imnoise(I,'gaussian',0,0.02);figure,imshow(I1)h=[11111;11111;11111;11111;11111];h=h/9;J=conv2(I1,h);figure,imshow(J,[])clearI=imread('kids.tif');imshow(I)I1=imnoise(I,'gaussian',0,0.02);figure,imshow(I1)h=[1111111111111111111111111111111111111111111111111];h=h/9;J=conv2(I1,h);figure,imshow(J,[])2.中值滤波(非线性滤波)clearI=imread('kids.tif');J=imnoise(I,'gaussian',0.02);K=medfilt2(J);subplot(1,3,1),imshow(I);subplot(1,3,2),imshow(J);subplot(1,3,3),imshow(K);clearI=imread('Big_2009.jpg');J=imnoise(I,'gaussian',0.02);K=imnoise(I,'salt&pepper',0.02);subplot(1,3,1),imshow(I);subplot(1,3,2),imshow(J);subplot(1,3,3),imshow(K);小结:不同的滤波方法得出的效果不一样,同一种方法选择不同的参数得出的结果也不一样。如上图所示,对于中值滤波选择了3x3,5x5,7x7观察图形,清晰度不同。二、边缘检测clearI=imread('trees.tif');imshow(I)BW1=edge(I,'Roberts');figure,imshow(BW1)BW2=edge(I,'sobel');figure,imshow(BW2)BW3=edge(I,'Prewitt');figure,imshow(BW3)小结:边缘检测的方法也有很多,不同的检测方法提取的信息也不一样,该实验中,选择了'Roberts