




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验一 图像增强与平滑一实验目的及要求1了解matlab的操作环境和基本功能。2掌握matlab中图像增强与平滑的函数的使用方法。3加深理解图像增强与平滑的算法原理。二、实验内容(一)研究以下程序,分析程序功能;输入执行各命令行,认真观察命令执行的结果。熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结果。(可将每段程序保存为一个.m文件)1直方图均衡clear all; close all % clear the matlab workspace of any variables % and close open figure windows。i = imread(pout.tif);
2、 % reads the sample images pout.tif, and stores it in imshow(i) % an array named i.display the imagefigure, imhist(i) % create a histogram of the image and display it in % a new figure window.i2,t = histeq(i); % histogram equalization.figure, imshow(i2) % display the new equalized image, i2, in a ne
3、w figure window.figure, imhist(i2) % create a histogram of the equalized image i2.figure,plot(0:255)/255,t); % plot the transformation curve.imwrite (i2, pout2.png); % write the newly adjusted image i2 to a disk file named% pout2.png.imfinfo(pout2.png) % check the contents of the newly written file执
4、行结果如下:command窗口:ans = filename: pout2.png filemoddate: 29-apr-2006 15:33:34 filesize: 36938 format: png formatversion: width: 240 height: 291 bitdepth: 8 colortype: grayscale formatsignature: 137 80 78 71 13 10 26 10 colormap: histogram: interlacetype: none transparency: none simpletransparencydata:
5、 backgroundcolor: renderingintent: chromaticities: gamma: xresolution: yresolution: resolutionunit: xoffset: yoffset: offsetunit: significantbits: imagemodtime: 29 apr 2006 07:33:34 +0000 title: author: description: copyright: creationtime: software: disclaimer: warning: source: comment: othertext:
6、上述命令窗口显示的是图片pout2.png的相关信息,包括文件名- pout2.png、文件最后修改时间-29-apr-2006 15:33:34、文件大小-36938、图片格式-png、格式版本、图片宽度-240、图片高度-291、图像像素值所占用的二进制位数-8、图像类型- grayscale等等。下面是所显示的图像:原图像 原图像的灰度直方图利用直方图均衡化函数处理后的图像 图像被均衡化后的灰度直方图 matlab均衡化函数的函数曲线图 以.png格式保存后的图像对实验结果分析如下:由以上有关图像对比可以看出,经过均衡化的图像比原图像更富有层次感,对比度更加明显,图像效果也显得更为好一些
7、。从原图像的灰度直方图和变换后的灰度直方图可以看出,均衡化函数拉伸了原图像灰度值较为密集的部分(大约在75-150归一化为0.3-0.6),从而使图像的灰度范围得以扩大,灰度值更加均匀而非原图像的集中分布,所以原图像却是灰蒙蒙的,变换后的图像显得非常清亮。注意:imadjust()功能:调整图像灰度值或颜色映像表,也可实现伽马校正。语法:j = imadjust(i,low_in high_in,low_out high_out,gamma)newmap = imadjust(map,low_in high_in,low_out high_out,gamma)rgb2 = imadjust(r
8、gb1,.)2直接灰度变换clear all; close alli = imread(cameraman.tif);j = imadjust(i,0 0.2,0.5 1);imshow(i)figure, imshow(j)x,map = imread(forest.tif);figure,imshow(x,map)i2 = ind2gray(x,map);j2 = imadjust(i2,0.5); figure,imshow(i2)figure, imshow(j2)j3 = imadjust(i2,1.5); figure, imshow(j3)help imadjust % disp
9、lay the imadjust() function information.程序执行结果如下:command窗口:imadjust adjust image intensity values or colormap. j = imadjust(i,low_in high_in,low_out high_out,gamma) maps the values in intensity image i to new values in j such that values between low_in and high_in map to values between low_out and h
10、igh_out. values below low_in and above high_in are clipped; that is, values below low_in map to low_out, and those above high_in map to high_out. you can use an empty matrix () for low_in high_in or for low_out high_out to specify the default of 0 1. gamma specifies the shape of the curve describing
11、 the relationship between the values in i and j. if gamma is less than 1, the mapping is weighted toward higher (brighter) output values. if gamma is greater than 1, the mapping is weighted toward lower (darker) output values. if you omit the argument, gamma defaults to 1 (linear mapping). newmap =
12、imadjust(map,low_in; high_in,low_out; high_out,gamma) transforms the colormap associated with an indexed image. if low_in, high_in, low_out, high_out, and gamma are scalars, then the same mapping applies to red, green and blue components. unique mappings for each color component are possible when: l
13、ow_in and high_in are both 1-by-3 vectors, low_out and high_out are both 1-by-3 vectors, or gamma is a 1-by-3 vector. the rescaled colormap, newmap, is the same size as map. rgb2 = imadjust(rgb1,.) performs the adjustment on each image plane (red, green, and blue) of the rgb image rgb1. as with the
14、colormap adjustment, you can apply unique mappings to each plane. note that if high_out low_out, the output image is reversed, as in a photographic negative. the function stretchlim can be used with imadjust to apply an automatically computed contrast stretch. class support - for syntaxes that inclu
15、de an input image (rather than a colormap), the input image can be of class uint8, uint16, or double. the output image has the same class as the input image. for syntaxes that include a colormap, the input and output colormaps are of class double. examples - i = imread(pout.tif); j = imadjust(i,0.3
16、0.7,); imshow(i), figure, imshow(j) rgb1 = imread(flowers.tif); rgb2 = imadjust(rgb1,.2 .3 0; .6 .7 1,); imshow(rgb1), figure, imshow(rgb2) see also brighten, histeq, stretchlim.下面是所显示的图像: 原图像 灰度调整后的图像原彩色图像 原灰度图像 参数为0.5的灰度调整函数调整后的结果 参数为1.5的灰度调整函数调整后的结果对实验结果分析如下:通过查看命令窗口所显示的信息,对imadjus有所了解,以来分析函数作用的结
17、果。对于图像cameraman.tif, imadjust共有四个参数,程序中对该图像调整时,默认第四个参数为1,即进行线性变换。函数将0 0.2范围内的灰度对应到0.5 1,其余像素值不变,即0对应0.5,0.2对应1,其余像素值可根据直线方程类推,通过调整,图像中大于0.5的像素值大量增多,而小于0.2的像素经过调整已经没有了,所以整个图像显得比原图像明亮。对图像forest.tif,imadjust的第四个参数分别设置为0.5和1.5.上面已经提到如果第四个参数设置为1,即进行线性变换,而如果小于1则增强低灰度范围,相应的大于1则增强高灰度范围。由上面的第5、6、7幅图可以看出,参数设置
18、为0.5的图像明显比原灰度图像偏亮,而参数设置为1.5的图像与原灰度图像的效果差不多。这是因为,参数设置为0.5时,增强了低灰度值,从而使低灰度值的像素减少,高灰度值的像素增多,从而使图像变亮。而参数设置为1.5时,增强的是高灰度范围,对于低灰度范围没有影响,而且本身高灰度值效果就偏亮,所以函数作用效果有限,所以看上去与原灰度图像效果差不多。3空域平滑滤波(模糊、去噪)clear all; close alli = imread(eight.tif);h1 = ones(3,3) / 9;h2 = ones(5,5) / 25;i1 = imfilter(i,h1);i2 = imfilter
19、(i,h2);figure(1), imshow(i), title(original image);figure(2), imshow(i1), title(filtered image with 3*3 )figure(3), imshow(i2), title(filtered image with 5*5 )j1 = imnoise(i,gaussian,0,0.005); % 加入gaussian 噪声j2 = imnoise(i,salt & pepper,0.02); % 加入椒盐噪声% 对j1、j2进行平均值平滑滤波k1 = imfilter(j1,fspecial(avera
20、ge,3);k2 = imfilter(j2,fspecial(average,3);figure(4);subplot(2,2,1), imshow(j1) , title(gaussian);subplot(2,2,2), imshow(j2), title(salt & pepper );subplot(2,2,3), imshow(k1), title(average );subplot(2,2,4), imshow(k2);% 对j1、j2进行中值滤波k3 = medfilt2(j1,3 3);k4 = medfilt2(j2,3 3);figure(5);subplot(2,2,1
21、), imshow(j1) , title(gaussian);subplot(2,2,2), imshow(j2), title(salt & pepper );subplot(2,2,3), imshow(k3), title( median filtering );subplot(2,2,4), imshow(k4)程序执行结果如下:对以上实验结果分析如下: 由于没有添加噪声,所以看不出滤波效果。但是从上图可以看出,滤波后图像有点模糊,而使用5*5的邻域窗口滤波后的图像模糊的更加明显。这是因为,均值滤波采用计算邻域窗口的均值代替自身的像素值来滤波,邻域窗口越大,参与平均计算的像素增多,虽
22、然滤波效果也更为明显,特别是针对颗粒状噪声有很好的滤除效果,但同样也会使图像中物体的像素值产生更大的变化,反映在图像上就是物体显得更加模糊。 对以上实验结果分析如下: 中值滤波采用的是邻域的中值代替像素原来的值,所以原像素值受异常值的影响相对均值滤波要小的多,由中值滤波后的图像可以看出,图像并非像均值滤波那样显得模糊。下面比较一下均值滤波和中值滤波。对于同为3*3邻域窗口,对于椒盐噪声,中值滤波效果要好于均值滤波,而对于高斯噪声两者差不多。对于椒盐噪声,由均值滤波效果可以看出,噪声明显接近背景颜色,有一定滤波效果,如果邻域窗口变成5*5的一定会对噪声起到更好的滤除作用,但负面作用是会使图像变得
23、更加模糊。而中值滤波,由于采用的中值,所以对于颗粒状的物体也可以很好的滤出。而对于高斯噪声,噪声符合一定分布,均值、中值对像素值的作用有限,所以虽然有一定的滤波作用,但并不能彻底消除噪声,可以尝试维纳滤波等其它滤波方法。4空域锐化滤波clear all; close all;i = imread(moon.tif);w=fspecial(laplacian,0),w8=1,1,1;1,-8,1;1,1,1i1= imfilter(i,w, replicate);figure(1); imshow(i), title(original image);figure(2), imshow(i1),
24、title(laplacian image);f = im2double(i);f1= imfilter(f,w, replicate);figure(3), imshow(f1,), title(laplacian image);f2= imfilter(f,w8, replicate);f4 = f-f1;f8 = f-f2;figure(4), imshow(f4);figure(5), imshow(f8); f4=f-f1 f8=f-f2对以上实验结果分析如下:程序中先对原图像采用拉普拉斯算子对原图像进行锐化,然后再将图像像素值转化成double类型,之后再进行拉普拉斯算子和一个自编的算子进行锐化。由上图可以看出,两个拉普拉斯滤波后的图像虽然亮度不一样,但是特征并没有多少差异,这是因为像素值转化为double类型时,像素值进行了相应变化。由于算子本身有滤波作用,而且可以增强图像的边缘轮廓,所以计算f4 = f-f1;f8 = f-f2;然后再显示f4和f8,具体的边缘轮廓细节较原图像效果要好很多。5图像的伪彩色处理密度分割clear all, close alli = imread(ngc4024m.tif);x = grayslice(i,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 苏州工业园区服务外包职业学院《瑶族民歌演唱》2023-2024学年第二学期期末试卷
- 山东轻工职业学院《大学英语4B级》2023-2024学年第一学期期末试卷
- 湖南体育职业学院《中国现当代文学2》2023-2024学年第二学期期末试卷
- 宾川县2024-2025学年数学三下期末学业水平测试模拟试题含解析
- 阜阳幼儿师范高等专科学校《高等工程结构》2023-2024学年第二学期期末试卷
- 河南省长葛市第三实验高中2024-2025学年5月高考英语试题模练习(一)含解析
- 浙江农业商贸职业学院《数据可视化技术》2023-2024学年第二学期期末试卷
- 广州大学《舞蹈技能(男生)实训》2023-2024学年第二学期期末试卷
- 古代诗歌常识知识
- 针对大学生喜爱的舞种调研
- 腮腺炎病人护理常规
- 运用精益管理(TPS)缩短医院门诊患者就诊时间医院品质管理成果汇报
- 《铁路轨道维护》课件-混凝土枕硫磺改锚作业
- 2024解析:第十五章电流和电路-基础练(解析版)
- 2024年资助政策主题班会课件
- 安全生产责任体系重点岗位履职清单
- 四川省成都市2024年中考道德与法治真题试卷(含答案)
- 学校门卫室改造合同范例
- 大学物理实验(绪论)学习通超星期末考试答案章节答案2024年
- 不合格产品处置管理制度
- 《现代家政导论》电子教案 2.2模块二项目二家庭制度认知
评论
0/150
提交评论