《数字图象处理》实验指导书 -...
Transcript of 《数字图象处理》实验指导书 -...
《数字图象处理》实验指导书
编者: 史东承、侯阿临、梁超
长春工业大学计算机科学与工程学院 2003年9月
前 言
MATLAB 是一套功能强大的工程计算及数据处理软件,广泛应用
于工业,电子,医疗和建筑等众多领域。它是一种面向对象的,交互
式程序设计语言,其结构完整、具有可移植性。它在矩阵运算,数字
信号处理、图象处理方面有强大的功能。另外,MATLAB提供了方便的
绘图功能,便于用户直观地输出处理结果。
本课程实验要求学生运用MATLAB编程完成一些数字图象处理的
基本功能,加深对教学内容的理解。
长春工业大学-计算机科学与工程学院数字图像处理课程组
i
目 录 实验基本要求...................................................................................................................................1 实验报告格式...................................................................................................................................1 实验一:图像的显示与格式变换(2 学时) ................................................................................2
1.实验目的.............................................................................................................................2 2.实验内容.............................................................................................................................2 3.实验步骤.............................................................................................................................2
实验二:Matlab 的图像处理工具演示实验(2 学时)................................................................4 1.实验目的.............................................................................................................................4 2.实验内容.............................................................................................................................4 3.实验步骤.............................................................................................................................4
实验三:傅里叶变换与频域滤波(2 学时) ................................................................................5 1.实验目的.............................................................................................................................5 2.实验内容.............................................................................................................................5 3.实验步骤.............................................................................................................................5
实验四:图像增强(2 学时)........................................................................................................7 1.实验目的.............................................................................................................................7 2.实验内容.............................................................................................................................7 3.实验步骤.............................................................................................................................7
实验五:逆滤波...............................................................................................................................8 1.实验目的.............................................................................................................................8 2.实验内容.............................................................................................................................8 3.实验步骤.............................................................................................................................8
实验六:离散余弦变换 DCT(2 学时).....................................................................................10 1.实验目的...........................................................................................................................10 2.实验内容...........................................................................................................................10 3.实验步骤...........................................................................................................................10
实验七:数据压缩与数学形态学.................................................................................................11 1.实验目的...........................................................................................................................11 2.实验内容...........................................................................................................................11 3.实验步骤...........................................................................................................................11
图像压缩:JPEG............................................................................................................11 图像压缩:MPEG..........................................................................................................11 数学形态学.....................................................................................................................12
附录 1:数字图像处理实验报告实例..........................................................................................13 1.Objectives: ........................................................................................................................13 2.The Experiment Content: ..................................................................................................13 3.The Experiment Principle: ................................................................................................13 4.The Experiment Steps .......................................................................................................14 5.The Experiment Results: ...................................................................................................14 6.Conclusions:......................................................................................................................14 7.Appendix:..........................................................................................................................14
长春工业大学-计算机科学与工程学院数字图像处理课程组
ii
附录 2:Matlab 图像处理基础简介 (Fundamentals).............................................................16 IMAGE I/O 影像的輸入/輸出 ..............................................................................................16
附录 3:MATLAB 图像处理命令 ...............................................................................................21 1.applylut .............................................................................................................................21 2.bestblk ...............................................................................................................................21 3.blkproc ..............................................................................................................................22 4.brighten .............................................................................................................................22 5.bwarea ...............................................................................................................................22 6.bweuler...........................................................................................................................23 7.bwfill .................................................................................................................................23 8.bwlabel ..............................................................................................................................24 9.bwmorph ...........................................................................................................................25 10.bwperim ..........................................................................................................................26 11.bwselect...........................................................................................................................27 12.cmpermute.......................................................................................................................28 13.cmunique.........................................................................................................................28 14.col2im .............................................................................................................................28 15.colfilt ...............................................................................................................................28 16.colorbar ...........................................................................................................................29 17.conv2...............................................................................................................................29 18.convmtx2.........................................................................................................................30 19.convn...............................................................................................................................30 20.corr2 ................................................................................................................................30 21.dct2..................................................................................................................................31 22.dctmtx .............................................................................................................................31 23.dilate................................................................................................................................32 24.dither ...............................................................................................................................32 25.double..............................................................................................................................32 26.edge .................................................................................................................................33 27.erode................................................................................................................................34 28.fft2...................................................................................................................................34 29.fftn...................................................................................................................................35 30.fftshift..............................................................................................................................35 31.filter2...............................................................................................................................36 32.freqspace .........................................................................................................................36 33.freqz2 ..............................................................................................................................37 34.fsamp2.............................................................................................................................37 35.fspecial ............................................................................................................................38 36.ftrans2 .............................................................................................................................38 37.fwind1 .............................................................................................................................39 38.fwind2 .............................................................................................................................39 39.getimage..........................................................................................................................39 40.gray2ind ..........................................................................................................................40 41.grayslice ..........................................................................................................................40
长春工业大学-计算机科学与工程学院数字图像处理课程组
iii
42.histeq ...............................................................................................................................40 43.hsv2rgb............................................................................................................................41 44.idct2.................................................................................................................................41 45.ifft2..................................................................................................................................42 46.ifftn..................................................................................................................................42 47.sim2bw............................................................................................................................42 48.im2col .............................................................................................................................43 49.im2double .......................................................................................................................43 50.im2uint8 ..........................................................................................................................43 51.im2uint16 ........................................................................................................................43 52.imadjust...........................................................................................................................44 53.imapprox .........................................................................................................................44 54.imcontour ........................................................................................................................44 55.imcrop .............................................................................................................................45 56.imfeature .........................................................................................................................46 57.imfinfo.............................................................................................................................47 58.imhist...............................................................................................................................48 59.immovie ..........................................................................................................................48 60.imnoise............................................................................................................................48 61.impixel ............................................................................................................................49 62.improfile..........................................................................................................................50 63.imread .............................................................................................................................50 64.imresize ...........................................................................................................................51 65.imrotate ...........................................................................................................................51 66.imshow............................................................................................................................52 67.imwrite ............................................................................................................................52 68.ind2gray ..........................................................................................................................52 69.ind2rgb ............................................................................................................................53 70.iptgetpref .........................................................................................................................53 71.iptsetpref .........................................................................................................................53 72.Iradon ..............................................................................................................................54 73.isbw.................................................................................................................................54 74.isgray...............................................................................................................................54 75.isind.................................................................................................................................55 76.isrgb.................................................................................................................................55 77.makelut............................................................................................................................55 78.mat2gray .........................................................................................................................56 79.mean2..............................................................................................................................56 80.medfilt2 ...........................................................................................................................56 81.montage...........................................................................................................................57 82.nlfilter..............................................................................................................................58 83.ntsc2rgb...........................................................................................................................58 84.ordfilt2.............................................................................................................................58 85.phantom...........................................................................................................................58
长春工业大学-计算机科学与工程学院数字图像处理课程组
iv
86.pixval...............................................................................................................................59 87.qtdecomp.........................................................................................................................59 88.qtgetblk ...........................................................................................................................60 89.qtsetblk............................................................................................................................61 90.radon ...............................................................................................................................61 91.rgb2gray ..........................................................................................................................62 93.rgb2ind ............................................................................................................................62 94.rgb2ntsc...........................................................................................................................63 95.rgb2ycbcr ........................................................................................................................63 96.rgbplot .............................................................................................................................63 97.roicolor ............................................................................................................................64 98.roifill ...............................................................................................................................64 99.roifilt2 .............................................................................................................................65 100.roipoly ...........................................................................................................................66 101.std2................................................................................................................................66 102.subimage .......................................................................................................................66 103.truesize ..........................................................................................................................67 104.uint8 ..............................................................................................................................67 105.uint16 ............................................................................................................................68 106.warp...............................................................................................................................68 107.wiener2..........................................................................................................................69 108.ycbcr2rgb ......................................................................................................................69 109.zoom..............................................................................................................................69
长春工业大学-计算机科学与工程学院数字图像处理课程组
1
实验基本要求
由自己独立完成; 除指定要求外,均在 Matlab 环境下完成; 提交实验结果(Source Code,Readme.txt 和实验报告)并向助教解释程序流程。
实验报告格式
Digital Image Processing Experiment Report
实 验 人: 学号: 成绩:
实验编号(Project Report #): 实验题目(the title of the project): 日 期(Date: Month/Day/Year):
1.实验目的:
2.实验内容:
3.实验原理
4.实验步骤:
5.实验结果:
6.结论:
7.附件:
长春工业大学-计算机科学与工程学院数字图像处理课程组
2
实验一:图像的显示与格式变换(2 学时)
1.实验目的
(1)熟悉常用的图像文件格式与格式转换; (2)熟悉图像矩阵的显示方法(灰度、索引、黑白、彩色); (3)熟悉图像矩阵的格式转换。
2.实验内容
练习图像读写命令 imread 和 imwrite 并进行图像文件格式间的转换。特别是索引图像与 1,4,8,16 比特图像的存储与转换。
熟悉下列模块函数: Image file I/O. imread - Read image file. imwrite - Write image file. Image display. colorbar - Display colorbar. getimage - Get image data from axes. image - Create and display image object. imagesc - Scale data and display as image. immovie - Make movie from multiframe indexed image. imshow - Display image. subimage - Display multiple images in single figure. truesize - Adjust display size of image. warp - Display image as texture-mapped surface. zoom - Zoom in and out of image or 2-D plot.
3.实验步骤
(1)从硬盘加载图像 cameraman.tif (使用函数 imread)。 (2)在窗口显示图像 (使用函数 image o 或 imshow)。 (3)在图像右侧加一个亮度条 (使用函数 colorbar)。 (4)从当前图形窗口(坐标轴)获得图像数据(使用函数 getimage)。 (5)显示图像从 64 到 128 的灰度级 (使用函数 imagesc)。 (6)将一个 4-D 图像制成动画(加载 mri,用 immovie 制作动画,用函数 movie 播放动画)。 (7)把图像显示在一个主面上(使用函数 warp)。
要求: 如下图显示 cameraman。
长春工业大学-计算机科学与工程学院数字图像处理课程组
3
做(1)至(7)实验写一份实验报告。
长春工业大学-计算机科学与工程学院数字图像处理课程组
4
实验二:Matlab 的图像处理工具演示实验(2 学时)
1.实验目的
用 Image processing Toolbox 处理模块的演示实验(Demos)了解几种常用的图象处理方法。
2.实验内容
(1)用 dctdemo(2-D DCT image compression demo.)函数观察图像 DCT 变换系数与图像重
构的关系; (2)用 edgedemo(Edge detection demo.)函数观察图像边沿检测的几种锐化算子的性能及效
果; (3)用 nrfiltdemo(Noise reduction filtering demo.)函数观察图像复原的几种方法; (4)用 roidemo(Region-of-interest processing demo.)函数观察各种图像变换的效果; (5)用 Images Transform Gallery 的例子观察图像的仿射(affine)变换方法。
3.实验步骤
(1) 在 Command Window 中键入: >>demos 出现 Matlab demos 窗口,选择该窗口的左栏选项 Toolboxes 的 Image processing 子项,右框为
其对应的图像处理演示例子汇集; (2)选择 Discrete cosine transform,观察压缩的图像与原图及变换系数的关系; (3)选择 Edge detect,比较各种锐化算子(模板)的效果; (4)选择 Noise reduction filtering,比较 Midian (filter),Averaging(filter),adative (即 wiener2 filter)的不同效果; (5)选择 Intensity adjustment and histogram equalization(亮度调节和直方图均衡),观察图像
的各种变化; (6)按 Images Transform Gallery 中提示的步骤对例子图像进行仿射几何(affine)变换。
长春工业大学-计算机科学与工程学院数字图像处理课程组
5
实验三:傅里叶变换与频域滤波(2 学时)
1.实验目的
熟悉傅里叶变换算法和图像频域处理的基本流程。
2.实验内容
实现正反傅里叶变换、Gaussian 低通滤波和 laplacian 高通滤波。
3.实验步骤
(1)用 Image processing Toolbox 的函数 FFT2,计算 lenna.gif 图像的 2D FFT 变换。 a. 计算幅度和相角的对数(如,Image processing Toolbox 的函数 ANGLE)。 b. 用 Image processing Toolbox 的函数 IFFT2,计算 lenna 图像的 2D FFT 反变换。 c. 绘制原 lenna 图像和反变换图像的幅度、相角对数曲线。
(2)低通滤波器设计 a. 用 Image processing Toolbox 的函数 FSPECIAL,设计一个 11×11 的 Gaussian 低通滤波
器,S 等于 1.3。 b. 用与 lenna 图像维数相同的 FFT 变换计算滤波器核的 2D FFT 变换(使用 SIZE 函数)。 c. 由 b 的结果计算并绘制 Gaussian 低通滤波器核的幅度和相角对数曲线。 d. 利用(1)和(2)-b.的结果列出滤波函数
G(u,v) = H(u,v)*F(u,v) 其中,H(u,v)为高斯滤波器核的 2D FFT 变换,F(u,v)为 lenna 图像的 2D FFT 变换。 绘制低通滤波后图像的幅度、相角度数曲线。
e. 计算低通滤波后图像的 2D FFT 反变换,并绘制曲线。 (3)高通滤波器设计 a. 用 Image processing Toolbox 的函数 FSPECIAL,设计一个的 laplacian 高通滤波器。 b. 用与 lenna 图像维数相同的 FFT 变换计算滤波器核的 2D FFT 变换(使用 SIZE 函数)。
c. 由 b 的结果计算并绘制 laplacian 高通滤波器核的幅度和相角对数曲线。 d. 利用(1)和(3)-b.的结果列出滤波函数
G(u,v) = H(u,v)*F(u,v) 其中,H(u,v)为 laplacian 高通滤波器核的 2D FFT 变换,F(u,v)为 lenna 图像的 2D FFT 变
换。绘制高通滤波后图像的幅度、相角度数曲线。 e. 用函数 IFFT2 计算高通滤波后图像的 2D FFT 反变换,并绘制曲线。
(4)二维滤波器设计 a. 本实验的目的是使用滤波器设计函数:fsamp2, fwind1 和 fwind2。
a)[f1,f2] = freqspace(21,'meshgrid');用频率采样法设计滤波器。 b) 当 a)完成后,计算由滤波器设计函数 fsamp2, fwind1 和 fwind2 设计的滤波器的半径。 ⅰ. 半径如下:
长春工业大学-计算机科学与工程学院数字图像处理课程组
6
ⅰ)带通:(r<0.1) | (r>0.6) ⅱ)低通:r>0.6 ⅲ)高通:r<0.6 ⅱ. 对每个滤波器算法:
ⅰ)设计一个带通、低通、高通滤波器 ⅱ)用与 lenna 图像维数相同的 FFT 变换计算滤波器核的 2D FFT 变换(使用
SIZE 函数)。 ⅲ)由ⅱ)的结果计算并绘制每个滤波器核的幅度和相角对数曲线。
ⅳ) 利用ⅱ)的结果列出滤波函数 G(u,v) = H(u,v)*F(u,v)
其中,H(u,v)为各个滤波器核的 2D FFT 变换,F(u,v)为 lenna 图像的 2D FFT 变
换。绘制高通滤波后图像的幅度、相角度数曲线。 ⅴ) 用函数 IFFT2 计算各个滤波后图像的 2D FFT 反变换,并绘制曲线。
长春工业大学-计算机科学与工程学院数字图像处理课程组
7
实验四:图像增强(2 学时)
1.实验目的
(1)熟悉灰度直方图的概念及其计算方法及直方图均衡化的计算过程;
(2)熟悉空域滤波中常用的平滑滤波器。
2.实验内容
练习图像增强的 Matlab 命令。 熟悉下列模块函数:
Image enhancement. histeq - histogram equalization. imadust - Adust image intensity values or colormap. Image noising.
imnoise - Add noise to an image. Image filtering medfilt2 - Perform 2-D median filtering. ordfilt2 - Perform 2-D order-statistic filtering. wiener2 - Perform 2-D adaptive noise-removal filtering.
3.实验步骤
(1)从硬盘加载图像 cameraman.tif (使用函数 imread)。 (2)在窗口显示该图像。 (3)显示该图象的直方图(用函数 imhist)。 (4)通过直方图均衡化增强图像的对比度。 (5)比较两幅图像的质量,并进行讨论。 (6)图像分别加入 gaussian, salt&pepper, speckle noise 噪声,比较其对均值和方差的影响。 (7)分别用函数 medfilt2, ordfilt2 and wiener2 去除所加的噪声。将处理后的图像与原图像比较,
讨论各种方法的作用。
长春工业大学-计算机科学与工程学院数字图像处理课程组
8
实验五:逆滤波
1.实验目的
了解采用逆滤波进行图像恢复的方法。
2.实验内容
(1)利用 Matlab 函数将 RGB 图像转换为灰度图像; (2)学习并实现模糊和噪声的点扩散函数(PSF's); (3)学习并计算噪声与图像的能量比;
(4)学习并实现图像复原中的各种滤波,包括 Wiener, Regular 和 Lucy-Richardson。 (5)学习噪声对图像的影响并用它来复原降质图像。 将上述函数和概念应用于实域。
3.实验步骤
(1)将 RGB 图像转换为灰度图像。 载入 RGB 图像 tissue1.jpg。用函数 RGB2IND 和 IND2GRAY 将其转换为灰度图像。
(2)生成 Gaussian 噪声矩阵。 用函数 RANDN 生成噪声矩阵,噪声矩阵的强度范围在[0.0,0.1]。
(3)由生成 Gaussian 噪声矩阵和 Matlab 的模糊操作生成点扩散函数(PSF)。 a. 用函数 FSPECIAL 以'motion'为参数生成一个 PSF(如,fspecial('motion',21, 11))。 b. 用 a.中的 PSF 和 IMFILTER 函数生成一个运动模糊图像。 c. 用 IMADD 函数对 b.中的运动模糊图像加 Gaussian 噪声,Gaussian 噪声矩阵在(2)生成。
(4)计算 noise-image 能量比。 a. 用如下方程计算(2)中噪声的能量和(3)-c.的退化图像。
Spectrum = abs(fft2(image)).^2;
Power = sum(Spectrum(:))/prod(size(Spectrum));
b. 由 a.的结果得信噪比。 (5)生成自相关函数用于逆滤波。
生成自相关矩阵可应用命令 IFFT2 和 REAL(如,fftshift(real(ifft2(' Spectrum of image')))。 (6)应用 Wiener 滤波器进行逆滤波
应用函数 DECONVWNR 实现 Wiener 滤波。可采用不同的参数: a. 对(3)中的降质图像实行 Wiener 滤波,缺省值 NSR = 0(如,deconvwnr(image,PSF))。
b.对(3)中的降质图像实行 Wiener 滤波,以信噪比为参数(如, deconvwnr(image,PSF,NoiseAutocorrelation))。
长春工业大学-计算机科学与工程学院数字图像处理课程组
9
c. 对(3)中的降质图像实行 Wiener 滤波,以信噪比的自相关函数为参数(如, deconvwnr(image,PSF,NoiseAutocorrelation))。
(7)应用 Regularized 滤波器进行逆滤波 应用函数 DECONVREG 实现 Regularized 滤波。可采用不同的参数:
a. 对(3)中的降质图像实行Regularized滤波,缺省值NSR = 0(如,Deconvreg (image,PSF))。 b.对( 3)中的降质图像实行 Wiener 滤波,以信噪能量为参数(如,Deconvreg (image,PSF,NoisePower)。
(8)应用 Lucy-Richardson 滤波器进行逆滤波 应用函数 DECONVLUCY 实现 Lucy-Richardson 滤波。可采用不同的参数,如:
deconvlucy(image, filterPSF, 5) deconvlucy(image, filterPSF, 3)
注意,最后一个参数为在退化图像上的迭代次数。 a. 对(3)中的降质图像实行 Lucy-Richardson 滤波,iterations=3。 b. 对(3)中的降质图像实行 Lucy-Richardson 滤波,iterations=5。
要求:
提供两幅退化图像,尽量使其变得清晰。图像如下: (1)原图像:hw4_lena_256.bmp (2)退化图像:hw4_source1.bmp
长春工业大学-计算机科学与工程学院数字图像处理课程组
10
实验六:离散余弦变换 DCT(2 学时)
1.实验目的
了解 DCT 离散余变换的特性和频域滤波方法。
2.实验内容
用实现分块图像 DCT 离散余变换,并实现频域滤波
3.实验步骤
(1)将输入图像分解为 8×8 的块。 (2)对每个块进行二维 DCT 变换。 (3)将图像变换到频域。 (4)每个块只保留部分 DCT 的系数(可分别保留 1,5,10,30 和 64 个系数)。 (5)进行 DCT 反变换的滤波图像。
长春工业大学-计算机科学与工程学院数字图像处理课程组
11
实验七:数据压缩与数学形态学
1.实验目的
了解 JPEG 、MPEG 编码和解码的原理和过程。
2.实验内容
实现 JPEG 、MPEG 的编码和解码。
3.实验步骤
图像压缩:JPEG
(1)读入 lena.pgm 文件 (2)对 lena 图像进行 8×8 的 DCT。 (3)用缺省的标准量化器量化 DCT 系数。 (4)反量化 c.中的数组。 (5)对 d.中的反量化数组执行 INVERSE DCT。 (6)计算原图像与重构图像的误差矩阵。 (7)显示原始图像、重构图像和误差图像。 要求:
实验报告需包括如下内容:JPEG 编码和解码的框图,简单介绍编码器和解码器的原理与操作。
图像压缩:MPEG
实验包括:Matlab 动画制作,MPEG 视频编码,MPEG 视频解码 (1)动画制作
a. 用 Matlab 命令 LOAD 加载文件 MRI(mri.mat),包括一系列 MRI 扫描来构成动画。 b. MRI 文件包括:四维向量 D、彩色映射 map、由每幅图像的维数和存储的帧数构成的向量
siz。由向量 siz 建立一个三维向量,并设计一个循环完成如下内容: a.) 将四维向量 D 映射到一个三维向量。
b.) 用命令 IMSHOW、PAUSE 播放图像切片。 c.) 生成 Matlab 动画。
(2)用函数 MPEGWRITE 进行 MPEG 编码 a. 该命令语法为:
mpgwrite(movie, map, 'filename', options)
长春工业大学-计算机科学与工程学院数字图像处理课程组
12
b. 生成的 MPEG 文件有回放功能,但以 WINDOWS MEDIA PLAYER 为标准。 (3)用函数 MPEGREAD 对 MPEG 数据流解码
a. 该命令语法为: mpgread('filename', frames)
b. 用命令 MOVIE 验证函数功能。 要求:
实验报告需包括如下内容:MPEG 编码和解码的框图,简单介绍编码器和解码器的原理与操
作。
数学形态学
这个问题比较难理解。所以,我们分析一个现有的算法 Detecting a Cell Using Image Segmentation,而不再自己设计。查找 image processing toolbox 中的 demos,有如下示例:
(1)算法 1 a.)安装分割代码构成完整的算法。 b.) 执行代码,注意分割算法的结果。
(2)算法 2 a.)使用 Matlab 函数 IMROTATE,利用双线性内插将原始图像旋转 90 度角。 b.) 执行代码,注意分割算法的结果。
(3)算法 3 a.)使用 Matlab 函数 IMROTATE,利用双线性内插将原始图像旋转 45 度角。 b.) 执行代码,注意分割算法的结果。
要求: 报告包括如下内容:详细描述算法和用到的所有函数。每种算法都分别显示其最终的分割图像
和原始图像。
长春工业大学-计算机科学与工程学院数字图像处理课程组
13
附录 1:数字图像处理实验报告实例
Digital Image Processing Experiment Report
实 验 人: 学号: 成绩:
实验编号(Project Report #): 实验题目(the title of the project): 日 期(Date: Month/Day/Year):
1.Objectives:
i. This report is to show you how to make your html reports for this class. ii. HTML is an easy language to learn, and this report will serve as a good starting
basis for all of your reports. iii. Write what you think the objectives of the project are from what is being asked
you to do in it.
2.The Experiment Content:
3.The Experiment Principle:
Briefly describe your algorithms and any other relevant implementation details.
Put in math details, as feasible within html format. Give references to any analytical derivations (for example: The equation 4.5 of chapter 4 from Gonzalez and Woods was used).
Also, discuss the structure of your code and how to run your programs. Provide pseudo-code and/or event sequences to assist in discussing the program.
长春工业大学-计算机科学与工程学院数字图像处理课程组
14
4.The Experiment Steps
5.The Experiment Results:
Give detailed observations on all of your results. At the end of this section provide the CPU time and clock time needed to execute your programs.
Ask yourself the following questions: Are the results what you were expecting they would be? If not, why not? Do you think it's because the algorithm is not the appropriate one, or because your implementation of it has a bug? It is important that you realize when your results are wrong, that means that you understood the theory behind the project content. In some cases, credit is given for incorrect results when the error is pointed out and thorough explanations are given for the incorrect results along with possible corrections or solutions.
Images can either be placed in this section or in the appendix. If images are in the appendix, be certain to refer to the proper figure number. Placing links to each figure will ensure correctness and make it easier to jump back and forth. Please refer to Figure 1.
6.Conclusions:
Write the conclusions of your project in a clear an concise way. Remember, conclusions are not observations. You draw conclusions from what you observe in your results. This is a very important part of your project, so think a lot about what you want to write in here. This section does not have to be extremely long, but please be thorough! Points will be deducted if you lack sufficient conclusions.
7.Appendix:
1.Well-labeled images, figures, tables and plots.
2.Be sure to have explanatory captions for all of these items. Places images together, tables together, etc.. Figure captions should be complete! Please be sure that the images shown represent the original image size. The HEIGHT and WIDTH tags should be used to improve download... use the original image size in these tags. This will reserve the space for the image so that subsequent text may transfer first. State what the figure is and give any parameters involved in its generation. See below for example image arrangement.
长春工业大学-计算机科学与工程学院数字图像处理课程组
15
Figure 1: Input image (#1), aerial.dat Figure 2: Input image (#2), boat.dat
You can also arrange your images like this: In the event that the image has a white or near-white border, please use BORDER=1 in the image tag to separate the picture from the background (as is done for the wheel image below).
Figure 3: Input image Figure 4: Output image
3.A link to your source code.
长春工业大学-计算机科学与工程学院数字图像处理课程组
16
附录 2:Matlab 图像处理基础简介 (Fundamentals)
一數位影像(digital image)是由各像素(pixel)所組成, 各 pixel 可以想像是在螢幕上的一個小點
(dots). 典型的一個影像大小是 512x512 pixels. 一般方便做影像處理時, 大小儘量是 2 的 power 次數. 如 512=2^9. 一般來說 我們可以將影像大小視為 m x n pixels(size m-by-n) . 在水平方向上 有 n pixels (horizontal direction).在垂直方向上 有 m pixels (vertical direction ).
一張影像其格式(format)為 512-by-1024 pixels, 則此影像包含信息(information)有 524288 pixels, 此是一很大的記憶量(memory). 所以壓縮影像(compressing image)是一非常有效率的影像處理.
IMAGE I/O 影像的輸入/輸出
影像的讀入及輸出, 可用指令 imread(),及 imwrite(), 對這兩指令不熟悉的話, 可以下指令 "help imread" 及 "help imwrite", 看 show 出來的訊息. Matlab 支持(support)的影像格式(image format)有 · BMP , 此為 indexed image, 使用 colormap 來表示影像, 對 true color 影像來說, 儲存成 BMP 格式會失真. 對灰階影像則不失真. · JPEG(joint photographic expert group), 此為有失真壓縮, 所以影像會失真 · TIFF(tagged image file format,標記式影像檔案格式) 此為無失真. 各人習慣用此檔案格式, 來儲存影像. · PCX · HDF(hierarchical data format, 階層式資料格式) · XWB(x windows dump, X 視窗傾印) · PNG(portable network graphics,可攜式網路圖形) · GIF(graphic interchange format, 圖形交換格式, 第六版才支援). 一般影像檔格式 會先放 檔頭(header) 之後再放 pixels 資料. Header 內包含 1. 識別記號 2.影像之 高(height), 寬(width) 及 3. 字串長度 + 字串內容描述此影
像檔的一些文字敘述. X=imread('檔名'); image(X) % show 出影像 X axis image % 以影像本身的長寬比來顯示影像. 若要使影像資料上的每一點對應至螢幕上的像素, 可輸入 [m,n]=size(X); figure('unit','pixel', 'position', [100,100, n, m] ); image(X); colormap(map); % 若 X 是 indexed image, 則得用調色盤. set(gca, 'position', [0, 0, 1, 1]); 其中 'position', [100,100, n, m] 表視窗左下角置於(100,100)位置. 寬度為 n, 高度為 m. 且以 pixel 為單位. set(gca, 'position', [0, 0, 1, 1]);
长春工业大学-计算机科学与工程学院数字图像处理课程组
17
gca 傳回使用中的圖軸, 將整個圖軸的位置設為整個視窗的大小. 欲列印影像時, matlab 會根據視窗的 paper position 性質來調整 圖形的長寬比, 使得印出之影像變形, 防止此情形 可下指令: set(gcf, 'PaperPositionMode', 'auto'); gcf 傳回使用中的視窗, 將'PaperPositionMode' 設為 'auto' 列印出的長寬比會與顯示在螢幕的長寬比一樣. 也可在 startup.m 中加入 set(0, 'DefaultFigurePaperPositionMode','auto'); 則會設預設值為 'auto'
· Working formats in Matlab X 是一 矩陣, 可用 image(X) 指令來顯示 X 之影像. 1. X 是 mxnx3 的矩陣, 則為一 true color image. 則 X(:,:,1) 表 紅色影像. X(:,:,2)表 綠色影像. X(:,:,3)表藍色影像. 矩陣 X 之值 可以是介於 0~1 之間的浮點數.
0~255 的整數. uint8 只是 0,1 兩個值. binary image.
2. X 是 mxn 的矩陣, 則 X 可能是 1. 灰階影像 gray image 2. indexed image 3. binary image. 當一張 JPEG 影像被讀入進 Matlab, 因要對影像作處理, 例如對影像進行 Wavelet 轉換, 會將影像轉
換成不同的格式(format). 格式如下: · 1. Intensity image (gray scale image) 灰階影像 灰階影像在 Matlab 中被表式成一個矩陣, 矩陣之元素的值(value)用來表示 該 pixel 的明暗度
(bright/dark). 元素的值可用 double 表示,也即是浮點數的表示, 如此其亮度值介於 0~1 之間的實數. 0 是最暗
(dark), 1 是最亮(white). 元素的值 可用 uint8 表示, 類似 C 語言中的 unsigned char, 在此是 unsigned int, 亮度值是介於 0~255 的整數(integer). 0是最暗, 255是最亮(white). 以 double class用掉 8btyes表示 是以 uint8 class表示量的 8 倍. 但 Matlab 中許多 function()的運算是 double class. 所以若是 uint8 class 則得先做轉
換(convert). · 2. Binary Image 二值影像 影像格式只有兩個值 black 及 white, 無其它灰階值. assigns 0 for black, assigns 1 for white. · 3. Indexed Image 索引影像
colormap matrix(調色盤矩陣)是一顏色之對照表(table), 一般而言欲顯示 K 種不同顏色, 調色盤
长春工业大学-计算机科学与工程学院数字图像处理课程组
18
必需是 Kx3 的矩陣, 每一列代表一種顏色, 元素值由 0~1 間的實數表示. 分別為(Red 紅,Green 綠
色,Blue 藍色), 若 X(i,j)=p, 則其顏色由 map(p,:)決定, 即為調色盤中第 p 個顏色. 例子: clear load clown; % clown 為內建的小丑影像, 其變數為 X. whos; %看目前有何變數. 有 X 及 map image(X); colormap(map); % 將 map 設入調色盤內. 由於 X 是 indexed image, 其值不會大於 map 的列數. K=size(map,1) % 此例 K=81. max(max(X)) % 最大值為 81. 欲正確顯示 indexed image, 其調色盤 colormap 必需正確. 下例 圖會亂掉. newmap=rand(size(map)); colormap(newmap); image(X); 若矩陣之值有些 小於 1, 或大於 K, 則可用 imagesc 來調整 show 影像. X=peaks; colormap(gray); imagesc(X); · 8-bits 影像(uint8) uint8能表示之範圍為 0~255. 若一 indexed image 原先是 double 索引(1~256). 要轉成以 uint8索引
(0~255) 所以 要先減 1 再 convert 例如: load clown; image(X); colormap(map); % X 是一 double class 的 indexed image. A=uint8(X-1); image(A); colormap(map); % A 是一 uint8 class 的 indexed image. 當然 uint8 class 的 indexed image 要轉成 double 的話, 要先加 1. B=double(A) +1; * 欲將 double class(值 0~1)的全彩影像 Y 轉成 uint8 class(值 0~255) 可輸入如下:
Z=uint8( round( Y * 255) ); * 欲將 uint8 class 影像 Z 轉成 double class 影像 Y
Y=double(Z) /255;
长春工业大学-计算机科学与工程学院数字图像处理课程组
19
1. Intensity image, imread 讀入後, 傳回資料是 uint8 的矩陣 mxn 2 Indexed image, imread 讀入後, 傳回資料是 uint8 的矩陣 mxn 及 傳回 一 double class 的 調色盤 map 矩陣 Kx3, 值介於 0~1 之間. 3. True Color image, imread 讀入後, 傳回資料是 uint8 的矩陣 mxnx3 IMWRITE(A,FILENAME,FMT) writes the image A to FILENAME. FILENAME is a string that specifies the name of the output file, and FMT is a string the specifies the format of the file. If A is a grayscale intensity image or a truecolor (RGB) image of class uint8, IMWRITE writes the actual values in the array to the file. If A is of class double, IMWRITE rescales the values in the array before writing, using uint8(round(255*A)). This operation converts the floating-point numbers in the range [0,1] to 8-bit integers in the range [0,255]. FMT include: 'bmp' Windows Bitmap (BMP) 'hdf' Hierarchical Data Format (HDF) 'jpg' or 'jpeg' Joint Photographic Experts Group (JPEG) 'pcx' Windows Paintbrush (PCX) 'tif' or 'tiff' Tagged Image File Format (TIFF) 'xwd' X Window Dump (XWD) IMWRITE(X,MAP,FILENAME,FMT) writes the indexed image in X, and its associated colormap MAP, to FILENAME. If X is of class uint8, IMWRITE writes the actual values in the array to the file. If X is of class double, IMWRITE offsets the values in the array before writing, using uint8(X-1). MAP must be a valid MATLAB colormap. Note that most image file formats do not support colormaps with more than 256 entries. 例如: load clown imwrite(X, map, 'clown.jpg'); %將 indexed image X 存成 clown.jpg. imwrite(X, map, 'clown.bmp'); * 可用 imfinfo('檔名') 傳回影像檔案之各項資訊. imfinfo('clown.jpg'); imfinfo('clown.bmp'); colormap(hsv)
长春工业大学-计算机科学与工程学院数字图像处理课程组
20
colormap(gray) colormap(hot) colormap(cool) colormap(pink) colormap(jet)
长春工业大学-计算机科学与工程学院数字图像处理课程组
21
附录 3:MATLAB 图像处理命令
1.applylut
功能:在二进制图像中利用lookup 表进行边沿操作。
语法:
A = applylut(BW,lut)
举例
lut = makelut('sum(x(:)) == 4',2);
BW1 = imread('text.tif');
BW2 = applylut(BW1,lut);
imshow(BW1)
figure, imshow(BW2)
相关命令:
makelut
2.bestblk
功能:确定进行块操作的块大小。
语法:
siz = bestblk([m n],k)
[mb,nb] = bestblk([m n],k)
举例
siz = bestblk([640 800],72)
siz =
64 50
相关命令:
blkproc
长春工业大学-计算机科学与工程学院数字图像处理课程组
22
3.blkproc
功能:实现图像的显式块操作。
语法:
B = blkproc(A,[m n],fun)
B = blkproc(A,[m n],fun,P1,P2,...)
B = blkproc(A,[m n],[mborder nborder],fun,...)
B = blkproc(A,'indexed',...)
举例
I = imread('alumgrns.tif');
I2 = blkproc(I,[8 8],'std2(x)*ones(size(x))');
imshow(I)
figure, imshow(I2,[]);
相关命令:
colfilt, nlfilter,inline
4.brighten
功能:增加或降低颜色映像表的亮度。
语法:
brighten(beta)
newmap = brighten(beta)
newmap = brighten(map,beta)
brighten(fig,beta)
相关命令:
imadjust, rgbplot
5.bwarea
功能:计算二进制图像对象的面积。
语法:
total = bwarea(BW)
举例
BW = imread('circles.tif');
长春工业大学-计算机科学与工程学院数字图像处理课程组
23
imshow(BW);
bwarea(BW)
ans =
15799
相关命令:
bweuler, bwperim
6.bweuler.
功能:计算二进制图像的欧拉数。
语法:
eul = bweuler(BW,n)
举例
BW = imread('circles.tif');
imshow(BW);
bweuler(BW)
ans =
–2
相关命令:
bwmorph, bwperim
7.bwfill
功能:填充二进制图像的背景色。
语法:
BW2 = bwfill(BW1,c,r,n)
BW2 = bwfill(BW1,n)
[BW2,idx] = bwfill(...)
BW2 = bwfill(x,y,BW1,xi,yi,n)
[x,y,BW2,idx,xi,yi] = bwfill(...)
BW2 = bwfill(BW1,'holes',n)
[BW2,idx] = bwfill(BW1,'holes',n)
举例
长春工业大学-计算机科学与工程学院数字图像处理课程组
24
BW1 =[1 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0
1 0 0 0 1 0 1 0
1 0 0 0 1 1 1 0
1 1 1 1 0 1 1 1
1 0 0 1 1 0 1 0
1 0 0 0 1 0 1 0
1 0 0 0 1 1 1 0]
BW2 = bwfill(BW1,3,3,8)
BW2 =
1 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0
1 1 1 1 1 0 1 0
1 1 1 1 1 1 1 0
1 1 1 1 0 1 1 1
1 0 0 1 1 0 1 0
1 0 0 0 1 0 1 0
1 0 0 0 1 1 1 0
I = imread('blood1.tif');
BW3 = ~im2bw(I);
BW4 = bwfill(BW3,'holes');
imshow(BW3)
figure, imshow(BW4)
相关命令:
bwselect, roifill
8.bwlabel
功能:标注二进制图像中已连接的部分。
语法:
L = bwlabel(BW,n)
[L,num] = bwlabel(BW,n)
举例
BW = [1 1 1 0 0 0 0 0
长春工业大学-计算机科学与工程学院数字图像处理课程组
25
1 1 1 0 1 1 0 0
1 1 1 0 1 1 0 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 1 1 0
1 1 1 0 0 0 0 0]
L = bwlabel(BW,4)
L =
1 1 1 0 0 0 0 0
1 1 1 0 2 2 0 0
1 1 1 0 2 2 0 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 3 3 0
1 1 1 0 0 0 0 0
[r,c] = find(L==2);
rc = [r c]
rc =
2 5
3 5
2 6
3 6
相关命令:
bweuler, bwselect
9.bwmorph
功能:提取二进制图像的轮廓。
语法:
BW2 = bwmorph(BW1,operation)
BW2 = bwmorph(BW1,operation,n)
举例
BW1 = imread('circles.tif'); imshow(BW1);
长春工业大学-计算机科学与工程学院数字图像处理课程组
26
BW2 = bwmorph(BW1,'remove');
BW3 = bwmorph(BW1,'skel',Inf);
imshow(BW2)
figure, imshow(BW3)
相关命令:
bweuler, bwperim, dilate, erode
10.bwperim
功能:计算二进制图像中对象的周长。
语法:
BW2 = bwperim(BW1,n)
举例
BW1 = imread('circbw.tif');
BW2 = bwperim(BW1,8);
imshow(BW1)
figure, imshow(BW2)
长春工业大学-计算机科学与工程学院数字图像处理课程组
27
相关命令:
bwarea, bweuler, bwfill
11.bwselect
功能:在二进制图像中选择对象。
语法:
BW2 = bwselect(BW1,c,r,n)
BW2 = bwselect(BW1,n)
[BW2,idx] = bwselect(...)
举例
BW1 = imread('text.tif');
c = [16 90 144];
r = [85 197 247];
BW2 = bwselect(BW1,c,r,4);
imshow(BW1)
figure, imshow(BW2)
相关命令:
bwfill, bwlabel, impixel, roipoly, roifill
长春工业大学-计算机科学与工程学院数字图像处理课程组
28
12.cmpermute
功能:调整颜色映像表中的颜色。
语法:
[Y,newmap] = cmpermute(X,map)
[Y,newmap] = cmpermute(X,map,index)
举例
To order a colormap by luminance, use: ntsc = rgb2ntsc(map);
[dum,index] = sort(ntsc(:,1));
[Y,newmap] = cmpermute(X,map,index);
相关命令:
randperm
13.cmunique
功能:查找颜色映像表中特定的颜色及相应的图像。
语法:
[Y,newmap] = cmunique(X,map)
[Y,newmap] = cmunique(RGB)
[Y,newmap] = cmunique(I)
相关命令:
gray2ind, rgb2ind
14.col2im
功能:将矩阵的列重新组织到块中。
语法:
A = col2im(B,[m n],[mm nn],block_type) A = col2im(B,[m n],[mm nn])
相关命令:
blkproc, colfilt, im2col, nlfilter
15.colfilt
功能:利用列相关函数进行边沿操作。
语法:
B = colfilt(A,[m n],block_type,fun)
B = colfilt(A,[m n],block_type,fun,P1,P2,...)
B = colfilt(A,[m n],[mblock nblock],block_type,fun,...)
B = colfilt(A,'indexed',...)
长春工业大学-计算机科学与工程学院数字图像处理课程组
29
相关命令:
blkproc, col2im, im2col, nlfilter
16.colorbar
功能:显示颜色条。
语法:
colorbar('vert')
colorbar('horiz')
colorbar(h)
colorbar
h = colorbar(...)
举例
I = imread('blood1.tif');
h = fspecial('log');
I2 = filter2(h,I);
imshow(I2,[]), colormap(jet(64)), colorbar
17.conv2
功能:进行二维卷积操作。
语法:
C = conv2(A,B)
C = conv2(hcol,hrow,A)
C = conv2(...,shape)
举例
A = magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
长春工业大学-计算机科学与工程学院数字图像处理课程组
30
11 18 25 2 9
B = [1 2 1;0 2 0;3 1 3]
B =
1 2 1
0 2 0
3 1 3
C = conv2(A,B)
C =
17 58 66 34 32 38 15
23 85 88 35 67 76 16
55 149 117 163 159 135 67
79 78 160 161 187 129 51
23 82 153 199 205 108 75
30 68 135 168 91 84 9
33 65 126 85 104 15 27 相关命令:
filter2
18.convmtx2
功能:计算二维卷积矩阵。
语法:
T = convmtx2(H,m,n)
T = convmtx2(H,[m n])
相关命令:
conv2
19.convn
功能:计算n 维卷积。
语法:
C = convn(A,B)
C = convn(A,B,shape)
相关命令:
conv2
20.corr2
功能:计算两个矩阵的二维相关系数。
语法:
r = corr2(A,B)
相关命令:
长春工业大学-计算机科学与工程学院数字图像处理课程组
31
std2
21.dct2
功能:进行二维离散余弦变换。
语法:
B = dct2(A)
B = dct2(A,m,n)
B = dct2(A,[m n])
举例
RGB = imread('autumn.tif');
I = rgb2gray(RGB);
J = dct2(I);
imshow(log(abs(J)),[]), colormap(jet(64)), colorbar
J(abs(J) < 10) = 0;
K = idct2(J)/255;
imshow(K)
相关命令:
fft2, idct2, ifft2
22.dctmtx
功能:计算离散余弦变换矩阵。
语法:
D = dctmtx(n)
相关命令:
长春工业大学-计算机科学与工程学院数字图像处理课程组
32
dct2
23.dilate
功能:放大二进制图像。
语法:
BW2 = dilate(BW1,SE)
BW2 = dilate(BW1,SE,alg)
BW2 = dilate(BW1,SE,...,n)
举例
BW1 = imread('text.tif');
SE = ones(6,2);
BW2 = dilate(BW1,SE);
imshow(BW1)
figure, imshow(BW2)
相关命令:
bwmorph, erode
24.dither
功能:通过抖动增加外观颜色分辨率,转换图像。
语法:
X = dither(RGB,map)
BW = dither(I)
相关命令:
rgb2ind
25.double
功能:转换数据为双精度型。
语法:
B = double(A)
长春工业大学-计算机科学与工程学院数字图像处理课程组
33
举例
A = imread('saturn.tif');
B = sqrt(double(A));
相关命令:
im2double, im2uint, uint8
26.edge
功能:识别强度图像中的边界。
语法:
BW = edge(I,'sobel')
BW = edge(I,'sobel',thresh)
BW = edge(I,'sobel',thresh,direction)
[BW,thresh] = edge(I,'sobel',...)
BW = edge(I,'prewitt')
BW = edge(I,'prewitt',thresh)
BW = edge(I,'prewitt',thresh,direction)
[BW,thresh] = edge(I,'prewitt',...)
BW = edge(I,'roberts')
BW = edge(I,'roberts',thresh)
[BW,thresh] = edge(I,'roberts',...)
BW = edge(I,'log')
BW = edge(I,'log',thresh)
BW = edge(I,'log',thresh,sigma)
[BW,threshold] = edge(I,'log',...)
BW = edge(I,'zerocross',thresh,h)
[BW,thresh] = edge(I,'zerocross',...)
BW = edge(I,'canny')
BW = edge(I,'canny',thresh)
BW = edge(I,'canny',thresh,sigma) [BW,threshold] = edge(I,'canny',...)
举例
I = imread('rice.tif');
BW1 = edge(I,'prewitt');
BW2 = edge(I,'canny');
imshow(BW1);
figure, imshow(BW2)
长春工业大学-计算机科学与工程学院数字图像处理课程组
34
27.erode
功能:弱化二进制图像的边界。
语法:
BW2 = erode(BW1,SE)
BW2 = erode(BW1,SE,alg)
BW2 = erode(BW1,SE,...,n)
举例
BW1 = imread('text.tif');
SE = ones(3,1);
BW2 = erode(BW1,SE);
imshow(BW1)
figure, imshow(BW2)
相关命令:
bwmorph, dilate
28.fft2
功能:进行二维快速傅里叶变换。
语法:
B = fft2(A)
B = fft2(A,m,n)
长春工业大学-计算机科学与工程学院数字图像处理课程组
35
举例
load imdemos saturn2
imshow(saturn2)
B = fftshift(fft2(saturn2));
imshow(log(abs(B)),[]), colormap(jet(64)), colorbar
相关命令:
dct2, fftshift, idct2, ifft2
29.fftn
功能:进行n 维快速傅里叶变换。
语法:
B = fftn(A)
B = fftn(A,siz)
相关命令:
fft2, ifftn
30.fftshift
功能:把快速傅里叶变换的DC 组件移到光谱中心。
语法:
B = fftshift(A)
长春工业大学-计算机科学与工程学院数字图像处理课程组
36
举例
B = fftn(A);
C = fftshift(B);
相关命令:
fft2, fftn, ifftshift
31.filter2
功能:进行二维线性过滤操作。
语法:
B = filter2(h,A)
B = filter2(h,A,shape)
举例
A = magic(6)
A =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
h = fspecial('sobel')
h =
1 2 1
0 0 0
–1 –2 –1
B = filter2(h,A,'valid')
B =
–8 4 4 –8
–23 –44 –5 40
–23 –50 1 40
–8 4 4 –8
相关命令:
conv2, roifilt2
32.freqspace
功能:确定二维频率响应的频率空间。
语法:
[f1,f2] = freqspace(n)
[f1,f2] = freqspace([m n])
[x1,y1] = freqspace(...,'meshgrid')
f = freqspace(N)
长春工业大学-计算机科学与工程学院数字图像处理课程组
37
f = freqspace(N,'whole')
相关命令:
fsamp2, fwind1, fwind2
33.freqz2
功能:计算二维频率响应。
语法:
[H,f1,f2] = freqz2(h,n1,n2)
[H,f1,f2] = freqz2(h,[n2 n1])
[H,f1,f2] = freqz2(h,f1,f2)
[H,f1,f2] = freqz2(h)
[...] = freqz2(h,...,[dx dy])
[...] = freqz2(h,...,dx)
freqz2(...)
举例
Hd = zeros(16,16);
Hd(5:12,5:12) = 1;
Hd(7:10,7:10) = 0;
h = fwind1(Hd,bartlett(16));
colormap(jet(64))
freqz2(h,[32 32]); axis ([–1 1 –1 1 0 1])
34.fsamp2
功能:用频率采样法设计二维FIR 过滤器。
语法:
h = fsamp2(Hd)
h = fsamp2(f1,f2,Hd,[m n])
举例
[f1,f2] = freqspace(21,'meshgrid');
Hd = ones(21);
r = sqrt(f1.^2 + f2.^2);
Hd((r<0.1)|(r>0.5)) = 0;
长春工业大学-计算机科学与工程学院数字图像处理课程组
38
colormap(jet(64))
mesh(f1,f2,Hd)
相关命令:
conv2, filter2, freqspace, ftrans2, fwind1, fwind2
35.fspecial
功能:创建预定义过滤器。
语法:
h = fspecial(type)
h = fspecial(type,parameters)
举例
I = imread('saturn.tif');
h = fspecial('unsharp',0.5);
I2 = filter2(h,I)/255;
imshow(I)
figure, imshow(I2)
相关命令:
conv2, edge, filter2, fsamp2, fwind1, fwind2
36.ftrans2
功能:通过频率转换设计二维FIR 过滤器。
语法:
h = ftrans2(b,t)
h = ftrans2(b)
举例
colormap(jet(64))
b = remez(10,[0 0.05 0.15 0.55 0.65 1],[0 0 1 1 0 0]);
[H,w] = freqz(b,1,128,'whole');
plot(w/pi–1,fftshift(abs(H)))
相关命令:
conv2, filter2, fsamp2, fwind1, fwind2
长春工业大学-计算机科学与工程学院数字图像处理课程组
39
37.fwind1
功能:用一维窗口方法设计二维FIR 过滤器。
语法:
h = fwind1(Hd,win)
h = fwind1(Hd,win1,win2)
h = fwind1(f1,f2,Hd,...)
举例
[f1,f2] = freqspace(21,'meshgrid');
Hd = ones(21);
r = sqrt(f1.^2 + f2.^2);
Hd((r<0.1)|(r>0.5)) = 0; colormap(jet(64))
mesh(f1,f2,Hd)
相关命令:
conv2, filter2, fsamp2, freqspace, ftrans2, fwind2
38.fwind2
功能:用二维窗口方法设计二维FIR 过滤器。
语法:
h = fwind2(Hd,win)
h = fwind2(f1,f2,Hd,win)
举例
[f1,f2] = freqspace(21,'meshgrid');
Hd = ones(21);
r = sqrt(f1.^2 + f2.^2);
Hd((r<0.1)|(r>0.5)) = 0;
colormap(jet(64))
mesh(f1,f2,Hd) 相关命令:
conv2, filter2, fsamp2, freqspace, ftrans2, fwind1
39.getimage
功能:从坐标轴取得图像数据。
语法:
A = getimage(h)
[x,y,A] = getimage(h)
[...,A,flag] = getimage(h)
[...] = getimage
举例
长春工业大学-计算机科学与工程学院数字图像处理课程组
40
imshow rice.tif
I = getimage;
40.gray2ind
功能:转换灰度图像为索引图像。
语法:
[X,map] = gray2ind(I,n)
相关命令:
ind2gray
41.grayslice
功能:从灰度图像创建索引图像。
语法:
X = grayslice(I,n)
X = grayslice(I,v)
举例
I = imread('ngc4024m.tif');
X = grayslice(I,16);
imshow(I)
figure, imshow(X,jet(16))
相关命令:
gray2ind
42.histeq
功能:用柱状图均等化增强对比。
语法:
J = histeq(I,hgram)
J = histeq(I,n)
[J,T] = histeq(I,...)
举例
I = imread('tire.tif');
J = histeq(I);
长春工业大学-计算机科学与工程学院数字图像处理课程组
41
imshow(I)
figure, imshow(J)
imhist(I,64)
figure; imhist(J,64)
相关命令: brighten, imadjust, imhist
43.hsv2rgb
功能:转换 HSV 值为 RGB 颜色空间。 语法: rgbmap = hsv2rgb(hsvmap) RGB = hsv2rgb(HSV) 相关命令: rgb2hsv, rgbplot
44.idct2
功能:计算二维离散反余弦变换。
语法:
B = idct2(A)
B = idct2(A,m,n)
B = idct2(A,[m n])
相关命令:
dct2, dctmtx, fft2, ifft2
长春工业大学-计算机科学与工程学院数字图像处理课程组
42
45.ifft2
功能:计算二维快速傅里叶反变换。
语法:
B = ifft2(A)
B = ifft2(A,m,n)
相关命令:
fft2, fftshift, idct2
46.ifftn
功能:计算n 维快速傅里叶反变换。
语法:
B = ifftn(A)
B = ifftn(A,siz)
相关命令:
fft2, fftn, ifft2
47.sim2bw
功能:转换图像为二进制图像。
语法:
BW = im2bw(I,level)
BW = im2bw(X,map,level)
BW = im2bw(RGB,level)
举例
load trees
BW = im2bw(X,map,0.4);
imshow(X,map) figure, imshow(BW)
相关命令: ind2gray, rgb2gray
长春工业大学-计算机科学与工程学院数字图像处理课程组
43
48.im2col
功能:重调图像块为列。 语法: B = im2col(A,[m n],block_type) B = im2col(A,[m n]) B = im2col(A,'indexed',...) 相关命令: blkproc, col2im, colfilt, nlfilter
49.im2double
功能:转换图像矩阵为双精度型。 语法: I2 = im2double(I1) RGB2 = im2double(RGB1) BW2 = im2double(BW1) X2 = im2double(X1,'indexed') 相关命令: double, im2uint8, uint8
50.im2uint8
功能:转换图像阵列为 8 位无符号整型。 语法: I2 = im2uint8(I1) RGB2 = im2uint8(RGB1) BW2 = im2uint8(BW1) X2 = im2uint8(X1,'indexed') 相关命令:
im2uint16, double, im2double, uint8, imapprox, uint16
51.im2uint16
功能:转换图像阵列为16 位无符号整型。
语法:
I2 = im2uint16(I1)
RGB2 = im2uint16(RGB1)
X2 = im2uint16(X1,'indexed')
相关命令:
im2uint8, double, im2double, uint8, uint16, imapprox
长春工业大学-计算机科学与工程学院数字图像处理课程组
44
52.imadjust
功能:调整图像灰度值或颜色映像表。
语法:
J = imadjust(I,[low high],[bottom top],gamma)
newmap = imadjust(map,[low high],[bottom top],gamma)
RGB2 = imadjust(RGB1,...)
举例
I = imread('pout.tif');
J = imadjust(I,[0.3 0.7],[]);
imshow(I)
figure, imshow(J)
相关命令:
brighten, histeq
53.imapprox
功能:对索引图像进行近似处理。
语法:
[Y,newmap] = imapprox(X,map,n)
[Y,newmap] = imapprox(X,map,tol)
Y = imapprox(X,map,newmap)
[...] = imapprox(...,dither_option)
相关命令:
cmunique, dither, rgb2ind
54.imcontour
功能:创建图像数据的轮廓图。
语法:
imcontour(I,n)
imcontour(I,v)
长春工业大学-计算机科学与工程学院数字图像处理课程组
45
imcontour(x,y,...)
imcontour(...,LineSpec)
[C,h] = imcontour(...)
举例
I = imread('ic.tif');
imcontour(I,3)
相关命令:
clabel, contour, LineSpec
55.imcrop
功能:剪切图像。
语法:
I2 = imcrop(I)
X2 = imcrop(X,map)
RGB2 = imcrop(RGB)
I2 = imcrop(I,rect)
X2 = imcrop(X,map,rect)
RGB2 = imcrop(RGB,rect)
[...] = imcrop(x,y,...)
[A,rect] = imcrop(...)
[x,y,A,rect] = imcrop(...)
举例
I = imread('ic.tif');
I2 = imcrop(I,[60 40 100 90]);
imshow(I)
figure, imshow(I2)
长春工业大学-计算机科学与工程学院数字图像处理课程组
46
相关命令: zoom
56.imfeature
功能:计算图像区域的特征尺寸。 语法: stats = imfeature(L,measurements) stats = imfeature(L,measurements,n) 举例 BW = imread('text.tif'); L = bwlabel(BW); stats = imfeature(L,'all'); stats(23) ans = Area: 89 Centroid: [95.6742 192.9775] BoundingBox: [87.5000 184.5000 16 15] MajorAxisLength: 19.9127 MinorAxisLength: 14.2953 Eccentricity: 0.6961 Orientation: 9.0845 ConvexHull: [28x2 double] ConvexImage: [15x16 uint8 ]
ConvexArea: 205
Image: [15x16 uint8 ]
FilledImage: [15x16 uint8 ]
FilledArea: 122
EulerNumber: 0
Extrema: [ 8x2 double]
EquivDiameter: 10.6451
Solidity: 0.4341
Extent: 0.3708
PixelList: [89x2 double]
相关命令:
长春工业大学-计算机科学与工程学院数字图像处理课程组
47
bwlabel
57.imfinfo
功能:返回图形文件信息。
语法:
info = imfinfo(filename,fmt)
info = imfinfo(filename)
举例
info = imfinfo('canoe.tif')
info =
Filename:'canoe.tif'
FileModDate: '25-Oct-1996 22:10:39'
FileSize: 69708
Format: 'tif'
FormatVersion: []
Width: 346
Height: 207
BitDepth: 8
ColorType: 'indexed'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubfileType: 0
BitsPerSample: 8
Compression: 'PackBits'
PhotometricInterpretation: 'RGB Palette' StripOffsets: [ 9x1 double]
SamplesPerPixel: 1
RowsPerStrip: 23
StripByteCounts: [ 9x1 double]
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Colormap: [256x3 double]
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
长春工业大学-计算机科学与工程学院数字图像处理课程组
48
Thresholding: 1
相关命令:
imread, imwrite
58.imhist
功能:显示图像数据的柱状图。
语法:
imhist(I,n)
imhist(X,map)
[counts,x] = imhist(...)
举例
I = imread('pout.tif');
imhist(I)
相关命令:
histeq
59.immovie
功能:创建多帧索引图的电影动画。
语法:
mov = immovie(X,map)
举例
load mri
mov = immovie(D,map);
相关命令:
montage
60.imnoise
功能:增加图像的渲染效果。
长春工业大学-计算机科学与工程学院数字图像处理课程组
49
语法:
J = imnoise(I,type)
J = imnoise(I,type,parameters)
举例
I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
imshow(I)
figure, imshow(J)
相关命令:
rand
61.impixel
功能:确定像素颜色值。
语法:
P = impixel(I)
P = impixel(X,map)
P = impixel(RGB)
P = impixel(I,c,r)
P = impixel(X,map,c,r)
P = impixel(RGB,c,r)
[c,r,P] = impixel(...)
P = impixel(x,y,I,xi,yi)
P = impixel(x,y,X,map,xi,yi)
P = impixel(x,y,RGB,xi,yi)
[xi,yi,P] = impixel(x,y,...)
举例
RGB = imread('flowers.tif');
c = [12 146 410];
r = [104 156 129];
pixels = impixel(RGB,c,r)
pixels =
61 59 101
253 240 0
237 37 44
长春工业大学-计算机科学与工程学院数字图像处理课程组
50
相关命令:
improfile, pixval
62.improfile
功能:沿线段计算剖面图的像素值。
语法:
c = improfile
c = improfile(n)
c = improfile(I,xi,yi)
c = improfile(I,xi,yi,n)
[cx,cy,c] = improfile(...)
[cx,cy,c,xi,yi] = improfile(...)
[...] = improfile(x,y,I,xi,yi)
[...] = improfile(x,y,I,xi,yi,n) [...] = improfile(...,method)
举例
I = imread('alumgrns.tif');
x = [35 338 346 103];
y = [253 250 17 148];
improfile(I,x,y), grid on
相关命令:
impixel, pixval
63.imread
功能:从图形文件中读取图像。
语法:
A = imread(filename,fmt)
[X,map] = imread(filename,fmt)
[...] = imread(filename)
[...] = imread(...,idx) (TIFF only)
长春工业大学-计算机科学与工程学院数字图像处理课程组
51
[...] = imread(...,ref) (HDF only) [...] = imread(...,’BackgroundColor’,BG) (PNG only) [A,map,alpha] = imread(...) (PNG only) 举例
[X,map] = imread('flowers.tif',6);
info = imfinfo('skull.hdf');
[X,map] = imread('skull.hdf',info(4).Reference);
bg = [255 0 0];
A = imread('image.png','BackgroundColor',bg);
[A,map,alpha] = imread('image.png');
相关命令:
imfinfo, imwrite,fread,double,uint8,uint16
64.imresize
功能:改变图像大小。
语法:
B = imresize(A,m,method)
B = imresize(A,[mrows ncols],method)
B = imresize(...,method,n)
B = imresize(...,method,h)
65.imrotate
功能:旋转图像。
语法:
B = imrotate(A,angle,method)
B = imrotate(A,angle,method,'crop')
举例
I = imread('ic.tif');
J = imrotate(I,–4,'bilinear','crop');
imshow(I)
figure, imshow(J)
相关命令:
长春工业大学-计算机科学与工程学院数字图像处理课程组
52
imcrop, imresize
66.imshow
功能:显示图像。
语法:
imshow(I,n) imshow(I,[low high]) imshow(BW) imshow(X,map) imshow(RGB) imshow(...,display_option) imshow(x,y,A,...) imshow filename h = imshow(...) 相关命令: getimage, imread, iptgetpref, iptsetpref, subimage, truesize, warp
67.imwrite
功能:把图像写入图形文件中。 语法: imwrite(A,filename,fmt) imwrite(X,map,filename,fmt) imwrite(...,filename) imwrite(...,Param1,Val1,Param2,Val2...) 举例 imwrite(X,map,'flowers.hdf','Compression','none',... 'WriteMode','append') 相关命令: imfinfo, imread
68.ind2gray
功能:把检索图像转化为灰度图像。 语法: I = ind2gray(X,map) 举例 load trees I = ind2gray(X,map); imshow(X,map) figure,imshow(I)
长春工业大学-计算机科学与工程学院数字图像处理课程组
53
相关命令: gray2ind, imshow, rgb2ntsc
69.ind2rgb
功能:转化索引图像为 RGB 真彩图像。 语法: RGB = ind2rgb(X,map) 相关命令: ind2gray, rgb2ind
70.iptgetpref
功能:获取图像处理工具箱参数设置。 语法: value = iptgetpref(prefname) 举例 value = iptgetpref('ImshowAxesVisible') value = off 相关命令: imshow, iptsetpref
71.iptsetpref
功能:设置图像处理工具箱参数。 语法: iptsetpref(prefname,value) 举例 iptsetpref('ImshowBorder','tight') 相关命令: imshow, iptgetpref, truesize
长春工业大学-计算机科学与工程学院数字图像处理课程组
54
72.Iradon
功能:进行反Radon 变换。
语法:
I = iradon(P,theta)
I = iradon(P,theta,interp,filter,d,n)
[I,h] = iradon(...)
举例
P = phantom(128);
R = radon(P,0:179);
I = iradon(R,0:179,'nearest','Hann');
imshow(P)
figure, imshow(I)
相关命令:
radon, phantom
73.isbw
功能:判断是否为二进制图像。
语法:
flag = isbw(A)
相关命令:
isind, isgray, isrgb
74.isgray
功能:判断是否为灰度图像。
语法:
flag = isgray(A)
相关命令:
isbw, isind, isrgb
长春工业大学-计算机科学与工程学院数字图像处理课程组
55
75.isind
功能:判断是否为索引图像。
语法:
flag = isind(A)
相关命令:
isbw, isgray, isrgb
76.isrgb
功能:判读是否为RGB真彩图像。
语法:
flag = isrgb(A)
相关命令:
isbw, isgray, isind
77.makelut
功能:创建一个用于applylut 函数的lookup 表。
语法:
lut = makelut(fun,n)
lut = makelut(fun,n,P1,P2,...)
举例
f = inline('sum(x(:)) >= 2');
lut = makelut(f,2)
lut =
0
0
0
1
0
1
1
1
0
1
1
1
1
1
1
1
长春工业大学-计算机科学与工程学院数字图像处理课程组
56
相关命令:
applylut
78.mat2gray
功能:转化矩阵为灰度图像。
语法:
I = mat2gray(A,[amin amax])
I = mat2gray(A)
举例
I = imread('rice.tif');
J = filter2(fspecial('sobel'),I);
K = mat2gray(J);
imshow(I)
figure, imshow(K)
相关命令:
gray2ind
79.mean2
功能:计算矩阵元素的平均值。
语法:
b = mean2(A)
相关命令:
std2, mean, std
80.medfilt2
功能:进行二维中值过滤。
语法:
B = medfilt2(A,[m n])
B = medfilt2(A)
B = medfilt2(A,'indexed',...)
长春工业大学-计算机科学与工程学院数字图像处理课程组
57
举例
I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
K = medfilt2(J);
imshow(J)
figure, imshow(K)
相关命令:
filter2, ordfilt2, wiener2
81.montage
功能:在矩形框中同时显示多幅图像。
语法:
montage(I)
montage(BW)
montage(X,map)
montage(RGB)
h = montage(...)
举例
load mri
montage(D,map)
相关命令: immovie
长春工业大学-计算机科学与工程学院数字图像处理课程组
58
82.nlfilter
功能:进行边沿操作。 语法: B = nlfilter(A,[m n],fun) B = nlfilter(A,[m n],fun,P1,P2,...) B = nlfilter(A,'indexed',...) 举例 B = nlfilter(A,[3 3],'median(x(:))'); 相关命令: blkproc, colfilt
83.ntsc2rgb
功能:转换 NTSC 的值为 RGB 颜色空间。 语法: rgbmap = ntsc2rgb(yiqmap) RGB = ntsc2rgb(YIQ) 相关命令: rgb2ntsc, rgb2ind, ind2rgb, ind2gray
84.ordfilt2
功能:进行二维统计顺序过滤。 语法: B = ordfilt2(A,order,domain) B = ordfilt2(A,order,domain,S) B = ordfilt2(...,padopt)
相关命令:
medfilt2
85.phantom
功能:产生一个头部幻影图像。
语法:
P = phantom(def,n)
P = phantom(E,n)
[P,E] = phantom(...)
举例
P = phantom('Modified Shepp-Logan',200);
imshow(P)
长春工业大学-计算机科学与工程学院数字图像处理课程组
59
相关命令:
radon, iradon
86.pixval
功能:显示图像像素信息。
语法:
pixval on
pixval off
pixval
pixval(fig,option)
相关命令:
impixel, improfile
87.qtdecomp
功能:进行四叉树分解。
语法:
S = qtdecomp(I)
S = qtdecomp(I,threshold)
S = qtdecomp(I,threshold,mindim)
S = qtdecomp(I,threshold,[mindim maxdim])
S = qtdecomp(I,fun)
S = qtdecomp(I,fun,P1,P2,...)
举例
I = [1 1 1 1 2 3 6 6
1 1 2 1 4 5 6 8
1 1 1 1 10 15 7 7
1 1 1 1 20 25 7 7
20 22 20 22 1 2 3 4
20 22 22 20 5 6 7 8
20 22 20 20 9 10 11 12
长春工业大学-计算机科学与工程学院数字图像处理课程组
60
22 22 20 20 13 14 15 16];
S = qtdecomp(I,5);
full(S)
ans =
4 0 0 0 2 0 2 0
0 0 0 0 0 0 0 0
0 0 0 0 1 1 2 0
0 0 0 0 1 1 0 0
4 0 0 0 2 0 2 0
0 0 0 0 0 0 0 0
0 0 0 0 2 0 2 0
0 0 0 0 0 0 0 0
相关命令:
qtgetblk, qtsetblk
88.qtgetblk
功能:获取四叉树分解中的块值。
语法:
[vals,r,c] = qtgetblk(I,S,dim)
[vals,idx] = qtgetblk(I,S,dim)
举例
[vals,r,c] = qtgetblk(I,S,4)
vals(:,:,1) =
1 1 1 1
1 1 2 1
1 1 1 1
1 1 1 1
vals(:,:,2) =
20 22 20 22
20 22 22 20
20 22 20 20
22 22 20 20
r =
1
5
c =
1
1
相关命令:
qtdecomp, qtsetblk
长春工业大学-计算机科学与工程学院数字图像处理课程组
61
89.qtsetblk
功能:设置四叉树分解中的块值。
语法:
J = qtsetblk(I,S,dim,vals)
举例
newvals = cat(3,zeros(4),ones(4));
J = qtsetblk(I,S,4,newvals)
J =
0 0 0 0 2 3 6 6
0 0 0 0 4 5 6 8
0 0 0 0 10 15 7 7 0 0 0 0 20 25 7 7
1 1 1 1 1 2 3 4
1 1 1 1 5 6 7 8
1 1 1 1 9 10 11 12
1 1 1 1 13 14 15 16
相关命令:
qtdecomp, qtgetblk
90.radon
功能:计算Radon变换。
语法:
R = radon(I,theta)
R = radon(I,theta,n)
[R,xp] = radon(...)
举例
iptsetpref('ImshowAxesVisible','on')
I = zeros(100,100);
I(25:75,25:75) = 1;
theta = 0:180;
[R,xp] = radon(I,theta);
imshow(theta,xp,R,[]), colormap(hot), colorbar
长春工业大学-计算机科学与工程学院数字图像处理课程组
62
相关命令: iradon, phantom
91.rgb2gray
功能:转换 RGB 图像或颜色映像表为灰度图像。 语法: I = rgb2gray(RGB) newmap = rgb2gray(map) 相关命令: ind2gray, ntsc2rgb, rgb2ind, rgb2ntsc 92.rgb2hsv
功能:
转化RGB值为HSV颜色空间。
语法:
hsvmap = rgb2hsv(rgbmap)
HSV = rgb2hsv(RGB)
相关命令:
hsv2rgb, rgbplot
93.rgb2ind
功能:转化RGB图像为索引图像。
语法:
[X,map] = rgb2ind(RGB,tol)
[X,map] = rgb2ind(RGB,n)
X = rgb2ind(RGB,map)
[...] = rgb2ind(...,dither_option)
举例
RGB = imread('flowers.tif');
[X,map] = rgb2ind(RGB,128);
imshow(X,map)
长春工业大学-计算机科学与工程学院数字图像处理课程组
63
相关命令:
cmunique, dither, imapprox, ind2rgb, rgb2gray
94.rgb2ntsc
功能:转化RGB的值为NTSC颜色空间。
语法:
yiqmap = rgb2ntsc(rgbmap)
YIQ = rgb2ntsc(RGB)
相关命令:
ntsc2rgb, rgb2ind, ind2rgb, ind2gray
95.rgb2ycbcr
功能:转化RGB的值为YcbCr 颜色空间。
语法:
ycbcrmap = rgb2ycbcr(rgbmap)
YCBCR = rgb2ycbcr(RGB)
相关命令:
ntsc2rgb, rgb2ntsc, ycbcr2rgb
96.rgbplot
功能:划分颜色映像表。
语法:
rgbplot(map)
举例
rgbplot(jet)
长春工业大学-计算机科学与工程学院数字图像处理课程组
64
相关命令:
colormap
97.roicolor
功能:选择感兴趣的颜色区。
语法:
BW = roicolor(A,low,high)
BW = roicolor(A,v)
举例
I = imread('rice.tif');
BW = roicolor(I,128,255);
imshow(I);
figure, imshow(BW)
相关命令:
roifilt2, roipoly
98.roifill
功能:在图像的任意区域中进行平滑插补。
语法:
J = roifill(I,c,r)
J = roifill(I)
J = roifill(I,BW)
长春工业大学-计算机科学与工程学院数字图像处理课程组
65
[J,BW] = roifill(...)
J = roifill(x,y,I,xi,yi)
[x,y,J,BW,xi,yi] = roifill(...)
举例
I = imread('eight.tif');
c = [222 272 300 270 221 194];
r = [21 21 75 121 121 75];
J = roifill(I,c,r);
imshow(I)
figure, imshow(J)
相关命令:
roifilt2, roipoly
99.roifilt2
功能:过滤敏感区域。
语法:
J = roifilt2(h,I,BW)
J = roifilt2(I,BW,fun)
J = roifilt2(I,BW,fun,P1,P2,...)
举例
h = fspecial('unsharp');
J = roifilt2(h,I,BW);
imshow(J)
相关命令: filter2, roipoly
长春工业大学-计算机科学与工程学院数字图像处理课程组
66
100.roipoly
功能:选择一个敏感的多边形区域。 语法: BW = roipoly(I,c,r) BW = roipoly(I) BW = roipoly(x,y,I,xi,yi) [BW,xi,yi] = roipoly(...) [x,y,BW,xi,yi] = roipoly(...) 举例 I = imread('eight.tif'); c = [222 272 300 270 221 194]; r = [21 21 75 121 121 75]; BW = roipoly(I,c,r); imshow(I) figure, imshow(BW)
相关命令: roifilt2, roicolor, roifill
101.std2
功能:计算矩阵元素的标准偏移。 语法: b = std2(A) 相关命令: corr2, mean2
102.subimage
功能:在一幅图中显示多个图像。 语法:
长春工业大学-计算机科学与工程学院数字图像处理课程组
67
subimage(X,map) subimage(I) subimage(BW) subimage(RGB) subimage(x,y,...) h = subimage(...) 举例 load trees [X2,map2] = imread('forest.tif'); subplot(1,2,1), subimage(X,map) subplot(1,2,2), subimage(X2,map2) 相关命令:
103.truesize
功能:调整图像显示尺寸。
语法:
truesize(fig,[mrows mcols])
truesize(fig)
相关命令:
imshow, iptsetpref, iptgetpref
104.uint8
功能:转换数据为8 位无符号整型。
语法:
B = uint8(A)
举例
a = [1 3 5];
b = uint8(a);
whos
Name Size Bytes Class
a 1x3 24 doublearray
b 1x3 3 uint8 array
相关命令:
长春工业大学-计算机科学与工程学院数字图像处理课程组
68
double, im2double, im2uint8
105.uint16
功能:转换数据为16 位无符号整型。
语法:
I = uint16(X)
举例
a = [1 3 5];
b = uint16(a);
whos
Name Size Bytes Class
a 1x3 24 double array
b 1x3 6 uint16 array
相关命令:
double, datatypes, uint8, uint32, int8, int16, int32.
106.warp
功能:将图像显示到纹理映射表面。
语法:
warp(X,map)
warp(I,n)
warp(BW)
warp(RGB)
warp(z,...)
warp(x,y,z,...)
h = warp(...)
举例
[x,y,z] = cylinder;
I = imread('testpat1.tif');
warp(x,y,z,I);
相关命令:
长春工业大学-计算机科学与工程学院数字图像处理课程组
69
imshow
107.wiener2
功能:进行二维适应性去噪过滤处理。
语法:
J = wiener2(I,[m n],noise)
[J,noise] = wiener2(I,[m n])
举例
I = imread('saturn.tif');
J = imnoise(I,'gaussian',0,0.005);
K = wiener2(J,[5 5]);
imshow(J)
figure, imshow(K)
相关命令:
filter2, medfilt2
108.ycbcr2rgb
功能:转化YcbCr 值为RGB颜色空间。
语法:
rgbmap = ycbcr2rgb(ycbcrmap)
RGB = ycbcr2rgb(YCBCR)
相关命令:
ntsc2rgb, rgb2ntsc, rgb2ycbcr
109.zoom
功能:缩放图像。
语法:
zoom on
zoom off
zoom out
长春工业大学-计算机科学与工程学院数字图像处理课程组
70
zoom reset
zoom
zoom xon
zoom yon
zoom(factor)
zoom(fig,option)
相关命令:
imcrop