matlab imread函数全说明
imread
Read image from graphics file
Syntax
A = imread(filename, fmt)
[X, map] = imread(...)
[...] = imread(filename)
[...] = imread(URL,...)
[...] = imread(...,Param1,Val1,Param2,Val2...)
Description
A = imread(filename, fmt) reads a grayscale or color image from the file specified by the string filename. If the file is not in the current folder, or in a folder on the MATLAB path, specify the full pathname.
The text string fmt specifies the format of the file by its standard file extension. For example, specify 'gif' for Graphics Interchange Format files. To see a list of supported formats, with their file extensions, use the imformats function. If imread cannot
find a file named filename, it looks for a file named filename.fmt.
The return value A is an array containing the image data. If the file contains a grayscale image, A is an M-by-N array. If the file contains a truecolor image, A is an M-by-N-by-3 array. For TIFF files containing color images that use the CMYK color space,
A is an M-by-N-by-4 array. See TIFF in the Format-Specific Information section for more information.
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. See Tips for a discussion
of bitdepths, and see Format-Specific Information for more detail about supported bitdepths 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].
[...] = 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://).
[...] = imread(...,Param1,Val1,Param2,Val2...) specifies parameters that control various characteristics of the operations for specific formats. For more information, see Format-Specific Information.
Tips
Bitdepth is the number of bits used to represent each image pixel. Bitdepth 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 bitdepth
of 24. Sometimes the sample size associated with a bitdepth can be ambiguous: does a 48-bit bitdepth represent six 8-bit samples, four 12-bit samples, or three 16-bit samples? The following format-specific sections provide sample size information to avoid
this ambiguity.
Format-Specific Information
The following sections provide information about the support for specific formats, listed in alphabetical order by format name. These sections include information about format-specific syntaxes, if they exist. BMP — Windows BitmapJPEG — Joint Photographic Experts
GroupPNG — Portable Network GraphicsCUR — Cursor FileJPEG 2000 — Joint Photographic Experts Group 2000PPM — Portable PixmapGIF — Graphics Interchange FormatPBM — Portable BitmapRAS — Sun RasterHDF4 — Hierarchical Data FormatPCX — Windows PaintbrushTIFF — Tagged
Image File FormatICO — Icon FilePGM — Portable GraymapXWD — X Window Dump
BMP — Windows Bitmap
Supported BitdepthsNo CompressionRLE CompressionOutput ClassNotes1-bity–logical 4-bityyuint8 8-bityyuint8 16-bity–uint81 sample/pixel24-bity–uint83 samples/pixel32-bity–uint83 samples/pixel
(1 byte padding)
CUR — Cursor File
Supported BitdepthsNo CompressionCompressionOutput Class1-bity–logical4-bity–uint88-bity–uint8
Format-specific syntaxes:
[...] = imread(..., idx) reads in one image from a multi-image icon or cursor file. idx is an integer value that specifies the order that the image appears in the file. For example, if idx is 3, imread reads the third image in the file. If you omit this argument,
imread reads the first image in the file.
[A, map, alpha] = imread(...) returns the AND mask for the resource, which can be used to determine the transparency information. For cursor files, this mask may contain the only useful data.
Note By default, Microsoft Windows cursors are 32-by-32 pixels. MATLAB pointers must be 16-by-16. You will probably need to scale your image. If you have Image Processing Toolbox™, you can use its imresize function.
GIF — Graphics Interchange Format
Supported BitdepthsNo CompressionCompressionOutput Class1-bity–logical2-bit to 8-bity–uint8
Format-specific syntaxes:
[...] = imread(..., idx) reads in one or more frames from a multiframe (i.e., animated) GIF file. idx must be an integer scalar or vector of integer values. For example, if idx is 3, imread reads the third image in the file. If idx is 1:5, imread returns only
the first five frames.
[...] = imread(..., 'frames', idx) is the same as the syntax above except that idx can be 'all'. In this case, all the frames are read and returned in the order that they appear in the file.
Note Because of the way that GIF files are structured, all the frames must be read when a particular frame is requested. Consequently, it is much faster to specify a vector of frames or 'all' for idx than to call imread in a loop when reading multiple frames
from the same GIF file.
HDF4 — Hierarchical Data Format
Supported BitdepthsRaster Image with colormapRaster image without colormapOutput ClassNotes8-bityyuint8 24-bit–yuint83 samples/pixel
Format-specific syntaxes:
[...] = imread(..., ref) reads in one image from a multi-image HDF4 file. ref is an integer value that specifies the reference number used to identify the image. For example, if ref is 12, imread reads the image whose reference number is 12. (Note that in an
HDF4 file the reference numbers do not necessarily correspond to the order of the images in the file. You can use imfinfo to match image order with reference number.) If you omit this argument, imread reads the first image in the file.
ICO — Icon File
See CUR — Cursor File
JPEG — Joint Photographic Experts Group
imread can read any baseline JPEG image as well as JPEG images with some commonly used extensions. For information about support for JPEG 2000 files, see JPEG 2000.Supported Bitdepths
(Bits-per-sample)Lossy CompressionLossless CompressionOutput ClassNotes8-bityyuint8Grayscale or RGB12-bityyuint16Grayscale or RGB16-bit–yuint16Grayscale
JPEG 2000 — Joint Photographic Experts Group 2000
For information about JPEG files, see JPEG.
Note Only 1- and 3-sample images are supported. Indexed JPEG 2000 images are not supported.
Supported Bitdepths (Bits-per-sample)Lossy CompressionLossless CompressionOutput ClassNotes1-bityylogicalGrayscale only2- to 8-bityyuint8Grayscale
or RGB9- to 16-bityyuint16Grayscale
or RGB
Format-specific syntaxes:
[...] = imread(..., 'Param1', value1, 'Param2', value2, ...) uses parameter-value pairs to control the read operation, described in the following table.ParameterValue'ReductionLevel'A non-negative integer specifying the reduction in the resolution of the image.
For a reduction level L, the image resolution is reduced by a factor of 2^L. Its default value is 0 implying no reduction. The reduction level is limited by the total number of decomposition levels as specified by the'WaveletDecompositionLevels' field in the
structure returned by the imfinfo function.'PixelRegion'{ROWS, COLS} — The imread function returns the sub-image specified by the boundaries in ROWS and COLS. ROWS and COLS must both be two-element vectors that denote the 1-based indices [START STOP]. If 'ReductionLevel'
is greater than 0, then ROWS and COLS are coordinates in the reduced-sized image.
PBM — Portable Bitmap
Supported BitdepthsRaw BinaryASCII (Plain) EncodedOutput Class1-bityylogical
PCX — Windows Paintbrush
Supported BitdepthsOutput ClassNotes1-bitlogicalGrayscale only8-bituint8Grayscale or indexed24-bituint8RGB
Three 8-bit samples/pixel
PGM — Portable Graymap
Supported BitdepthsRaw BinaryASCII (Plain) EncodedOutput ClassNotes8-bity–uint8 16-bity–uint16 Arbitrary–y1-bit to 8-bit: uint8
9-bit to 16-bit: uint16Values are scaled
PNG — Portable Network Graphics
Supported BitdepthsOutput ClassNotes1-bitlogicalGrayscale2-bituint8Grayscale4-bituint8Grayscale8-bituint8Grayscale or Indexed16-bituint16Grayscale or Indexed24-bituint8RGB
Three 8-bit samples/pixel.48-bituint16RGB
Three 16-bit samples/pixel.
Format-specific syntaxes:
[...] = imread(...,'BackgroundColor',BG) composites any transparent pixels in the input image against the color specified in BG. If BG is 'none', then no compositing is performed. If the input image is indexed, BG must be an integer in the range [1,P] where
P is the colormap length. If the input image is grayscale, BG should be an integer in the range [0,1]. If the input image is RGB, BG should be a three-element vector whose values are in the range [0,1]. The string 'BackgroundColor' may be abbreviated.
[A, map, alpha] = imread(...) returns the alpha channel if one is present; otherwise alpha is []. Note that map may be empty if the file contains a grayscale or truecolor image.
If you specify thealpha output argument, BG defaults to 'none', if not specified. Otherwise, if the PNG file contains a background color chunk, that color is used as the default value for BG. If alpha is not used and the file does not contain a background color
chunk, then the default value for BG is 1 for indexed images; 0 for grayscale images; and [0 0 0] for truecolor (RGB) images.
PPM — Portable Pixmap
Supported BitdepthsRaw BinaryASCII (Plain) EncodedOutput ClassUp to 16-bity–uint8Arbitrary–y
RAS — Sun Raster
The following table lists the supported bitdepths, compression, and output classes for RAS files.Supported BitdepthsOutput ClassNotes1-bitlogicalBitmap8-bituint8Indexed24-bituint8RGB
Three 8-bit samples/pixel32-bituint8RGB with Alpha
Four 8-bit samples/pixel
TIFF — Tagged Image File Format
imread supports the following 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 is an M-by-N-by-4 array. To determine which color space is used, use imfinfo to get information about the graphics file and look at the value of the PhotometricInterpretation
field. If a file contains CIELAB color data, imread converts it to ICCLAB before bringing it into the MATLAB workspace because 8- 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
The following table lists the supported bit/sample and corresponding output classes for TIFF files.Supported BitdepthsCompressionOutput Class Notes NonePackbitsCCITTRGBICCLABCIELABCMYK 1-bityyy----logical 8-bityy-----uint8 12-bit-------uint16Grayscale or Indexed16-bit-------uint16Grayscale
or Indexed24-bityy-yyy-uint83 samples32-bit------yuint84 samples36-bit---y---uint163 samples48-bit---yyy-uint163 samples64-bit------ydouble4 samples
Note imread supports 8-bit integral and 32-bit floating point tiled TIFF images, with any compression and color space combination listed above, and 32-bit IEEE floating point images.
The following are format-specific syntaxes for TIFF files.
A = imread(...) returns color data that uses the RGB, CIELAB, ICCLAB, or CMYK color spaces. If the color image uses the CMYK color space, A is an M-by-N-by-4 array.
[...] = imread(..., 'Param1', value1, 'Param2', value2, ...) uses parameter/value pairs to control the read operation. The following table lists the parameters you can use.ParameterValue'Index'Positive integer specifying which image to read. For example, if
you specify the value 3, imread reads the third image in the file. If you omit this argument, imread reads the first image in the file.'Info'
Structure array returned by imfinfo.
Note: When reading images from a multi-image TIFF file, passing the output of imfinfo as the value of the 'Info' argument helps imread locate the images in the file more quickly.'PixelRegion'Cell array, {Rows, Cols}, specifying the boundaries of the region.
Rows and Cols must be either two- or three-element vectors. If you specify two elements, the values denote the 1-based indices [start stop]. If you specify three elements, the values denote the 1-based indices [start increment stop], to allow image downsampling.
For copyright information, see the libtiffcopyright.txt file.
XWD — X Window Dump
The following table lists the supported bitdepths, compression, and output classes for XWD files.Supported BitdepthsZPixmapsXYBitmapsXYPixmapsOutput Class1-bity–ylogical8-bity––uint8
Class Support
For most image file formats, imread uses 8 or fewer bits per color plane to store image pixels. The following table lists the class of the returned array for the data types used by the file formats.
Data Type Used in File
Class of Array Returned by imread
1-bit per pixel
logical
2- to 8-bits per color plane
uint8
9- to 16-bit per pixel
uint16 (BMP, JPEG, PNG, and TIFF)
For the 16-bit BMP packed format (5-6-5), MATLAB returns uint8
Note For indexed images, imread always reads the colormap into an array of class double, even though the image array itself may be of class uint8 or uint16.
Examples
Read sample image.
imdata = imread('ngc6543a.jpg');
Read indexed image and convert it to an RGB image.
[cdata,map] = imread( filename )
if ~isempty( map )
cdata = ind2rgb( cdata, map );
end
Read sixth image in a TIFF file.
[X,map] = imread('your_image.tif',6);
Read fourth image in an HDF4 file.
info = imfinfo('your_hdf_file.hdf');
[X,map] = imread('your_hdf_file.hdf',info(4).Reference);
Read a 24-bit PNG image and set any of its fully transparent (alpha channel) pixels to red.
bg = [1 0 0];
A = imread('your_image.png','BackgroundColor',bg);
Return the alpha channel (if any) of a PNG image.
[A,map,alpha] = imread('your_image.png');
Read an ICO image, apply a transparency mask, and then display the image.
[a,b,c] = imread('your_icon.ico');
% Augment colormap for background color (white).
b2 = [b; 1 1 1];
% Create new image for display.
d = ones(size(a)) * (length(b2) - 1);
% Use the AND mask to mix the background and
% foreground data on the new image
d(c == 0) = a(c == 0);
% Display new image
image(uint8(d)), colormap(b2)
matlab imread函数全说明的更多相关文章
- 【原创】Matlab中plot函数全功能解析
[原创]Matlab中plot函数全功能解析 该帖由Matlab技术论(http://www.matlabsky.com)坛原创,更多精彩内容参见http://www.matlabsky.com 功能 ...
- Matlab中plot函数全功能解析
Matlab中plot函数全功能解析 功能 二维曲线绘图 语法 plot(Y)plot(X1,Y1,...)plot(X1,Y1,LineSpec,...)plot(...,'PropertyName ...
- Matlab中imread函数使用报错“不应为MATLAB 表达式”分析
问题描述: 使用imread读取特定路径下的文件时,会提示出错! >> mytest错误: 文件:mytest.m 行:10 列:87不应为 MATLAB 表达式. 出错行: Images ...
- opencv学习之读取图像-imread函数
序 想要完整全面地学习opencv,仅凭阅读samples的示例源码是不够的.毕竟opencv是一个拥有非常多函数的程序库,所以在每学习一个函数时,芒果觉得有必要记录下来,分享给有需要的同学.于是,就 ...
- MyEclipse调用Matlab打包函数
本文部分内容参考了http://www.360doc.com/content/15/1103/16/1180274_510463048.shtml 一.检查Java环境 对于已经装上JAVA环境的计算 ...
- Matlab中函数定义方法
Matlab自定义函数的六种方法 n1.函数文件+调用函数(命令)文件:需单独定义一个自定义函数的M文件: n2.函数文件+子函数:定义一个具有多个自定义函数的M文件: n3.Inline:无需M文件 ...
- Matlab图像处理函数:regionprops
本篇文章为转载,仅为方便学术讨论所用,不用于商业用途.由于时间较久,原作者以及原始链接暂时无法找到,如有侵权以及其他任何事宜欢迎跟我联系,如有侵扰,在此提前表示歉意.----------------- ...
- imread函数、namedWindow函数、imshow函数、imwrite函数
1.imread函数 首先,我们看imread函数,可以在OpenCV官方文档中查到其原型如下: Mat imread(const string& filename, int flags=1 ...
- 向量和矩阵的范数及MATLAB调用函数
范数就是长度的一种推广形式,数学语言叫一种度量.比如有一个平面向量,有两个分量来描述:横坐标和纵坐标.向量的二范数就是欧几里得意义下的这个向量的长度.还有一些诸如极大值范数,就是横坐标或者纵坐标的最大 ...
随机推荐
- jaxb读有BOM的XML文件问题
一开始找了半天没找到什么原因,读文件就报错: Content is not allowed in prolog 后来发现是文件是UTF-8带BOM和不带BOM的问题 问题就好解决了,直接读带BOM文件 ...
- Django框架下数据存储实现时间戳格式存储到数据库2019-12-11 17:53:13
2019-12-11 17:53:13 models.py class DomainDir(models.Model): date = models.DateTimeField() views.py ...
- Java8-Lock-No.01
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- Maratona Brasileira de Popcorn( 二分答案+暴力 )
题意:输入三个数n,c,t . 桌子上有n堆爆米花,每一堆有ai个, 现在有c个人一起吃爆米花,每人每分钟最多能吃t个爆米花,但有两个规定:1.一堆爆米花只能一个人吃, 2.每个人只能吃连续的若干堆爆 ...
- 【算法进阶-康托展开】-C++
目录 引入 这位老爷子就是康托 基本概念 康托展开是一个全排列到一个自然数的双射,常用于构建hash表时的空间压缩.设有n个数(1,2,3,4,-,n),可以有组成不同(n!种)的排列组合,康托展开表 ...
- CF768F Barrels and boxes
嘟嘟嘟 此题不难. 这种题做几道就知道些套路了:我们枚举酒有几堆,这样就能算出食物有多少堆以及他们的排列数,那么概率就是合法方案数 / 总方案数. 设酒有\(i\)堆,那么就有\(C_{w - 1} ...
- Bzoj 1588: [HNOI2002]营业额统计(splay)
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Description 营业额统计 Tiger最近被公司升任为营业部经理,他上 ...
- 网络1911、1912 C语言第4次作业--函数批改总结
目录 网络1911.1912 C语言第4次作业--函数批改总结 一.评分规则 二.本次作业亮点 三.本次作业存在的问题 四.助教有话说 五.得分详情 网络1911.1912 C语言第4次作业--函数批 ...
- vue后台_登录权限
登录权限控制包含着这么几个方面的含义: 1)不同的权限对应不同的路由 2)侧边栏需要根据不同的权限,异步生成 登录:使用用户名和密码,登录成功后返回用户的token(防止XSS攻击),将此token存 ...