您的位置:首页 > 编程语言 > MATLAB

MATLAB常见函数

2016-12-07 09:40 411 查看
设图像矩阵为A。。

1、读取图像

imread

2、显示图像

imshow(A,[])

3、保存图像

imwrite

○ 作用:imwrite Write image to graphics file.

○ 用法:imwrite(A,FILENAME,FMT) writes the image A to the file specified by FILENAME in the format specified by FMT.

○ 说明:FILENAME is a string that specifies the name of the file.最好是绝对路径文件名,这样就可以保存到自己想要的路径中。

dir

Matlab使用dir函数获得指定文件夹下的所有子文件夹和文件,并存放在在一种为文件结构体数组中.

调用方式:

dir(‘.’)列出当前目录下所有子文件夹和文件

dir(‘G:\Matlab’)列出指定目录下所有子文件夹和文件

dir(‘*.m’)列出当前目录下符合正则表达式的文件夹和文件

返回:

返回一个结构体,包含5个字段

name(the first two are . and ..)

date

bytes

isdir(0:not , 1:is)

datenum

例子:

file_dir = dir([path  '*.bmp']);
dircell = struct2cell(file_dir);
fileNames = dircell(1,:);
for i = 1:length(fileNames)
fileName = char(fileNames(i));
end


trainingFiles = dir('pristine');
trainingIms = cell(length(trainingFiles)-2,1);
for fileIndex = 3:length(trainingFiles) %the first two are . and ..
currentFileName = ['pristine\' trainingFiles(fileIndex).name];
image = imread(currentFileName);
resizedIm = imresize(image, [normalizedWidth normalizedWidth]);
trainingIms{fileIndex-2} = resizedIm;
end


构造绝对路径,将两个字符串连载一起的方法

str1=’Iloveyou’; str2=’123’;

1、方法一:

用中括号将str1和str2像矩阵元素一样包含起来:

SC=[str1,str2]

输出:SC = Iloveyou123

rgb2gray

rgb2gray Convert RGB image or colormap to grayscale.

rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance.

I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I.

NEWMAP = rgb2gray(MAP) returns a grayscale colormap equivalent to MAP.

Class Support

If the input is an RGB image, it can be uint8, uint16, double, or single. The output image I has the same class as the input image.

If the input is a colormap, the input and output colormaps are both of class double.

Example

I = imread('board.tif');
J = rgb2gray(I);
figure, imshow(I), figure, imshow(J);


[X,map] = imread('trees.tif');
gmap = rgb2gray(map);
figure, imshow(X,map), figure, imshow(X,gmap);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: