您的当前位置:首页正文

MATLAB图像处理工具箱常用函数列表

2023-11-05 来源:步旅网


附录 MATLAB图像处理工具箱函数

表1 通用函数

函数 功能 colorbar colorbar(...,'peer',axes_handle) colorbar 显示颜色条 语法 colorbar(axes_handle) colorbar('location') colorbar(...,'PropertyName',propertyvalue) cbar_axes = colorbar(...) A = getimage(h) getimage 从坐标轴取得图像数据 [x,y,A] = getimage(h) [...,A,flag] = getimage(h) [...] = getimage image(C) image(x,y,C) image 创建并显示图像对象 image(...,'PropertyName',PropertyValue,...) image('PropertyName',PropertyValue,...) Formal syntax - PN/PV only handle = image(...) imagesc(C) imagesc 按图像显示数据矩阵 imagesc(x,y,C) imagesc(...,clims) h = imagesc(...) imshow(I,n) imshow 显示图像 imshow(I,[low high]) imshow(BW) imshow(X,map) 1

imshow(RGB) imshow(…,display_option) imshow(x,y,A,…) imshow filename h = imshow(…) imview(I) imview(RGB) imview(X,map) imview 利用图像浏览器显示图像 imview(I,range) imview(filename) imview(...,'InitialMagnification',initial_mag) h = imview(...) imview close all montage(I) montage 在矩形框中同时显示多帧图像 montage(BW) montage(X,map) montage(RGB) h = montage(...) immovie 创建多帧索引色图像的电影动画 mov = immovie(X,map) mov = immovie(RGB) subimage(X,map) subimage(I) subimage 在一个图形中显示多个图像,结合函数subplot使用 subimage(BW) subimage(RGB) subimage(x,y,...) h = subimage(...) truesize 调整图像显示尺寸 truesize(fig,[mrows mcols]) truesize(fig) warp(X,map) warp(I,n) warp(BW) wrap 将图像显示到纹理映射表面 warp(RGB) warp(z,...) warp(x,y,z,...) h = warp(...) 2

zoom on zoom off zoom out zoom reset zoom 缩放图像或图形 zoom zoom xon zoom yon zoom(factor) zoom(fig, option)

3

表2 图像文件I/O函数

函数 imfinfo 功能 返回图像文件信息 语法 info = imfinfo(filename,fmt) info = imfinfo(filename) A = imread(filename,fmt) [X,map] = imread(filename,fmt) [...] = imread(filename) [...] = imread(URL,...) [...] = imread(...,idx) (CUR, GIF, ICO, and TIFF only) imread 从图像文件中读取图像 [...] = imread(..., 'PixelRegion', { ROWS, COLS }) (TIFF only) [...] = imread(...,'frames',idx) (GIF only) [...] = imread(...,ref) (HDF only) [...] = imread(...,'BackgroundColor',BG) (PNG only) [A,map,alpha] = imread(...) (ICO, CUR, and PNG only) imwrite(A,filename,fmt) imwrite 把图像写入图像文件中 imwrite(X,map,filename,fmt) imwrite(...,filename) imwrite(...,Param1,Val1,Param2,Val2...)

4

表3 空间变换函数

函数 findbounds fliptform 功能 为空间变换寻找输出边界 切换空间变换结构的输入和输出角色 语法 outbounds = findbounds(TFORM,inbounds) TFLIP = fliptform(T) I2 = imcrop(I) X2 = imcrop(X,map) RGB2 = imcrop(RGB) I2 = imcrop(I,rect) imcrop 剪切图像 X2 = imcrop(X,map,rect) RGB2 = imcrop(RGB,rect) [...] = imcrop(x,y,...) [A,rect] = imcrop(...) [x,y,A,rect] = imcrop(...) B = imresize(A,m) B = imresize(A,m,method) imresize 图像缩放 B = imresize(A,[mrows ncols],method) B = imresize(...,method,n) B = imresize(...,method,h) B = imrotate(A,angle) imrotate 图像旋转 B = imrotate(A,angle,method) B = imrotate(A,angle,method,bbox) ZI = interp2(X,Y,Z,XI,YI) interp2 2-D数据插值 ZI = interp2(Z,XI,YI) ZI = interp2(Z,ntimes) ZI = interp2(X,Y,Z,XI,YI,method) B = imtransform(A,TFORM) B = imtransform(A,TFORM,INTERP) imtransform 对图像进行2-D空间变换 [B,XDATA,YDATA] = imtransform(...) [B,XDATA,YDATA] = imtransform(..., param1, val1, param2, val2,...) makeresampler 生成重采样结构 maketform

