Read image from graphics file
[
additionally returns the image transparency. This syntax applies only to PNG, CUR, and ICO files. For PNG files,A
,map
,transparency
] = imread(___)transparency
是alpha通道,如果存在一个。对于CUR和ICO文件,它是AND(不透明度)掩码。
Read a sample image.
a = imread('ngc6543a.jpg');
imread
返回650×600-by-3阵列,A
。
Display the image.
图像(a)
读取样本索引图像文件中的第一个图像,corn.tif
。
[x,cmap] = imread('玉米。');
索引图像X
is a 415-by-312 array of typeuint8.
。该colormapCMAP.
是256×3矩阵类型双
, therefore there are 256 colors in the indexed image. Display the image.
imshow(X,cmap)
将索引图像转换为RGB图像。结果是415×312×3型类型双
。
RGB = ind2rgb(X,cmap);
Check that values of the RGB image are in the range [0, 1].
DISP(['Range of RGB image is [',num2str(min(rgb(:))),', ',num2str(max(RGB(:))),'].'])
Range of RGB image is [0.0078431, 0.97647].
Return the alpha channel of the sample image,peppers.png
。
[X,map,alpha] = imread('peppers.png'); whosalpha
名称大小字节类属性Alpha 0x0 0 Double
No alpha channel is present, soalpha
是空的。
Read a specific region of pixels of the sample image,corn.tif
。
Specify the'PixelRegion'
parameter with a cell array of vectors indicating the boundaries of the region to read. The first vector specifies the range of rows to read, and the second vector specifies the range of columns to read.
a = imread('玉米。','PixelRegion',{[1,2],[2,5]});
imread
reads the image data in rows 1-2 and columns 2-5 fromcorn.tif
and returns the 2-by-4 array,A
。
文档名称
—名称of graphics file名称of graphics file, specified as a character vector or string scalar.
根据您的文件的位置,文档名称
可以承担其中的一个形式。
位置 |
Form |
||||||||
---|---|---|---|---|---|---|---|---|---|
Current folder or folder on the MATLAB®path | Specify the name of the file in Example: |
||||||||
File in a folder |
如果the file is not in the current folder or in a folder on the MATLAB path, then specify the full or relative path name. Example: Example: |
||||||||
URL | 如果the file is located by an internet URL, then Example: |
||||||||
Remote Location |
如果the file is stored at a remote location, then
基于您的远程位置,
For more information, see使用远程数据。 Example: |
For information on the bit depths, compression schemes, and color spaces supported for each file type, seeAlgorithms。
数据类型:char
|串
fmt
—Image formatImage format, specified as a character vector or string scalar indicating the standard file extension. Callimformats.
to see a list of supported formats and their file extensions.
Example:'png'
数据类型:char
|串
idx.
—阅读图像阅读阅读图像阅读, specified as an integer scalar or, for GIF files, a vector of integers. For example, ifidx.
is 3, thenimread
返回文件中的第三个图像。对于GIF文件,如果idx.
is1:5
, thenimread
仅返回前五个框架。该idx.
argument is supported only for multi-image GIF, CUR, ICO, and HDF4 files.
When reading multiple frames from the same GIF file, specifyidx.
as a vector of frames or use the'Frames','all'
名称值对参数。由于GIF文件构造的方式,与调用相比,这些语法提供了更快的性能imread
在循环中。
对于HDF4文件,idx.
corresponds to the reference number of the image to read. Reference numbers do not necessarily correspond to the order of the images in the file. You can useimfinfo
to match image order with reference number.
Example:3
数据类型:双
Specify optional comma-separated pairs of名称,Value
arguments.名称
is the argument name andValue
is the corresponding value.名称
must appear inside quotes. You can specify several name and value pair arguments in any order as名称1,Value1,...,NameN,ValueN
。
'Index',5
读取TIFF文件的第五个图像。
'Frames'
—Frame to read'all'
读取的框架,指定为逗号分隔对'Frames'
and a positive integer, a vector of integers, or'all'
。例如,if you specify the value 3,imread
reads the third frame in the file. If you specify'all'
, thenimread
reads all frames and returns them in the order in which they appear in the file.
Example:'框架',5
'PixelRegion'
—Subimage to read{Rows,Cols}
读取的Subimage,指定为逗号分隔的配对组成'PixelRegion'
和形式的细胞阵列{Rows,Cols}
。该rows
input specifies the range of rows to read. The科尔斯
输入指定要读取的列范围。都rows
and科尔斯
must be two-element vectors containing 1-based indices. For example,'PixelRegion',{[1 2],[3 4]}
reads the subimage bounded by rows 1 and 2 and columns 3 and 4 in the image data. If the'Reganslevel'
值大于0,然后rows
and科尔斯
是Subimage的坐标。
Example:'pixelregion',{[1 100],[4 500]}
'Reganslevel'
—Reduction of image resolutionReduction of the image resolution, specified as the comma-separated pair consisting of'Reganslevel'
and a nonnegative integer. For reduction levelL, the image resolution is reduced by a factor of 2^L。减少水平受到如此规定的分解水平总数的限制'WaveletDecompositionLevels'
field in the output of theimfinfo
功能。
Example:'Reganslevel',5
数据类型:单
|双
'v79申请'
—Compatibility with MATLAB 7.9 (R2009b) and earlierfalse
(默认)|true
与MATLAB 7.9(R2009B)和更早的兼容性,指定为逗号分隔对'v79申请'
and eithertrue
orfalse
。如果you specifytrue
, then the returned grayscale or RGB image is consistent with previous versions ofimread
(MATLAB 7.9 (R2009b) and earlier).
Example:'v79申请',true
数据类型:logical
'BackgroundColor'
—Background color'none'
|integer|3-element vector of integersBackground color, specified as'none'
, an integer, or a three-element vector of integers. IfBackgroundColor
is'none'
, thenimread
does not perform any compositing. Otherwise,imread
blends transparent pixels with the background color.
如果输入图像被索引,则值为BackgroundColor
must be an integer in the range[1,P]
,在哪里P
is the colormap length.
如果输入图像是灰度,那么值BackgroundColor
must be an integer in the range[0,1]
。
如果the input image is RGB, then the value ofBackgroundColor
必须是三元素矢量,其中值在范围内[0,1]
。
该default value forBackgroundColor
depends on the presence of thetransparency
output argument and the image type:
如果you request thetransparency
output argument, then the default value ofBackgroundColor
is'none'
。
如果you do not request thetransparency
输出和PNG文件包含背景颜色块,然后该颜色是默认值BackgroundColor
。
如果you do not request thetransparency
output and the file does not contain a background color chunk, then the default value forBackgroundColor
is1
for indexed images,0
for grayscale images, and[0 0 0]
for truecolor (RGB) images.
'Index'
—阅读图像阅读阅读图像阅读, specified as the comma-separated pair consisting of'Index'
and a positive integer. For example, if the value ofIndex
is 3, thenimread
reads the third image in the file.
数据类型:单
|双
'Info'
—Information about imageInformation about the image, specified as the comma-separated pair consisting of'Info'
and a structure array returned by theimfinfo
功能。使用Info
name-value pair argument to helpimread
locate the images in a multi-image TIFF file more quickly.
数据类型:struct
'PixelRegion'
—地区边界地区边界, specified as the comma-separated pair consisting of'PixelRegion'
和形式的细胞阵列{Rows,Cols}
。该rows
input specifies the range of rows to read. The科尔斯
输入指定要读取的列范围。rows
and科尔斯
must be either two-element or three-element vectors of 1-based indices. A two-element vector specifies the first and last rows or columns to read. For example,'PixelRegion',{[1 2],[3 4]}
reads the region bounded by rows 1 and 2 and columns 3 and 4 in the image data.
A three-element vector must be in the form[start increment stop]
,在哪里开始
is the first row or column to read,increment
是一个增量值,和stop
是要读取的最后一行或列。此语法允许映像下采样。例如,'PixelRegion',{[1 2 10],[4 3 12]}
读取由行1和10和列4和12界限的区域,并在垂直方向上的每2个像素和水平方向上的每3个像素进行样本数据。
Example:'pixelregion',{[1 100],[4 500]}
数据类型:cell
A
- 图像数据Image data, returned as an array.
如果the file contains a grayscale image, then A is anm
-by-n
array.
如果该文件包含索引图像,则A是一个m
-by-n
索引值数组对应于该索引中的颜色map
。
如果the file contains a truecolor image, then A is anm
-by-n
-by-3 array.
如果文件是一个包含彩色图像的TIFF文件that use the CMYK color space, then A is anm
-by-n
-by-4 array.
该class ofA
depends on the image format and the bit depth of the image data. For more information, seeAlgorithms
map
- ColorMap.m
-by-3 matrixColorMap与索引图像数据相关联A
, returned as anm
-by-3 matrix of class双
。
transparency
— Transparency information透明度信息,作为矩阵返回。对于PNG文件,transparency
是alpha通道,如果存在的话。如果没有alpha通道存在,或者指定'BackgroundColor'
name-value pair argument, thentransparency
是空的。对于cur和iCo文件,transparency
is the AND mask. For cursor files, this mask sometimes contains the only useful data.
比特深度是用于表示每个图像像素的比特数。
Bit depth is calculated by multiplying the bits-per-sample with the samples-per-pixel. Thus, a format that uses 8 bits for each color component (or sample) and three samples per pixel has a bit depth of 24. Sometimes the sample size associated with a bit depth can be ambiguous. For example, does a 48-bit bit depth represent six 8-bit samples, four 12-bit samples, or three 16-bit samples? SeeAlgorithmsfor sample size information to avoid this ambiguity.
For most image file formats,imread
uses 8 or fewer bits per color plane to store image pixels. This table lists the class of the returned image array,A
,对于文件格式使用的位深度。
位深度in File |
Class of Array Returned by |
---|---|
每像素1位 |
|
2 to 8 bits per color plane |
|
9 to 16 bits per pixel |
For the 16-bit BMP packed format (5-6-5), MATLAB returns |
该following sections provide information about the support for specific formats, listed in alphabetical order by format name.
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | 没有压缩 | RLE Compression | Output Class | 笔记 |
---|---|---|---|---|
1位 | ✓ | – | logical |
|
4 bit | ✓ | ✓ | uint8. |
|
8 bit | ✓ | ✓ | uint8. |
|
16位 | ✓ | – | uint8. |
1 sample/pixel |
24位 | ✓ | – | uint8. |
3个样本/像素 |
32位 | ✓ | – | uint8. |
3个样本/像素 (1字节填充) |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | 没有压缩 | Compression | Output Class |
---|---|---|---|
1位 | ✓ | – | logical |
4 bit | ✓ | – | uint8. |
8 bit | ✓ | – | uint8. |
Note
By default, Microsoft®Windows®cursors are 32-by-32 pixels. Since MATLAB pointers must be 16-by-16, you might need to scale your image. If you have Image Processing Toolbox™, you can use theimresize
功能。
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | 没有压缩 | Compression | Output Class |
---|---|---|---|
1位 | ✓ | – | logical |
2位to 8 bit | ✓ | – | uint8. |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Raster Image with colormap | Raster image without colormap | Output Class | 笔记 |
---|---|---|---|---|
8 bit | ✓ | ✓ | uint8. |
|
24位 | – | ✓ | uint8. |
3个样本/像素 |
Seecur - 光标文件
imread
reads any baseline JPEG image, as well as JPEG images with some commonly used extensions. For information on JPEG 2000 file support, seeJPEG 2000.。
Supported Bits per Sample | 有损压缩 | Lossless Compression | Output Class | 笔记 |
---|---|---|---|---|
8 bit | ✓ | ✓ | uint8. |
Grayscale or RGB |
12 bit | ✓ | ✓ | uint16 |
Grayscale or RGB |
16位 | – | ✓ | uint16 |
Grayscale |
有关JPEG文件的信息,请参阅JPEG。
Note
不支持索引JPEG 2000图像。金宝appJP2 / JPX文件仅支持JP2兼容颜色空格。金宝app缺省情况下,所有图像通道都按照它们存储在文件中的顺序返回。
Supported Bits per Sample |
有损压缩 | Lossless Compression | Output Class | 笔记 |
---|---|---|---|---|
1位 | ✓ | ✓ | logical |
Grayscale only |
2位to 8 bit | ✓ | ✓ | uint8. orINT8. |
Grayscale 或RGB. |
9 bit to 16 bit | ✓ | ✓ | uint16 orint16 |
Grayscale 或RGB. |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Raw Binary | ASCII (Plain) Encoded | Output Class |
---|---|---|---|
1位 | ✓ | ✓ | logical |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Output Class | 笔记 |
---|---|---|
1位 | logical |
Grayscale only |
8 bit | uint8. |
灰度或索引 |
24位 | uint8. |
RGB 三个8位样本/像素 |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Raw Binary | ASCII (Plain) Encoded | Output Class | 笔记 |
---|---|---|---|---|
8 bit | ✓ | – | uint8. |
|
16位 | ✓ | – | uint16 |
|
Arbitrary | – | ✓ | 1-bit to 8-bit:uint8. 9-bit to 16-bit: uint16 |
Values are scaled |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Output Class | 笔记 |
---|---|---|
1位 | logical |
Grayscale |
2位 | uint8. |
Grayscale |
4 bit | uint8. |
Grayscale |
8 bit | uint8. |
Grayscale or Indexed |
16位 | uint16 |
Grayscale or Indexed |
24位 | uint8. |
RGB 三个8位样本/像素。 |
48位 | uint16 |
RGB Three 16-bit samples/pixel. |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Raw Binary | ASCII (Plain) Encoded | Output Class |
---|---|---|---|
最多16位 | ✓ | – | uint8. |
Arbitrary | – | ✓ |
This table lists supported bit depths and the data type of the output image data array.
Supported Bit Depths | Output Class | 笔记 |
---|---|---|
1位 | logical |
Bitmap |
8 bit | uint8. |
Indexed |
24位 | uint8. |
RGB 三个8位样本/像素 |
32位 | uint8. |
RGB with Alpha Four 8-bit samples/pixel |
TIFF-based image file format.imread
supports reading uncompressed and compressed images, including images with JPEG2000 compression. For more information, seeTIFF — Tagged Image File Format。
imread
reads most images supported by the TIFF specification or LibTIFF. Theimread
function supports these TIFF capabilities:
Any number of samples per pixel
CCITT group 3 and 4 FAX, Packbits, JPEG, LZW, Deflate, ThunderScan compression, and uncompressed images
Logical, grayscale, indexed color, truecolor and hyperspectral images
RGB, CMYK, CIELAB, ICCLAB color spaces. If the color image uses the CMYK color space,A
是一个m
-by-n
-by-4 array. To determine which color space is used, useimfinfo
to get information about the graphics file and look at the value of thePhotometricInterpretation
field. If a file contains CIELAB color data,imread
converts it to ICCLAB before bringing it into the MATLAB workspace. This conversion is necessary because 8-bit or 16-bit TIFF CIELAB-encoded values use a mixture of signed and unsigned data types that cannot be represented as a single MATLAB array.
Data organized into tiles or scanlines
imread
reads and converts TIFF images as follows:
YCbCr images are converted into the RGB colorspace.
All grayscale images are read as if black =0
, white = largest value.
1-bit images are returned as classlogical
。
16-bit floating-point images are returned as class单
。
CIELab images are converted into ICCLab colorspace.
出于版权信息,打开libtiffcopyright.txt
file.
This table lists the supported bit depths, compression, and output classes for XWD files.
Supported Bit Depths | ZPixmaps | XYBITMAPS. | XYPixmaps | Output Class |
---|---|---|---|---|
1位 | ✓ | – | ✓ | logical |
8 bit | ✓ | – | – | uint8. |
使用说明和限制:
Supports reading of 8-bit JPEG images only. The input argument文档名称
must be a valid absolute path or relative path.
这个函数使用precompil生成代码ed,platform-specific shared library(Image Processing Toolbox)。
使用说明和限制:
Supports reading of 8-bit JPEG images only. The input argument文档名称
must be a valid absolute path or relative path.
这个函数使用precompil生成代码ed,platform-specific shared library(Image Processing Toolbox)。
吓唬
|image
|imfinfo
|imformats.
|IMWRITE.
|ind2rgb
|tiffreadvolume
(Image Processing Toolbox)
A modified version of this example exists on your system. Do you want to open this version instead?
You clicked a link that corresponds to this MATLAB command:
在MATLAB命令窗口中输入它来运行命令。Web浏览器不支持MATLAB命令。金宝app
You can also select a web site from the following list:
选择the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.