MATLAB图像处理常用函数

  • 格式:doc
  • 大小:96.00 KB
  • 文档页数:8

一.MATLAB基础1.Linspace功能:创建从初值开始到终值结束,有n个元素的行向量x。

语法:X=linspace(初值,终值,n)2.Logspace功能:创建从初值开始到终值结束,有n个元素对数分隔量x。

语法:X=logspace(初值,终值,n)3.Ones功能:创建元素全为1的数组。

语法:A=ones(n) (n*n的1数组)A=ones(r,c) (r*c的1数组)4.zeros功能:创建元素全为0的数组。

语法:A=zeros(n) (n*n的0数组)A=zeros(r,c) (r*c的0数组)5.Eye功能:创建单位矩陈。

语法:A=eye(n)6.rand功能:创建随机矩阵。

语法:A=rand (m,n)7.randn功能:创建正态分布的随机矩阵。

语法:A=randn(m,n)8.Find功能:寻找非零元素下标。

语法:I = find(X)[I,J] = find(X)[I,J,V] = find(X)9.Size功能:返回矩阵大小。

语法:D = size(X)[M,N] = size(X)10.Length功能:获得已知数组的规模。

语法:N=length(A)11.Reshape功能:改变数组维数、大小。

语法:X=reshape(A,m,n)12.Repmat功能:铺放模块维数语法:X = repmat(A,m,n)13.Diag功能:提取矩阵的对角元素,并返回给列向量。

语法:diag(V,K)14.Flipud功能:将矩阵上下翻转。

语法:X=flipud(A)15.Fliplr功能:将矩阵左右翻转。

语法:X=fliplr(A)16.All功能:所有元素非零为真。

语法:X=all(A)17.Any功能:所有元素非全零为真。

语法;X=any(A)二.转换图像类型:1.Dither功能:通过抖动增加外观颜色分辨率,转换图像。

语法:X = dither(RGB,map)BW = dither(I)相关命令:rgb2ind2.im2bw功能:转换图像为二进制图像。

语法: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, rgb2gray3.ind2gray功能:把检索图像转化为灰度图像。

语法:I = ind2gray(X,map)举例load treesI = ind2gray(X,map);imshow(X,map)figure,imshow(I)相关命令:gray2ind, imshow, rgb2ntsc4.ind2rgb功能:转化索引图像为RGB 真彩图像。

语法:RGB = ind2rgb(X,map)相关命令:ind2gray, rgb2ind5.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)相关命令:gray2ind6.gray2ind功能:转换灰度图像为索引图像。

语法:[X,map] = gray2ind(I,n)相关命令:ind2gray7.grayslice功能:从灰度图像创建索引图像。

语法:X = grayslice(I,n)X = grayslice(I,v)举例I = imread('ngc4024m.tif');X = grayslice(I,16);imshow(I)figure, imshow(X,jet(16))相关命令:gray2ind8.rgb2gray功能:转换RGB 图像或颜色映像表为灰度图像。

语法:I = rgb2gray(RGB)newmap = rgb2gray(map)相关命令:ind2gray, ntsc2rgb, rgb2ind, rgb2ntsc9.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)相关命令:cmunique, dither, imapprox, ind2rgb, rgb2gray三.读写和显示图像:1.imread功能:从图形文件中读取图像。

语法:A = imread(filename,fmt)[X,map] = imread(filename,fmt)[...] = imread(filename)[...] = imread(...,idx) (TIFF only)[...] = 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,uint162.imwrite功能:把图像写入图形文件中。

语法:imwrite(A,filename,fmt)imwrite(X,map,filename,fmt)imwrite(...,filename)imwrite(...,Param1,Val1,Param2,Val2...)举例imwrite(X,map,'flowers.hdf','Compression','no ne',...'WriteMode','append')相关命令:imfinfo, imread3. imfinfo功能:返回图形文件信息。

语法:info = imfinfo(filename,fmt)info = imfinfo(filename)举例info = imfinfo('canoe.tif')info =Filename:'canoe.tif'FileModDate: '25-Oct-1996 22:10:39' FileSize: 69708Format: 'tif'FormatVersion: []Width: 346Height: 207BitDepth: 8ColorType: 'indexed' FormatSignature: [73 73 42 0] ByteOrder: 'little-endian' NewSubfileType: 0 BitsPerSample: 8Compression: 'PackBits' PhotometricInterpretation: 'RGB Palette' StripOffsets: [ 9x1 double] SamplesPerPixel: 1 RowsPerStrip: 23 StripByteCounts: [ 9x1 double] XResolution: 72YResolution: 72ResolutionUnit: 'Inch'Colormap: [256x3 double] PlanarConfiguration: 'Chunky' TileWidth: []TileLength: []TileOffsets: []TileByteCounts: []Orientation: 1FillOrder: 1GrayResponseUnit: 0.0100 MaxSampleValue: 255 MinSampleValue: 0Thresholding: 1相关命令:imread, imwrite4. imshow功能:显示图像。

语法:imshow(I,n)imshow(I,[low high])imshow(BW)imshow(X,map)imshow(RGB)imshow(...,display_option)imshow(x,y,A,...)imshow filenameh = imshow(...)相关命令:getimage, imread, iptgetpref, iptsetpref, subimage, truesize, warp5. colorbar功能:显示颜色条。

语法:colorbar('vert')colorbar('horiz')colorbar(h)colorbarh = colorbar(...)举例I = imread('blood1.tif');h = fspecial('log');I2 = filter2(h,I);imshow(I2,[]), colormap(jet(64)), colorbar6. zoom功能:缩放图像。

语法:zoom onzoom offzoom outzoom resetzoomzoom xonzoom yonzoom(factor)zoom(fig,option)相关命令:imcrop7. subimage功能:在一幅图中显示多个图像。

语法: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) 相关命令:8. montage功能:在矩形框中同时显示多幅图像。