www.gusucode.com > images 案例代码 matlab源码程序 > images/ReadImageDataIntoTheWorkspaceExample.m

    %% Read Image Data into the Workspace
% This example shows to read image data from a graphics file into the
% MATLAB workspace using the |imread| function.
%%
% Read a truecolor image into the workspace. The example reads the image
% data from a graphics file that uses JPEG format. 

% Copyright 2015 The MathWorks, Inc.

RGB = imread('football.jpg');
%%
% If the image file format uses 8-bit pixels, |imread| returns the image
% data as an m-by-n-by-3 array of |uint8| values. For graphics file formats
% that support 16-bit data, such as PNG and TIFF, |imread| returns an array
% of |uint16| values.
whos
%%
% Read a grayscale image into the workspace. The example reads the image
% data from a graphics file that uses the TIFF format. |imread| returns the
% grayscale image as an m-by-n array of |uint8| values.
I = imread('cameraman.tif');
whos
%%
% Read an indexed image into the workspace. |imread| uses two variables to
% store an indexed image in the workspace: one for the image and another
% for its associated colormap. |imread| always reads the colormap into a
% matrix of class |double|, even though the image array itself may be of
% class |uint8| or |uint16|.
[X,map] = imread('trees.tif');
whos
%%
% In these examples, |imread| infers the file format to use from the
% contents of the file. You can also specify the file format as an argument
% to |imread|. |imread| supports many common graphics file formats, such as
% the Graphics Interchange Format (GIF), Joint Photographic Experts Group
% (JPEG), Portable Network Graphics (PNG), and Tagged Image File Format
% (TIFF) formats. For the latest information concerning the bit depths
% and image formats supported, see |imread| and |imformats| reference
% pages.
pep = imread('peppers.png','png');
whos