MATLAB Functions | Help Desk |
imread
Read image from graphics file
A = imread(filename,fmt) [X,map] = imread(filename,fmt) [...] = imread(filename) [...] = imread(...,idx) (TIFF only) [...] = imread(...,ref) (HDF only)
A = imread(filename,fmt)
reads the image in filename
into A
, whose class is uint8
. If the file contains a grayscale intensity image, A
is a two-dimensional array. If the file contains a truecolor (RGB) image, A
is a three-dimensional (m
-by-n
-by-3) array. filename
is a string that specifies the name of the graphics file, and fmt
is a string that specifies the format of the file. The file must be in the current directory or in a directory in the MATLAB path. If imread
cannot find a file named filename
, it looks for a file named filename.fmt
.
This table lists the possible values for fmt
:
|
---|
[X,map] = imread(filename,fmt)
reads the indexed image in filename
into X
and its associated colormap into map
. X
is of class uint8
, and map
is of class double
. The colormap values are rescaled to the range [0, 1].
[...] = imread(filename)
attempts to infer the format of the file from its content.
[...] = imread(...,idx)
reads in one image from a multi-image TIFF file. idx
is an integer value that specifies the order in which 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.
[...] = imread(...,ref)
reads in one image from a multi-image HDF 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 HDF file the reference numbers do not necessarily correspond to the order of the images in the file.) If you omit this argument, imread
reads the first image in the file.
This table summarizes the types of images that imread
can read:[X,map] = imread('flowers.tif',6);This example reads the fourth image in an HDF file:
info = imfinfo('skull.hdf'); [X,map] = imread('skull.hdf',info(4).Reference);
imfinfo
Return information about a graphics file
imwrite
Write an image to a graphics file