数字图像处理实验报告(三四五).doc
《数字图像处理实验报告(三四五).doc》由会员分享,可在线阅读,更多相关《数字图像处理实验报告(三四五).doc(26页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、-_实验三 图像的几何变换一实验目的及要求掌握图像几何变换的基本原理,熟练掌握数字图像的缩放、旋转、平移、 镜像和转置的基本原理及其 MATLAB 编程实现方法。二、二、实验内容(一)研究以下程序,分析程序功能;输入执行各命令行,认真观察命令 执行的结果。熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结 果。1.1. 图像缩放图像缩放 clear all, close all I = imread(cameraman.tif); Scale = 1.35; % 将图像放大1.35倍 J1 = imresize(I, Scale, nearest); % using the neares
2、t neighbor interpolation J2 = imresize(I, Scale, bilinear); % using the bilinear interpolation imshow(I), title(Original Image); figure, imshow(J1), title(Resized Image- using the nearest neighbor interpolation ); figure, imshow(J2), title(Resized Image- using the bilinear interpolation ); % 查看imres
3、ize使用帮助 help imresizeCommand窗口显示如下: IMRESIZE Resize image.B = IMRESIZE(A, SCALE) returns an image that is SCALE times thesize of A, which is a grayscale, RGB, or binary image.B = IMRESIZE(A, NUMROWS NUMCOLS) resizes the image so that it hasthe specified number of rows and columns. Either NUMROWS or
4、NUMCOLSmay be NaN, in which case IMRESIZE computes the number of rows orcolumns automatically in order to preserve the image aspect ratio.Y, NEWMAP = IMRESIZE(X, MAP, SCALE) resizes an indexed image.Y, NEWMAP = IMRESIZE(X, MAP, NUMROWS NUMCOLS) resizes an indexedimage.-_To control the interpolation
5、method used by IMRESIZE, add a METHODargument to any of the syntaxes above, like this:IMRESIZE(A, SCALE, METHOD) IMRESIZE(A, NUMROWS NUMCOLS, METHOD),IMRESIZE(X, MAP, M, METHOD)IMRESIZE(X, MAP, NUMROWS NUMCOLS, METHOD)METHOD can be a string naming a general interpolation method:nearest - nearest-nei
6、ghbor interpolationbilinear - bilinear interpolationbicubic - cubic interpolation; the default methodMETHOD can also be a string naming an interpolation kernel:box - interpolation with a box-shaped kerneltriangle - interpolation with a triangular kernel(equivalent to bilinear)cubic - interpolation w
7、ith a cubic kernel (equivalent to bicubic)lanczos2 - interpolation with a Lanczos-2 kernellanczos3 - interpolation with a Lanczos-3 kernelFinally, METHOD can be a two-element cell array of the form f,w,where f is the function handle for a custom interpolation kernel, andw is the custom kernels width
8、. f(x) must be zero outside theinterval -w/2 = x w/2. Your function handle f may be called with ascalar or a vector input.You can achieve additional control over IMRESIZE by usingparameter/value pairs following any of the syntaxes above. Forexample:B = IMRESIZE(A, SCALE, PARAM1, VALUE1, PARAM2, VALU
9、E2, .)Parameters include:-_Antialiasing - true or false; specifies whether to perform antialiasing when shrinking an image. Thedefault value depends on the interpolation method you choose. For the nearest method,the default is false; for all other methods,the default is true.Colormap - (only relevan
10、t for indexed images) originalor optimized; if original, then theoutput newmap is the same as the input map.If it is optimized, then a new optimizedcolormap is created. The default value isoptimized. Dither - (only for indexed images) true or false;specifies whether to perform colordithering. The de
11、fault value is true.Method - As described aboveOutputSize - A two-element vector, MROWS NCOLS,specifying the output size. One element maybe NaN, in which case the other value iscomputed automatically to preserve the aspectratio of the image. Scale - A scalar or two-element vector specifying theresiz
12、e scale factors. If it is a scalar, thesame scale factor is applied to eachdimension. If it is a vector, it containsthe scale factors for the row and columndimensions, respectively.Examples-Shrink by factor of two using the defaults of bicubic interpolationand antialiasing.I = imread(rice.png);J = i
13、mresize(I, 0.5);figure, imshow(I), figure, imshow(J)Shrink by factor of two using nearest-neighbor interpolation.(This is the fastest method, but it has the lowest quality.)-_J2 = imresize(I, 0.5, nearest);Resize an indexed image.X, map = imread(trees.tif);Y, newmap = imresize(X, map, 0.5);imshow(Y,
14、 newmap)Resize an RGB image to have 64 rows. The number of columns iscomputed automatically.RGB = imread(peppers.png);RGB2 = imresize(RGB, 64 NaN);Note-The function IMRESIZE in previous versions of the Image ProcessingToolbox used a somewhat different algorithm by default. If you needthe same result
15、s produced by the previous implementation, call thefunction IMRESIZE_OLD.Class Support-The input image A can be numeric or logical and it must be nonsparse.The output image is of the same class as the input image. The inputindexed image X can be uint8, uint16, or double.See also imresize_old, imrota
16、te, imtransform, tformarray.Reference page in Help browserdoc imresize 执行程序所得结果如下:-_改变参数Scale =0.5得到图形结果如下:-_对以上实验结果,分析如下:通过查看命令窗口查看imresize函数的使用方法。本实验中利用了形式B = imresize(A,m,method)。实验中method采用了,nearest(默认值)最近邻插值 方法和bilinear双线性插值方法,由图片显示结果可以看出,双线性插值方法要好于最近邻插值方法。这是由于最近邻插值方法仅是取离其最近的一个像素的像素值,而双线性插值方法采用
17、了其周围的像素值参与计算,所以更能适应图像的局部特征。m为放大倍数,由上面实验结果可以明显看出,放大1.35倍和0.5倍的效果差异。2.2. 图像旋转图像旋转 clear all, close all I = imread(cameraman.tif); Theta = 45; % 将图像逆时针旋转45。 J1 = imrotate(I, Theta, nearest); % using the nearest neighbor interpolation %and enlarge the output image Theta = -45; % 将图像顺时针旋转45。 J2 = imrotat
18、e(I, Theta, bilinear, crop); % using the bilinear interpolation % and crops the output image imshow(I), title(Original Image); figure, imshow(J1), title(Rotated Image- using the nearest neighbor interpolation ); figure, imshow(J2), title( Rotated Image- using the bilinear interpolation ); % 查看imrota
19、te使用帮助 help imrotateCommand窗口显示如下: IMROTATE Rotate image.B = IMROTATE(A,ANGLE) rotates image A by ANGLE degrees in a counterclockwise direction around its center point. To rotate the imageclockwise, specify a negative value for ANGLE. IMROTATE makes the outputimage B large enough to contain the enti
20、re rotated image. IMROTATE usesnearest neighbor interpolation, setting the values of pixels in B that are outside the rotated image to 0 (zero).-_B = IMROTATE(A,ANGLE,METHOD) rotates image A, using the interpolationmethod specified by METHOD. METHOD is a string that can have one of thefollowing valu
21、es. The default value is enclosed in braces ().nearest Nearest neighbor interpolationbilinear Bilinear interpolationbicubic Bicubic interpolation. Note: This interpolationmethod can produce pixel values outside the originalrange.B = IMROTATE(A,ANGLE,METHOD,BBOX) rotates image A, where BBOX specifies
22、 the size of the output image B. BBOX is a text string that can have either of the following values. The default value is enclosed in braces().loose Make output image B large enough to contain theentire rotated image. B is generally larger than A.crop Make output image B the same size as the input i
23、mageA, cropping the rotated image to fit. Class Support-The input image can be numeric or logical. The output image is of thesame class as the input image.Example-% This example brings image I into horizontal alignment by% rotating the image by -1 degree.I = fitsread(solarspectra.fts);I = mat2gray(I
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字图像 处理 实验 报告 四五
限制150内