生成几何变换结构 R = makeresampler(interpolant,padmethod) T = maketform(transformtype,...) 5

tformarray 多维数组的空间变换 B = tformarray(A, T, R, TDIMS_A, TDIMS_B, TSIZE_B, TMAP_B,F) [X,Y] = tformfwd(T,U,V) [X1,X2,X3,...] = tformfwd(T,U1,U2,U3,...) tformfwd 正向空间变换 X = tformfwd(T,U) [X1,X2,X3,...] = tformfwd(T,U) X = tformfwd(T,U1,U2,U3,...) tforminv 逆向空间变换 U = tforminv(X,T)

6

表4 像素和统计处理函数

函数 corr2 功能 计算两个矩阵的2-D相关系数 语法 r = corr2(A,B) imcontour(I) imcontour(I,n) imcontour 创建图像的轮廓图 imcontour(I,v) imcontour(x,y,...) imcontour(...,LineSpec) [C,h] = imcontour(...) imhist(I,n) imhist 显示图像的直方图 imhist(X,map) [counts,x] = imhist(...) P = impixel(I) P = impixel(X,map) P = impixel(RGB) P = impixel(I,c,r) P = impixel(X,map,c,r) impixel 确定像素颜色值 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,...) c = improfile c = improfile(n) c = improfile(I,xi,yi) c = improfile(I,xi,yi,n) improfile 沿线段计算剖面图的像素值 [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) mean2

求矩阵元素平均值 B = mean2(A) 7

pixval on pixval off pixval 显示图像像素信息 pixval pixval(fig,option) pixval(ax,option) pixval(H,option) regionprops std2 得到图像区域属性 计算矩阵元素的标准偏移 STATS = regionprops(L,properties) b = std2(A)

8

表5 图像分析函数

