1.imread函数
A = imread(filename, fmt) 读入字符串指定的文件名的图片文件。逗号后面的参数为格式。
该函数的返回值A有两种情况:
1.当图片文件为灰度图像的时候,得到的A是一个MxN的二维矩阵;
2.当图片文件为真彩图片的时候,得到的A是一个MxNx3的三维矩阵。
(注意这里的第三维一定是3,与图无关)
对于tiff格式的文件,由于它里面包含的彩色图片是采用CMYK色彩空间的,所以返回来的A是一个 MxNx4的三维矩阵。关于TIFF的更多信息请使用help窗口查看。
The class of A depends on the bits-per-sample
of the image data, rounded to被取整到 the next byte boundary. For example, imread returns
24-bit color data as an array of uint8 data because the sample size for each color component is 8 bits.例如,imread函数将24位的彩色数据返回为一个包含8位无符号整数的数组,因为每个色彩单元的样本尺寸是8比特。 See Tips for a discussion of bitdepths, and see Format-Specific Information for
more detail about supported bit depths and sample sizes for a particular format.
对于tiff格式的文件,由于它里面包含的彩色图片是采用CMYK色彩空间的,所以返回来的A是一个 MxNx4的三维矩阵。关于TIFF的更多信息请使用help窗口查看。
The class of A depends on the bits-per-sample
of the image data, rounded to被取整到 the next byte boundary. For example, imread returns
24-bit color data as an array of uint8 data because the sample size for each color component is 8 bits.例如,imread函数将24位的彩色数据返回为一个包含8位无符号整数的数组,因为每个色彩单元的样本尺寸是8比特。 See Tips for a discussion of bitdepths, and see Format-Specific Information for
more detail about supported bit depths and sample sizes for a particular format.
[X, map] = imread(...) reads the indexed image in filename into X and its associated colormap into map. Colormap values in the image file are automatically rescaled into the range [0,1].
该语句读取被索引的图片放入X中并且与其相关联的颜色
映射
表读入到变量map中。图片文件中的颜色映射表的所有值都被自动地重整到[0,1]区间的范围。
[...] = imread(filename) attempts to infer the format of the file from its content.
该语句是用来根据文件的内容来尝试推断文件的格式的。
[...] = imread(URL,...) reads the image from an Internet URL. The URL must include the protocol type (e.g.,
http://).
该语句是从网址或者说
统一资源定位符(Uniform Resource Locator)上读取互联网上的图片,而该网址必须包含协议类型也就是说例如HTTP等的开头。
[...] = imread(...,Param1,Val1,Param2,Val2...) specifies parameters that control various characteristics of the operations for specific formats. For more information, see Format-Specific Information.
EXAMPLE
Read and Display Image
Read a sample image.
A = imread('ngc6543a.jpg');
Read a sample image.
A = imread('ngc6543a.jpg');
mread returns a 650-by-600-by-3 array, A.
Display the image.
image(A)
Convert Indexed Image to RGB
Read an image and convert it to an RGB image.
Read the first image in the sample indexed image file, corn.tif.
Read an image and convert it to an RGB image.
Read the first image in the sample indexed image file, corn.tif.
[X,map] = imread('corn.tif');
X is a 415-by-312 array of type uint8.
X is a 415-by-312 array of type uint8.
Verify that the colormap, map, is not empty, and convert the data in X to RGB.通过map这个变量的值来验证颜色映射表是否为空(非真彩图像为空,彩色图像为非空),当为非空时将X的数据转换为RGB模型(彩色图像)。
if ~isempty(map)
Im = ind2rgb(X,map);
end
Im = ind2rgb(X,map);
end
View the size and class of X.
whos Im
Name Size Bytes Class Attributes
Im 415x312x3 3107520 double
Im 415x312x3 3107520 double
X is now a 415-by-312-by-3 array of type double.
2.im2double函数
Convert image to double precision 将图像转换为双精度数据类型
Syntax
Syntax
I2 = im2double(I)
RGB2 = im2double(RGB)
I = im2double(BW)
X2 = im2double(X,'indexed')
gpuarrayB = im2dou