| MATLAB® | ![]() |
| On this page… |
|---|
If you have a file in a standard graphics format, use the imfinfo function to get information about its contents. The imfinfo function returns a structure containing information about the file. The fields in the structure vary with the file format, but imfinfo always returns some basic information including filename, last modification date, file size, and format.
This example returns information about a file in Joint Photographic Experts Group (JPEG) format:
info = imfinfo('ngc6543a.jpg')
info =
Filename: [1x57 char]
FileModDate: '01-Oct-1996 16:19:44'
FileSize: 27387
Format: 'jpg'
FormatVersion: ''
Width: 600
Height: 650
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {[1x69 char]}
To import data into the MATLAB® workspace from a graphics file, use the imread function. Using this function, you can import data from files in many standard file formats, including the Tagged Image File Format (TIFF), Graphics Interchange Format (GIF), Joint Photographic Experts Group (JPEG), and Portable Network Graphics (PNG) formats. For a complete list of supported formats, see the imread reference page.
This example reads the image data stored in a file in JPEG format into the MATLAB workspace as the array I:
I = imread('ngc6543a.jpg');
imread represents the image in the workspace as a multidimensional array of class uint8. The dimensions of the array depend on the format of the data. For example, imread uses three dimensions to represent RGB color images:
whos I Name Size Bytes Class I 650x600x3 1170000 uint8 array Grand total is 1170000 elements using 1170000 bytes
To export data from the MATLAB workspace using one of the standard graphics file formats, use the imwrite function. Using this function, you can export data in formats such as the Tagged Image File Format (TIFF), Joint Photographic Experts Group (JPEG), and Portable Network Graphics (PNG). For a complete list of supported formats, see the imwrite reference page.
The following example writes a multidimensional array of uint8 data I from the MATLAB workspace into a file in TIFF format. The class of the output image written to the file depends on the format specified. For most formats, if the input array is of class uint8, imwrite outputs the data as 8-bit values. See the imwrite reference page for details.
whos I Name Size Bytes Class I 650x600x3 1170000 uint8 array Grand total is 1170000 elements using 1170000 bytes imwrite(I, 'my_graphics_file.tif','tif');
Note imwrite supports different syntaxes for several of the standard formats. For example, with TIFF file format, you can specify the type of compression MATLAB uses to store the image. See the imwrite reference page for details. |
![]() | Exporting Text Data | Working with Audio and Video Data | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |