This is a static copy of a profile report

Home

imread (11550 calls, 128.628 sec)
Generated 05-Nov-2014 07:52:35 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/imagesci/imread.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
tif2imgfunction11361
ml_readimagefunction189
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
438
[X, map] = feval(fmt_s.read, f...
11550107.008 s83.2%
382
[format, fmt_s] = imftype(file...
1155014.320 s11.1%
336
[filename, fmt_s, extraArgs, m...
115503.014 s2.3%
366
fid = fopen(filename, 'r');
115501.863 s1.4%
377
filename = fopen(fid);
115500.350 s0.3%
All other lines  2.073 s1.6%
Totals  128.628 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
imagesci/private/readtiffunction11550106.708 s83.0%
imagesci/private/imftypefunction1155014.160 s11.0%
imread>parse_inputssubfunction115502.574 s2.0%
Self time (built-ins, overhead, etc.)  5.187 s4.0%
Totals  128.628 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function445
Non-code lines (comments, blank lines)376
Code lines (lines that can run)69
Code lines that did run23
Code lines that did not run46
Coverage (did run/can run)33.33 %
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 file
4 % specified by the string FILENAME. If the file is not in the current
5 % directory, or in a directory on the MATLAB path, specify the full
6 % pathname.
7 %
8 % The text string FMT specifies the format of the file by its standard
9 % file extension. For example, specify 'gif' for Graphics Interchange
10 % Format files. To see a list of supported formats, with their file
11 % extensions, use the IMFORMATS function. If IMREAD cannot find a file
12 % named FILENAME, it looks for a file named FILENAME.FMT.
13 %
14 % The return value A is an array containing the image data. If the file
15 % contains a grayscale image, A is an M-by-N array. If the file contains
16 % a truecolor image, A is an M-by-N-by-3 array. For TIFF files containing
17 % color images that use the CMYK color space, A is an M-by-N-by-4 array.
18 % See TIFF in the Format-Specific Information section for more
19 % information.
20 %
21 % The class of A depends on the bits-per-sample of the image data,
22 % rounded to the next byte boundary. For example, IMREAD returns 24-bit
23 % color data as an array of uint8 data because the sample size for each
24 % color component is 8 bits. See the Remarks section for a discussion of
25 % bitdepths, and see the Format-Specific Information section for more
26 % detail about supported bitdepths and sample sizes for a particular
27 % format.
28 %
29 % [X,MAP] = IMREAD(FILENAME,FMT) reads the indexed image in FILENAME into
30 % X and its associated colormap into MAP. Colormap values in the image
31 % file are automatically rescaled into the range [0,1].
32 %
33 % [...] = IMREAD(FILENAME) attempts to infer the format of the file
34 % from its content.
35 %
36 % [...] = IMREAD(URL,...) reads the image from an Internet URL. The
37 % URL must include the protocol type (e.g., "http://").
38 %
39 % Remarks
40 %
41 % Bitdepth is the number of bits used to represent each image pixel.
42 % Bitdepth is calculated by multiplying the bits-per-sample with the
43 % samples-per-pixel. Thus, a format that uses 8-bits for each color
44 % component (or sample) and three samples per pixel has a bitdepth of 24.
45 % Sometimes the sample size associated with a bitdepth can be ambiguous:
46 % does a 48-bit bitdepth represent six 8-bit samples or three 16-bit
47 % samples? The following format-specific sections provide sample size
48 % information to avoid this ambiguity.
49 %
50 % Format-Specific Information (Listed Alphabetically by Format)
51 %
52 % BMP -- Windows Bitmap
53 %
54 % Supported Compression Output
55 % Bitdepths None RLE Class Notes
56 % ---------------------------------------------------------
57 % 1-bit x - logical
58 % 4-bit x x uint8
59 % 8-bit x x uint8
60 % 16-bit x - uint8 1 sample/pixel
61 % 24-bit x - uint8 3 samples/pixel
62 % 32-bit x - uint8 3 samples/pixel (1 byte padding)
63 %
64 % CUR -- Cursor File
65 %
66 % Supported Compression Output
67 % Bitdepths None Compressed Class
68 % --------------------------------------------------
69 % 1-bit x - logical
70 % 4-bit x - uint8
71 % 8-bit x - uint8
72 %
73 % Special syntaxes:
74 %
75 % [...] = IMREAD(...,IDX) reads in one image from a multi-image icon or
76 % cursor file. IDX is an integer value that specifies the order that the
77 % image appears in the file. For example, if IDX is 3, IMREAD reads the
78 % third image in the file. If you omit this argument, IMREAD reads the
79 % first image in the file.
80 %
81 % [A,MAP,ALPHA] = IMREAD(...) returns the AND mask for the resource,
82 % which can be used to determine transparency information. For cursor
83 % files, this mask may contain the only useful data.
84 %
85 % GIF -- Graphics Interchange Format
86 %
87 % Supported Compression Output
88 % Bitdepths None Compressed Class
89 % ---------------------------------------------
90 % 1-bit x - logical
91 % 2-to-8 bit x - uint8
92 %
93 % Special syntaxes:
94 %
95 % [...] = IMREAD(...,IDX) reads in one or more frames from a multiframe
96 % (i.e., animated) GIF file. IDX must be an integer scalar or vector of
97 % integer values. For example, if IDX is 3, IMREAD reads the third image
98 % in the file. If IDX is 1:5, only the first five frames are returned.
99 %
100 % [...] = IMREAD(...,'Frames',IDX) is the same as the syntax above except
101 % that IDX can be 'all'. In this case, all of the frames are read and
102 % returned in the order that they appear in the file.
103 %
104 % Note: Because of the way GIF files are structured, all of the frames
105 % must be read when a particular frame is requested. Consequently, it is
106 % much faster to specify a vector of frames or 'all' for IDX than to call
107 % IMREAD in a loop when reading multiple frames from the same GIF file.
108 %
109 % HDF -- Hierarchical Data Format
110 %
111 % Supported Raster image Raster image Output
112 % Bitdepths with colormap without colormap Class Notes
113 % ------------------------------------------------------------
114 % 8-bit x x uint8
115 % 24-bit - x uint8 3 samples/pixel
116 %
117 % Special Syntaxes:
118 %
119 % [...] = IMREAD(...,REF) reads in one image from a multi-image HDF file.
120 % REF is an integer value that specifies the reference number used to
121 % identify the image. For example, if REF is 12, IMREAD reads the image
122 % whose reference number is 12. (Note that in an HDF file the reference
123 % numbers do not necessarily correspond with the order of the images in
124 % the file. You can use IMFINFO to match up image order with reference
125 % number.) If you omit this argument, IMREAD reads the first image in
126 % the file.
127 %
128 % ICO -- Icon File
129 %
130 % See CUR.
131 %
132 % JPEG -- Joint Photographic Experts Group
133 %
134 % Note: IMREAD can read any baseline JPEG image as well as JPEG images
135 % with some commonly used extensions.
136 %
137 % Supported Compression Output
138 % Bitdepths Lossy Lossless Class Notes
139 % --------------------------------------------------------
140 % 8-bit x x uint8 Grayscale or RGB
141 % 12-bit x x uint16 Grayscale
142 % 16-bit - x uint16 Grayscale
143 % 36-bit x x uint16 RGB(Three 12-bit samples/pixel)
144 %
145 % JPEG 2000 - Joint Photographic Experts Group 2000
146 %
147 % Supported Compression Output
148 % Bitdepths Lossy Lossless Class
149 % (per sample)
150 % ----------------------------------------------------------
151 % 1-bit x x logical
152 % 2- to 8-bit x x uint8
153 % 9- to 16-bit x x uint16
154 %
155 % Note: Indexed JPEG 2000 images are not supported. Only JP2 compatible
156 % color spaces are supported for JP2/JPX files. Arbitrary channels are
157 % supported for raw codestream J2C files.
158 %
159 % Special Syntaxes
160 %
161 % [...] = IMREAD(..., 'Param1', value1, 'Param2', value2, ...) uses
162 % parameter-value pairs to control the read operation.
163 %
164 % Parameter name Value
165 % -------------- -----
166 % 'ReductionLevel' A non-negative integer specifying reduction in
167 % the resolution of the image. For a reduction
168 % level 'L', the image resolution is reduced by a
169 % factor of 2^L. Its default value is 0 implying
170 % no reduction. The reduction level is limited by
171 % the total number of decomposition levels as
172 % provided by 'WaveletDecompositionLevels' field
173 % in the structure returned from IMFINFO function.
174 %
175 % 'PixelRegion' {ROWS, COLS}. IMREAD returns the sub-image
176 % specified by the boundaries in ROWS and COLS.
177 % ROWS and COLS must both be two-element vectors
178 % that denote the 1-based indices [START STOP]. If
179 % 'ReductionLevel' is greater than 0, then ROWS and
180 % COLS are coordinates in the reduced-sized image.
181 %
182 % 'V79Compatible' A BOOL value. If true, image returned is color
183 % converted to gray-scale or RGB image as consistent
184 % with previous versions of IMREAD (MATLAB 7.9
185 % [R2009b] and earlier). Otherwise raw color
186 % image is returned. Default is false.
187 %
188 %
189 % PBM -- Portable Bitmap
190 %
191 % Supported Raw ASCII (Plain) Output
192 % Bitdepths Binary Encoded Class
193 % ----------------------------------------
194 % 1-bit x x logical
195 %
196 % PCX -- Windows Paintbrush
197 %
198 % Supported Output
199 % Bitdepths Class Notes
200 % ----------------------------------------------
201 % 1-bit logical Grayscale only
202 % 8-bit uint8 Grayscale or indexed
203 % 24-bit uint8 RGB (8-bit samples)
204 %
205 % PGM -- Portable Graymap
206 %
207 % Supported Raw ASCII (Plain) Output
208 % Bitdepths Binary Encoded Class
209 % ------------------------------------------------
210 % up to 16-bit x - uint8
211 % Arbitrary - x
212 %
213 % PNG -- Portable Network Graphics
214 %
215 % Supported Output
216 % Bitdepths Class Notes
217 % -------------------------------------------
218 % 1-bit logical Grayscale only
219 % 2-bit uint8 Grayscale only
220 % 4-bit uint8 Grayscale only
221 % 8-bit uint8 Grayscale or Indexed
222 % 16-bit uint16 Grayscale or Indexed
223 % 24-bit uint8 RGB (Three 8-bit samples/pixel)
224 % 48-bit uint16 RGB (Three 16-bit samples/pixel)
225 %
226 % Special Syntaxes:
227 %
228 % [...] = IMREAD(...,'BackgroundColor',BG) composites any transparent
229 % pixels in the input image against the color specified in BG. If BG is
230 % 'none', then no compositing is performed. Otherwise, if the input image
231 % is indexed, BG should be an integer in the range [1,P] where P is the
232 % colormap length. If the input image is grayscale, BG should be an
233 % integer in the range [0,1]. If the input image is RGB, BG should be a
234 % three-element vector whose values are in the range [0,1]. The string
235 % 'BackgroundColor' may be abbreviated.
236 %
237 % If the ALPHA output argument is used (see below), then BG defaults to
238 % 'none' if not specified by the user. Otherwise, if the PNG file
239 % ontains a background color chunk, that color is used as the default
240 % value for BG. If ALPHA is not used and the file does not contain a
241 % background color chunk, then the default value for BG is 1 for indexed
242 % images; 0 for grayscale images; and [0 0 0] for RGB images.
243 %
244 % [A,MAP,ALPHA] = IMREAD(...) returns the alpha channel if one is
245 % present; otherwise ALPHA is []. If 'BackgroundColor' is specified by
246 % the user then ALPHA is []. Note that MAP may be empty if the file
247 % contains a grayscale or truecolor image.
248 %
249 % PPM -- Portable Pixmap
250 %
251 % Supported Raw ASCII (Plain) Output
252 % Bitdepths Binary Encoded Class
253 % ------------------------------------------------
254 % up to 16-bit x - uint8
255 % Arbitrary - x
256 %
257 % RAS -- Sun Raster
258 %
259 % Supported Output
260 % Bitdepths Class Notes
261 % ----------------------------------------------------
262 % 1-bit logical Bitmap
263 % 8-bit uint8 Indexed
264 % 24-bit uint8 RGB (8-bit samples)
265 % 32-bit uint8 RGB with Alpha (8-bit samples)
266 %
267 % TIFF -- Tagged Image File Format
268 %
269 % Supported Compression Output
270 % Bitdepths None Packbits CCITT RGB ICCLAB CIELAB CMYK Class Notes
271 % -----------------------------------------------------------------------
272 % 1-bit x x x - - - - logical
273 % 8-bit x x - - - - - uint8
274 % 12-bit - - - - - - - uint16 Grayscale
275 % or Indexed
276 % 16-bit - - - - - - - uint16 Grayscale
277 % or Indexed
278 % 24-bit x x - x x x - uint8 3 samples
279 % 32-bit - - - - - - x uint8 4 samples
280 % 36-bit - - - x - - - uint16 3 samples
281 % 48-bit - - - x x x - uint16 3 samples
282 % 64-bit - - - - - - x double 4 samples
283 %
284 % NOTE: IMREAD supports 8-bit integral and 32-bit floating point tiled
285 % TIFF images, with any compression and colorspace combination listed
286 % above, and 32-bit IEEE floating point images.
287 %
288 % Special Syntaxes:
289 %
290 % A = IMREAD(...) returns color data that uses the RGB, CIELAB, ICCLAB,
291 % or CMYK color spaces. If the color image uses the CMYK color space, A
292 % is an M-by-N-by-4 array.
293 %
294 % [...] = IMREAD(..., 'Param1', value1, 'Param2', value2, ...) uses
295 % parameter-value pairs to control the read operation. There are three
296 % different parameters you can use:
297 %
298 % Parameter name Value
299 % -------------- -----
300 % 'Index' A positive integer specifying which image to read in
301 % a multi-image TIFF file. For example, if 'Index' is
302 % 3, IMREAD reads the third image in the file.
303 %
304 % 'Info' A structure array; the output of IMFINFO. When
305 % reading images from a multi-image TIFF file, passing
306 % the output of IMFINFO as the 'Info' parameter helps
307 % IMREAD locate the images in the file more quickly.
308 %
309 % 'PixelRegion' {ROWS, COLS}. IMREAD returns the sub-image
310 % specified by the boundaries in ROWS and COLS. ROWS
311 % and COLS must be either two- or three-element
312 % vectors. If two elements are provided, they denote
313 % the 1-based indices [START STOP]. If three elements
314 % are provided, the indices [START INCREMENT STOP]
315 % allow image downsampling.
316 %
317 % XWD -- X Window Dump
318 %
319 % Supported Output
320 % Bitdepths ZPixmaps XYBitmaps XYPixmaps Class
321 % --------------------------------------------------
322 % 1-bit x - x logical
323 % 8-bit x - - uint8
324 %
325 % Please read the file libtiffcopyright.txt for more information.
326 %
327 % Example:
328 %
329 % imdata = imread('ngc6543a.jpg');
330 %
331 % See also IMFINFO, IMWRITE, IMFORMATS, FREAD, IMAGE, DOUBLE, UINT8.
332
333 % Copyright 1984-2008 The MathWorks, Inc.
334 % $Revision: 1.1.6.21 $ $Date: 2011/05/17 02:25:06 $
335
3.01 11550 336 [filename, fmt_s, extraArgs, msg] = parse_inputs(varargin{:});
0.09 11550 337 if (~isempty(msg))
338 error(message('MATLAB:imagesci:imread:inputParsing', msg));
339 end
340
341 % Download remote file.
0.18 11550 342 if (strfind(filename, '://'))
343
344 url = true;
345
346 if (~usejava('jvm'))
347 error(message('MATLAB:imagesci:imread:noJava'))
348 end
349
350 try
351 filename = urlwrite(filename, tempname);
352 catch %#ok<*CTCH>
353 error(message('MATLAB:imagesci:imread:readURL', filename));
354 end
355
0.07 11550 356 else
357
0.08 11550 358 url = false;
359
0.02 11550 360 end
361
0.04 11550 362 if (isempty(fmt_s))
363 % The format was not specified explicitly.
364
365 % Verify that the file exists.
1.86 11550 366 fid = fopen(filename, 'r');
0.07 11550 367 if (fid == -1)
368
369 if ~isempty(dir(filename))
370 error(message('MATLAB:imagesci:imread:fileReadPermission', filename));
371 else
372 error(message('MATLAB:imagesci:imread:fileDoesNotExist', filename));
373 end
374
0.03 11550 375 else
376 % File exists. Get full filename.
0.35 11550 377 filename = fopen(fid);
0.19 11550 378 fclose(fid);
0.04 11550 379 end
380
381 % Try to determine the file type.
14.32 11550 382 [format, fmt_s] = imftype(filename);
383
0.18 11550 384 if (isempty(format))
385 error(message('MATLAB:imagesci:imread:fileFormat'));
386 end
387
388 else
389 % The format was specified explicitly.
390
391 % Verify that the file exists.
392 fid = fopen(filename, 'r');
393 if (fid == -1)
394 % Couldn't open using the given filename; search for a
395 % file with an appropriate extension.
396 for p = 1:length(fmt_s.ext)
397 fid = fopen([filename '.' fmt_s.ext{p}]);
398
399 if (fid ~= -1)
400 % The file was found. Don't continue searching.
401 break
402 end
403 end
404 end
405
406 if (fid == -1)
407 if ~isempty(dir(filename))
408 error(message('MATLAB:imagesci:imread:fileReadPermission', filename));
409 else
410 error(message('MATLAB:imagesci:imread:fileDoesNotExist', filename));
411 end
412 else
413 filename = fopen(fid);
414 fclose(fid);
415 end
416
417 end
418
0.19 11550 419 if isempty(fmt_s)
420 % Get format details.
421 fmt_s = imformats(format);
422 end
423
424 % Verify that a read function exists
0.07 11550 425 if (isempty(fmt_s.read))
426 error(message('MATLAB:imagesci:imread:readFunctionRegistration', fmt_s.ext{ 1 }));
427 end
428
0.07 11550 429 if ((fmt_s.alpha) && (nargout == 3))
430
431 % Use the alpha channel.
432 [X, map, alpha] = feval(fmt_s.read, filename, extraArgs{:});
433
0.04 11550 434 else
435
436 % Alpha channel is not requested or is not applicable.
0.06 11550 437 alpha = [];
107.01 11550 438 [X, map] = feval(fmt_s.read, filename, extraArgs{:});
439
0.04 11550 440 end
441
442 % Delete temporary file from Internet download.
0.04 11550 443 if (url)
444 delete_download(filename);
445 end

Other subfunctions in this file are not included in this listing.