当前位置:文档之家› 图像增强与平滑实验报告

图像增强与平滑实验报告

实验一图像增强与平滑一.实验目的及要求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'); % R eads the sample images ‘ pout.tif’, and stores it inimshow(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 new 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执行结果如下:Command窗口:ans =Filename: 'pout2.png'FileModDate: '29-Apr-2006 15:33:34'FileSize: 36938Format: 'png'FormatVersion: []Width: 240Height: 291BitDepth: 8ColorType: 'grayscale'FormatSignature: [137 80 78 71 13 10 26 10]Colormap: []Histogram: []InterlaceType: 'none'Transparency: 'none'SimpleTransparencyData: []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: []上述命令窗口显示的是图片pout2.png的相关信息,包括文件名- 'pout2.png'、文件最后修改时间-'29-Apr-2006 15:33:34'、文件大小-36938、图片格式-'png'、格式版本、图片宽度-240、图片高度-291、图像像素值所占用的二进制位数-8、图像类型- 'grayscale'等等。

下面是所显示的图像:原图像原图像的灰度直方图利用直方图均衡化函数处理后的图像图像被均衡化后的灰度直方图Matlab均衡化函数的函数曲线图以.png格式保存后的图像对实验结果分析如下:由以上有关图像对比可以看出,经过均衡化的图像比原图像更富有层次感,对比度更加明显,图像效果也显得更为好一些。

从原图像的灰度直方图和变换后的灰度直方图可以看出,均衡化函数拉伸了原图像灰度值较为密集的部分(大约在75-150归一化为0.3-0.6),从而使图像的灰度范围得以扩大,灰度值更加均匀而非原图像的集中分布,所以原图像却是灰蒙蒙的,变换后的图像显得非常清亮。

2.直接灰度变换clear all; close allI = imread('cameraman.tif'); J = imadjust(I,[0 0.2],[0.5 1]); imshow(I)figure, imshow(J) 注意: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(RGB1,...)[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 % Display 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 thevalues in intensity image I to new values in J such that values betweenLOW_IN and HIGH_IN map to values between LOW_OUT and HIGH_OUT. V aluesbelow LOW_IN and above HIGH_IN are clipped; that is, values below LOW_INmap to LOW_OUT, and those above HIGH_IN map to HIGH_OUT. You can use anempty matrix ([]) for [LOW_IN HIGH_IN] or for [LOW_OUT HIGH_OUT] tospecify the default of [0 1]. GAMMA specifies the shape of the curvedescribing the relationship between the values in I and J. If GAMMA isless than 1, the mapping is weighted toward higher (brighter) outputvalues. 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 = 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 mappingapplies to red, green and blue components. Unique mappings for eachcolor component are possible when:LOW_IN and HIGH_IN are both 1-by-3 vectors,LOW_OUT and HIGH_OUT are both 1-by-3 vectors, ORGAMMA 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 colormapadjustment, you can apply unique mappings to each plane.Note that if HIGH_OUT < LOW_OUT, the output image is reversed, as in aphotographic negative.The function STRETCHLIM can be used with IMADJUST to apply anautomatically computed contrast stretch.Class Support-------------For syntaxes that include 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 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有所了解,以来分析函数作用的结果。

相关主题