函数 功能 语法 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) edge 识别灰度图像中的边界 [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',...) S = qtdecomp(I) S = qtdecomp(I,threshold) qtdecomp 执行四叉树分解 S = qtdecomp(I,threshold,mindim) S = qtdecomp(I,threshold,[mindim maxdim]) S = qtdecomp(I,fun) S = qtdecomp(I,fun,P1,P2,...) 获取四叉树分解中的数组块qtgetblk [vals,r,c] = qtgetblk(I,S,dim) [vals,idx] = qtgetblk(I,S,dim) J = qtsetblk(I,S,dim,vals) 值 设置四叉树分解中的数组块值 qtsetblk

9

表6 图像增强函数

函数 adapthisteq 功能 执行对比度受限的直方图均衡 对多通道图像应用解卷积延拓 语法 J = adapthisteq(I) J = adapthisteq(I,param1,val1,param2,val2...) S = decorrstretch(I) S = decorrstretch(I,TOL) J = histeq(I,hgram) J = histeq(I,n) decorrstretch histeq 用直方图均等化增强对比度 [J,T] = histeq(I,...) newmap = histeq(X,map,hgram) newmap = histeq(X,map) [newmap,T] = histeq(X,...) J = imadjust(I) J = imadjust(I,[low_in; high_in],[low_out; 调整图像灰度值或颜色映射high_out]) J = imadjust(...,gamma) newmap = imadjust(map, [low_in high_in], [low_out high_out], gamma) RGB2 = imadjust(RGB1,...) imadjust 表 imnoise 向图像中加入噪声 J = imnoise(I,type) J = imnoise(I,type,parameters) B = medfilt2(A,[m n]) medfilt2 进行二维中值滤波 B = medfilt2(A) B = medfilt2(A,'indexed',...) B = ordfilt2(A,order,domain) ordfilt2 进行二维统计顺序滤波 B = ordfilt2(A,order,domain,S) B = ordfilt2(...,padopt) stretchlim 得到图像对比度延拓的灰度上下限 进行二维适应性去噪滤波 LOW_HIGH = stretchlim(I,TOL) LOW_HIGH = stretchlim(RGB,TOL) J = wiener2(I,[m n],noise) [J,noise] = wiener2(I,[m n])

wiener2 10

表7 线性滤波函数

函数 功能 C = conv2(A,B) conv2 二维卷积 语法 C = conv2(hcol,hrow,A) C = conv2(...,'shape') convmtx2 二维矩阵卷积 T = convmtx2(H,m,n) T = convmtx2(H,[m n]) C = convn(A,B) C = convn(A,B,'shape') Y = filter2(h,X) Y = filter2(h,X,shape) h = fspecial(type) h = fspecial(type,parameters) B = imfilter(A,H) B = imfilter(A,H,option1,option2,...) convn n维卷积 filter2 二维线性滤波 fspecial 创建预定义滤波器 imfilter 多维图像滤波

11

表8 线性二维滤波器设计函数

函数 功能 语法 [f1,f2] = freqspace(n) 确定二维频率响应的频率空间 [f1,f2] = freqspace([m n]) [x1,y1] = freqspace(...,'meshgrid') f = freqspace(N) f = freqspace(N,'whole') [H,f1,f2] = freqz2(h,n1,n2) [H,f1,f2] = freqz2(h,[n2 n1]) [H,f1,f2] = freqz2(h) freqspace freqz2 计算二维频率响应 [H,f1,f2] = freqz2(h,f1,f2) [...] = freqz2(h,...,[dx dy]) [...] = freqz2(h,...,dx) freqz2(...) fsamp2 用频率采样法设计二维FIR滤波器 通过频率转换法设计二维h = fsamp2(Hd) h = fsamp2(f1,f2,Hd,[m n]) h = ftrans2(b,t) h = ftrans2(b) h = fwind1(Hd,win) h = fwind1(Hd,win1,win2) h = fwind1(f1,f2,Hd,...) h = fwind2(Hd,win) h = fwind2(f1,f2,Hd,win)

ftrans2 FIR滤波器 用一维窗口方法设计二维FIR滤波器 用二维窗口方法设计二维fwind1 fwind2 FIR滤波器 12

表9 图像变换函数

函数 功能 B = dct2(A) dct2 进行二维离散余弦变换 语法 B = dct2(A,m,n) B = dct2(A,[m n]) dctmtx fft2 计算离散余弦变换矩阵 进行二维快速傅立叶变换 D = dctmtx(n) Y = fft2(X) Y = fft2(X,m,n) Y = fftn(X) Y = fftn(X,siz) Y = fftshift(X) Y = fftshift(X,dim) B = idct2(A) fftn 进行n维快速傅立叶变换 转换快速傅立叶变换的输出fftshift 象限 idct2 计算二维逆离散余弦变换 B = idct2(A,m,n) B = idct2(A,[m n]) Y = ifft2(X) ifft2 计算二维逆快速傅立叶变换 Y = ifft2(X,m,n) y = ifft2(..., 'nonsymmetric') y = ifft2(..., 'nonsymmetric') Y = ifftn(X) ifftn 计算n维逆快速傅立叶变换 Y = ifftn(X,siz) y = ifftn(..., 'nonsymmetric') y = ifftn(..., 'nonsymmetric') I = iradon(R,theta) iradon 逆Radon变换 I = iradon(R, theta, interp, filter, frequency_scaling, output_size) [I,H] = iradon(...) P = phantom(def,n) phantom 产生一个头部幻影图像 P = phantom(E,n) [P,E] = phantom(...) radon 计算Radon变换 R=radon(I,theta) [R,xp]=radon(…) 13

F = fanbeam(I,D) fanbeam 计算扇形投影变换 F = fanbeam(...,param1,val1,param1,val2,...) [F,sensor_positions,fan_rotation_angles] fanbeam(...)

= 14

表10 边沿和块处理函数

函数 bestblk 功能 确定进行块操作的块大小 语法 siz = bestblk([m n],k) [mb,nb] = bestblk([m n],k) B = blkproc(A,[m n],fun) blkproc 实现图像的非重叠(distinct)B = blkproc(A,[m n],fun,P1,P2,...) 块操作 B=blkproc(A,[m n],[mborder nborder], fun, ...) B = blkproc(A,'indexed',...) col2im 将矩阵的列重新组织到块中 A = col2im(B,[m n],[mm nn], block_type) A = col2im(B,[m n],[mm nn]) B = colfilt(A,[m n],block_type,fun) colfilt 利用列相关函数进行边沿操作 B = colfilt(A,[m n],block_type,fun,P1,P2,...) B = colfilt(A, [m n], [mblock nblock], block_type, fun,...) B = colfilt(A,'indexed',...) B = im2col(A,[m n],block_type) im2col 重调图像块为列 B = im2col(A,[m n]) B = im2col(A,'indexed',...) B = nlfilter(A,[m n],fun) nlfilter 通用滑动邻域操作 B = nlfilter(A,[m n],fun,P1,P2,...) B = nlfilter(A,'indexed',...)

15

表11 图像形态学操作函数

函数 applylut bwarea bweuler bwhitmiss 功能 在二值图像中利用查找表进行邻域操作 计算二值图像的对象面积 计算二值图像的欧拉数 执行二值图像的击中和击不中操作 标注二值图像中已连接的部语法 A = applylut(BW,LUT) total = bwarea(BW) eul = bweuler(BW,n) BW2 = bwhitmiss(BW1,SE1,SE2) BW2 = bwhitmiss(BW1,INTERVAL) L = bwlabel(BW,n) [L,num] = bwlabel(BW,n) BW2 = bwmorph(BW,operation) BW2 = bwmorph(BW,operation,n) BW2 = bwperim(BW1) BW2 = bwperim(BW1,CONN) BW2 = bwselect(BW,c,r,n) BW2 = bwselect(BW,n) bwlabel 分 二值图像的通用形态学操作 bwmorph bwperim 计算二值图像中对象的周长 bwselect 在二值图像中选择对象 [BW2,idx] = bwselect(...) BW2 = bwselect(x,y,BW,xi,yi,n) [x,y,BW2,idx,xi,yi] = bwselect(...) makelut 创建用于applylut函数的查找表 lut = makelut(fun,n) lut = makelut(fun,n,P1,P2,...) D = bwdist(BW) bwdist 距离变换 [D,L] = bwdist(BW) [D,L] = bwdist(BW,METHOD) imbothat 执行形态学的闭包运算 IM2 = imbothat(IM,SE) IM2 = imbothat(IM,NHOOD) IM2 = imclose(IM,SE) IM2 = imclose(IM,NHOOD) IM2 = imopen(IM,SE) IM2 = imopen(IM,NHOOD) IM2 = imdilate(IM,SE) imclose 图像的闭运算 imopen 图像的开运算 imdilate 图像的膨胀 IM2 = imdilate(IM,NHOOD) IM2 = imdilate(IM,SE,PACKOPT) IM2 = imdilate(...,PADOPT) 16

IM2 = imerode(IM,SE) imerode 图像的腐蚀 IM2 = imerode(IM,NHOOD) IM2 = imerode(IM,SE,PACKOPT,M) IM2 = imerode(...,PADOPT) BW2 = imfill(BW,locations) BW2 = imfill(BW,'holes') I2 = imfill(I) imfill 填充图像区域 BW2 = imfill(BW) [BW2 locations] = imfill(BW) BW2 = imfill(BW,locations,CONN) BW2 = imfill(BW,CONN,'holes') I2 = imfill(I,CONN) imtophat strel 用开运算后的图像减去原图像 创建形态学结构元素 IM2 = imtophat(IM,SE) IM2 = imtophat(IM,NHOOD) SE = strel(shape,parameters)

17

表12 区域处理函数

函数 roicolor 功能 选择感兴趣的颜色区 语法 BW = roicolor(A,low,high) BW = roicolor(A,v) J = roifill(I,c,r) J = roifill(I) roifill 在图像的任意区域中进行平滑插补 J = roifill(I,BW) [J,BW] = roifill(...) J = roifill(x,y,I,xi,yi) [x,y,J,BW,xi,yi] = roifill(...) J = roifilt2(h,I,BW) roifilt2 滤波特定区域 J = roifilt2(I,BW,fun) J = roifilt2(I,BW,fun,P1,P2,...) 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(...) roipoly 域

18

表13 图像代数操作

函数 imadd imsubtract immultiply imdivide 加运算 减运算 乘运算 除运算 功能 Z = imadd(X,Y) 语法 Z = imsubtract(X,Y) Z = immultiply(X,Y) Z = imdivide(X,Y)

19

表14 颜色空间转换函数

函数 hsv2rgb 功能 转换HSV的值为RGB颜色空间 转换NTSC的值为RGB颜色空间 转换RGB的值为HSV颜色空间 转换RGB的值为NTSC颜色空间 转换RGB的值为YCbCr颜语法 M = hsv2rgb(H) ntsc2rgb rgbmap = ntsc2rgb(yiqmap) RGB = ntsc2rgb(YIQ) cmap = rgb2hsv(M) rgb2hsv rgb2ntsc yiqmap = rgb2ntsc(rgbmap) YIQ = rgb2ntsc(RGB) ycbcrmap = rgb2ycbcr(rgbmap) YCBCR = rgb2ycbcr(RGB) rgbmap = ycbcr2rgb(ycbcrmap) RGB = ycbcr2rgb(YCBCR) rgb2ycbcr 色空间 转换YCbCr的值为RGB颜色空间 ycbcr2rgb

20

表15 图像类型和类型转换函数

函数 dither 功能 通过抖动增加外观颜色分辨率,转换图像 转换灰度图像为索引色图像 语法 X = dither(RGB,map) BW = dither(I) [X,map] = gray2ind(I,n) [X,map] = gray2ind(BW,n) X = grayslice(I,n) X = grayslice(I,v) BW = im2bw(I,level) gray2ind grayslice 从灰度图像为索引色图像 im2bw 转换图像为二值图像 BW = im2bw(X,map,level) BW = im2bw(RGB,level) I2 = im2double(I) im2double 转换图像矩阵为双精度类型 RGB2 = im2double(RGB) I = im2double(BW) X2 = im2double(X,'indexed') double uint8 转换数据为双精度类型 转换数据为8位无符号整型 double(X) I = uint8(X) I2 = im2uint8(I) im2uint8 转换图像阵列为8位为无符号整型 RGB2 = im2uint8(RGB) I = im2uint8(BW) X2 = im2uint8(X,'indexed') I2 = im2uint16(I) 转换图像阵列为16位为无im2uint16 RGB2 = im2uint16(RGB) I = im2uint16(BW) X2 = im2uint16(X,'indexed') 符号整型 转换数据为16位无符号整uint16 ind2gray ind2rgb isbw isgray isind isrgb I = uint16(X) 型 转换索引色图像为灰度图像 转换索引色图像为RGB图像 判断是否为二值图像 判断是否为灰度图像 判断是否为索引色图像 判断是否为RGB图像 I = ind2gray(X,map) RGB = ind2rgb(X,map) flag = isbw(A) flag = isgray(A) flag = isind(A) flag = isrgb(A) 21

mat2gray 转换矩阵为灰度图像 转换RGB图像或颜色映射I = mat2gray(A,[amin amax]) I = mat2gray(A) I = rgb2gray(RGB) newmap = rgb2gray(map) [X,map] = rgb2ind(RGB,tol) rgb2gray 表为灰度图像 rgb2ind 转换RGB图像为索引色图像 [X,map] = rgb2ind(RGB,n) X = rgb2ind(RGB,map) [...] = rgb2ind(...,dither_option)

22

表A.16 图像复原函数

函数 功能 语法 J = deconvwnr(I,PSF) deconvwnr 用维纳滤波复原图像 J = deconvwnr(I,PSF,NSR) J = deconvwnr(I,PSF,NCORR,ICORR) J = deconvreg(I,PSF) J = deconvreg(I,PSF,NOISEPOWER) 用最小约束二乘滤波复原图J = deconvreg(I, PSF, NOISEPOWER, LRANGE ) J = deconvreg(I, PSF, NOISEPOWER, LRANGE, REGOP) [J, LAGRA] = deconvreg(I,PSF,...) J = deconvlucy(I,PSF) J = deconvlucy(I,PSF,NUMIT) J = deconvlucy(I,PSF,NUMIT,DAMPAR) deconvreg 像 deconvlucy 用Richardson-Lucy滤波复原图像 J = deconvlucy(I, PSF, NUMIT, DAMPAR, WEIGHT) J = deconvlucy(I, PSF, NUMIT, DAMPAR, WEIGHT, READOUT) J = deconvlucy(I, PSF, NUMIT, DAMPAR, WEIGHT, READOUT, SUBSMPL) [J,PSF] = deconvblind(I,INITPSF) [J,PSF] = deconvblind(I,INITPSF,NUMIT) [J,PSF] = deconvblind(I, INITPSF, NUMIT, DAMPAR) deconvblind 用盲卷积滤波复原图像 [J,PSF] = deconvblind(I, INITPSF, NUMIT, DAMPAR, WEIGHT) [J,PSF] = deconvblind(I, INITPSF, NUMIT, DAMPAR, WEIGHT, READOUT ) [J,PSF] = deconvblind(..., FUN, P1, P2, ..., PN)

23

因篇幅问题不能全部显示,请点此查看更多更全内容