This is a static copy of a profile reportHome
imread (1 call, 0.109 sec)
Generated 15-Mar-2007 12:01:55 using real time.
M-function in file C:\Program Files\MATLAB71\toolbox\matlab\imagesci\imread.m
[Copy to new window for comparing multiple runs]
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
307 | [X, map] = feval(fmt_s.read, f... | 1 | 0.078 s | 71.4% |  |
243 | format = imftype(filename); | 1 | 0.031 s | 28.6% |  |
306 | alpha = []; | 1 | 0.000 s | 0.0% |  |
216 | url = false; | 1 | 0.000 s | 0.0% |  |
303 | else | 1 | 0.000 s | 0.0% |  |
Other lines & overhead | | | 0 s | 0% |  |
Totals | | | 0.109 s | 100% | |
Children (called functions)
M-Lint results
No M-Lint messages.Coverage results
[ Show coverage for parent directory ]
Total lines in file | 320 |
Non-code lines (comments, blank lines) | 249 |
Code lines (lines that can run) | 71 |
Code lines that did run | 23 |
Code lines that did not run | 48 |
Coverage (did run/can run) | 32.39 % |
Function listing
time calls line
1 function [X, map, alpha] = imread(varargin)
2 %IMREAD Read image from graphics file.
3 % A = IMREAD(FILENAME,FMT) reads a grayscale or color image from the
4 % file specified by the string FILENAME, where the string FMT specifies
5 % the format of the file. See the reference page, or the output of the
6 % function IMFORMATS, for a list of supported formats. If the file is
7 % not in the current directory or in a directory in the MATLAB path,
8 % specify the full pathname of the location on your system. If IMREAD
9 % cannot find a file named FILENAME, it looks for a file named
10 % FILENAME.FMT.
11 %
12 % IMREAD returns the image data in the array A. If the file contains a
13 % grayscale image, A is a two-dimensional (M-by-N) array. If the file
14 % contains a color image, A is a three-dimensional (M-by-N-by-3)
15 % array. The class of the returned array depends on the data type used
16 % by the file format.
17 %
18 % For most file formats, the color image data returned uses the RGB
19 % color space. For TIFF files, however, IMREAD can return color data
20 % that uses the RGB, CIELAB, ICCLAB, or CMYK color spaces. If the
21 % color image uses the CMYK color space, A is an M-by-N-by-4 array.
22 % See the reference page for more information about reading TIFF files
23 % that use these color spaces.
24 %
25 % [X,MAP] = IMREAD(FILENAME,FMT) reads the indexed image in FILENAME
26 % into X and its associated colormap into MAP. Colormap values in the
27 % image file are automatically rescaled into the range [0,1].
28 %
29 % [...] = IMREAD(FILENAME) attempts to infer the format of the file
30 % from its content.
31 %
32 % [...] = IMREAD(URL,...) reads the image from an Internet URL. The
33 % URL must include the protocol type (e.g., "http://").
34 %
35 % Data types
36 % ----------
37 % In most of the image file formats supported by IMREAD,
38 % pixels are stored using 8 or fewer bits per color plane.
39 % If the file contains only 1 bit per pixel, the class of the
40 % output (A or X) is logical. When reading other files with
41 % 8 or fewer bits per color plane, the class of the output
42 % is uint8. IMREAD also supports reading 16-bit-per-pixel
43 % data from BMP, PNG, JPEG, and TIFF files, as well as 12-bit
44 % JPEG and TIFF files. For 12-bit JPEG and TIFF and 16-bit
45 % JPEG, PNG, and TIFF image files, the class of the output (A
46 % or X) is uint16 and for 16-bit BMP image files, the class of
47 % the output is uint8.
48 %
49 % TIFF-specific syntaxes
50 % ----------------------
51 % [...] = IMREAD(...,IDX) reads in one image from a
52 % multi-image TIFF file. IDX is an integer value that
53 % specifies the order that the image appears in the file.
54 % For example, if IDX is 3, IMREAD reads the third image in
55 % the file. If you omit this argument, IMREAD reads the
56 % first image in the file.
57 %
58 % [...] = IMREAD(...,'PixelRegion',{ROWS, COLS}) returns the sub-image
59 % specified by the boundaries in ROWS and COLS. In the case of tiled
60 % TIFF images, IMREAD will read only the appropriate tiles, improving
61 % memory efficiency and performance. ROWS and COLS must be either two
62 % or three element vectors. If two elements are provided, they denote
63 % the 1-based indices [START STOP]. If three elements are provided,
64 % the indices [START INCREMENT STOP] allow image downsampling.
65 %
66 % PNG-specific syntaxes
67 % ---------------------
68 % [...] = IMREAD(...,'BackgroundColor',BG) composites any
69 % transparent pixels in the input image against the color
70 % specified in BG. If BG is 'none', then no compositing is
71 % performed. Otherwise, if the input image is indexed, BG
72 % should be an integer in the range [1,P] where P is the
73 % colormap length. If the input image is grayscale, BG
74 % should be an integer in the range [0,1]. If the input
75 % image is RGB, BG should be a three-element vector whose
76 % values are in the range [0,1]. The string
77 % 'BackgroundColor' may be abbreviated.
78 %
79 % If the ALPHA output argument is used (see below), then BG
80 % defaults to 'none' if not specified by the
81 % user. Otherwise, if the PNG file contains a background
82 % color chunk, that color is used as the default value for
83 % BG. If ALPHA is not used and the file does not contain a
84 % background color chunk, then the default value for BG is 1
85 % for indexed images; 0 for grayscale images; and [0 0 0]
86 % for RGB images.
87 %
88 % [A,MAP,ALPHA] = IMREAD(...) returns the alpha channel if
89 % one is present; otherwise ALPHA is []. Note that MAP may
90 % be empty if the file contains a grayscale or truecolor
91 % image.
92 %
93 % HDF-specific syntaxes
94 % ---------------------
95 % [...] = IMREAD(...,REF) reads in one image from a
96 % multi-image HDF file. REF is an integer value that
97 % specifies the reference number used to identify the image.
98 % For example, if REF is 12, IMREAD reads the image whose
99 % reference number is 12. (Note that in an HDF file the
100 % reference numbers do not necessarily correspond with the
101 % order of the images in the file. You can use IMFINFO to
102 % match up image order with reference number.) If you omit
103 % this argument, IMREAD reads the first image in the file.
104 %
105 % ICO- and CUR-specific syntaxes
106 % ------------------------------
107 % [...] = IMREAD(...,IDX) reads in one image from a
108 % multi-image icon or cursor file. IDX is an integer value
109 % that specifies the order that the image appears in the file.
110 % For example, if IDX is 3, IMREAD reads the third image in
111 % the file. If you omit this argument, IMREAD reads the
112 % first image in the file.
113 %
114 % [A,MAP,ALPHA] = IMREAD(...) returns the AND mask for the
115 % resource, which can be used to determine the transparency
116 % information. For cursor files, this mask may contain the
117 % only useful data.
118 %
119 % GIF-specific syntaxes
120 % ---------------------
121 % [...] = IMREAD(...,IDX) reads in one or more frames from a
122 % multiframe (i.e., animated) GIF file. IDX must be an integer
123 % scalar or vector of integer values. For example, if IDX is 3,
124 % IMREAD reads the third image in the file. If IDX is 1:5, only
125 % the first five frames will be returned.
126 %
127 % [...] = IMREAD(...,'Frames',IDX) is the same as the syntax
128 % above except that IDX can be 'all'. In this case, all of the
129 % frames are read and returned in the order that they appear in
130 % the file.
131 %
132 % Note: Because of the way that GIF files are structured, all of
133 % the frames must be read when a particular frame is requested.
134 % Consequently, it is much faster to specify a vector of frames
135 % or 'all' for IDX than to call IMREAD in a loop when reading
136 % multiple frames from the same GIF file.
137 %
138 % Supported file types
139 % --------------------
140 % JPEG Any baseline JPEG image; JPEG images with some
141 % commonly used extensions; 8-bit and 12-bit lossy
142 % compressed RGB and grayscale images; 8-bit and 12-bit
143 % lossless compressed RGB images; 8-bit, 12-bit, and
144 % 16-bit lossless compressed grayscale images
145 %
146 % TIFF Any baseline TIFF image, including 1-bit, 8-bit, and
147 % 24-bit uncompressed images; 1-bit, 8-bit, and 24-bit
148 % images with packbits compression; 1-bit images with
149 % CCITT compression; 12-bit grayscale, 12-bit indexed,
150 % and 36-bit RGB images; 16-bit grayscale, 16-bit indexed,
151 % and 48-bit RGB images; 24-bit and 48-bit ICCLAB and
152 % CIELAB images; 32-bit and 64-bit CMYK images; and 8-bit
153 % tiled TIFF images with any compression and colorspace
154 % combination listed above.
155 %
156 % GIF Any 1-bit to 8-bit GIF image
157 %
158 % BMP 1-bit, 4-bit, 8-bit, 16-bit, 24-bit, and 32-bit uncompressed
159 % images; 4-bit and 8-bit run-length encoded (RLE) images
160 %
161 % PNG Any PNG image, including 1-bit, 2-bit, 4-bit, 8-bit,
162 % and 16-bit grayscale images; 8-bit and 16-bit
163 % indexed images; 24-bit and 48-bit RGB images
164 %
165 % HDF 8-bit raster image datasets, with or without an
166 % associated colormap; 24-bit raster image datasets
167 %
168 % PCX 1-bit, 8-bit, and 24-bit images
169 %
170 % XWD 1-bit and 8-bit ZPixmaps; XYBitmaps; 1-bit XYPixmaps
171 %
172 % ICO 1-bit, 4-bit, and 8-bit uncompressed images
173 %
174 % CUR 1-bit, 4-bit, and 8-bit uncompressed images
175 %
176 % RAS Any RAS image, including 1-bit bitmap, 8-bit indexed,
177 % 24-bit truecolor and 32-bit truecolor with alpha.
178 %
179 % PBM Any 1-bit PBM image. Raw (binary) or ASCII (plain) encoded.
180 %
181 % PGM Any standard PGM image. ASCII (plain) encoded with
182 % arbitrary color depth. Raw (binary) encoded with up
183 % to 16 bits per gray value.
184 %
185 % PPM Any standard PPM image. ASCII (plain) encoded with
186 % arbitrary color depth. Raw (binary) encoded with up
187 % to 16 bits per color component.
188 %
189 % See also IMFINFO, IMWRITE, IMFORMATS, FREAD, IMAGE, DOUBLE, UINT8.
190
191 % Copyright 1984-2004 The MathWorks, Inc.
192 % $Revision: 1.1.6.5 $ $Date: 2005/06/20 03:12:39 $
193
1 194 [filename, format, extraArgs, msg] = parse_inputs(varargin{:});
1 195 if (~isempty(msg))
196 error('MATLAB:imread:inputParsing', '%s', msg);
197 end
198
199 % Download remote file.
1 200 if (strfind(filename, '://'))
201
202 url = true;
203
204 if (~usejava('mwt'))
205 error('MATLAB:imread:noJava', 'Reading from a URL requires a Java Virtual Machine.')
206 end
207
208 try
209 filename = urlwrite(filename, tempname);
210 catch
211 error('MATLAB:imread:readURL', 'Can''t read URL "%s".', filename);
212 end
213
< 0.01 1 214 else
215
< 0.01 1 216 url = false;
217
1 218 end
219
220
1 221 if (isempty(format))
222 % The format was not specified explicitly.
223
224 % Verify that the file exists.
1 225 fid = fopen(filename, 'r');
1 226 if (fid == -1)
227
228 if ~isempty(dir(filename))
229 error('MATLAB:imread:fileOpen', ['Can''t open file "%s" for reading;\nyou' ...
230 ' may not have read permission.'], ...
231 filename);
232 else
233 error('MATLAB:imread:fileOpen', 'File "%s" does not exist.', filename);
234 end
235
1 236 else
237 % File exists. Get full filename.
1 238 filename = fopen(fid);
1 239 fclose(fid);
1 240 end
241
242 % Try to determine the file type.
0.03 1 243 format = imftype(filename);
244
1 245 if (isempty(format))
246 error('MATLAB:imread:fileFormat', 'Unable to determine the file format.');
247 end
248
249 else
250 % The format was specified explicitly.
251
252 % Verify that the file exists.
253 fid = fopen(filename, 'r');
254 if (fid == -1)
255 % Couldn't open using the given filename; search for a
256 % file with an appropriate extension.
257 fmt_s = imformats(format);
258
259 if (isempty(fmt_s))
260 error('MATLAB:imread:fileFormat', ['Couldn''t find format %s in the format registry.' ...
261 ' See "help imformats".'], format);
262 end
263
264 for p = 1:length(fmt_s.ext)
265 fid = fopen([filename '.' fmt_s.ext{p}]);
266
267 if (fid ~= -1)
268 % The file was found. Don't continue searching.
269 break
270 end
271 end
272 end
273
274 if (fid == -1)
275 if ~isempty(dir(filename))
276 error('MATLAB:imread:fileOpen', ['Can''t open file "%s" for reading;\nyou' ...
277 ' may not have read permission.'], ...
278 filename);
279 else
280 error('MATLAB:imread:fileOpen', 'File "%s" does not exist.', filename);
281 end
282 else
283 filename = fopen(fid);
284 fclose(fid);
285 end
286
287 end
288
289 % Get format details.
1 290 fmt_s = imformats(format);
291
292 % Verify that a read function exists
1 293 if (isempty(fmt_s.read))
294 error('MATLAB:imread:readFunctionRegistration', 'No reading function for format %s. See "help imformats".', ...
295 fmt_s.ext{1});
296 end
297
1 298 if ((fmt_s.alpha) && (nargout == 3))
299
300 % Use the alpha channel.
301 [X, map, alpha] = feval(fmt_s.read, filename, extraArgs{:});
302
< 0.01 1 303 else
304
305 % Alpha channel is not requested or is not applicable.
< 0.01 1 306 alpha = [];
0.08 1 307 [X, map] = feval(fmt_s.read, filename, extraArgs{:});
308
1 309 end
310
311 % Delete temporary file from Internet download.
1 312 if (url)
313 delete_download(filename);
314 end
315
316
317
318 %%%
319 %%% Function delete_download
320 %%%
Other subfunctions in this file are not included in this listing.