Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pmi432 / LR07 / 2read / image processing toolbox guide.pdf
Скачиваний:
166
Добавлен:
18.03.2015
Размер:
18.08 Mб
Скачать

3 Reading and Writing Image Data

Getting Information About a Graphics File

To obtain information about a graphics file and its contents, use the imfinfo function. You can use imfinfo with any of the formats supported by MATLAB. Use the imformats function to determine which formats are supported.

Note You can also get information about an image displayed in the

Image Tool — see “Getting Information About an Image Using the Image

Information Tool” on page 4-40.

The information returned by imfinfo depends on the file format, but it always includes at least the following:

Name of the file

File format

Version number of the file format

File modification date

File size in bytes

Image width in pixels

Image height in pixels

Number of bits per pixel

Image type: truecolor (RGB), grayscale (intensity), or indexed

3-2

Reading Image Data

Reading Image Data

To import an image from any supported graphics image file format, in any of the supported bit depths, use the imread function. This example reads a truecolor image into the MATLAB workspace as the variable RGB.

RGB = imread('football.jpg');

If the image file format uses 8-bit pixels, imread stores the data in the workspace as a uint8 array. For file formats that support 16-bit data, such as PNG and TIFF, imread creates a uint16 array.

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');

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 Microsoft® Windows® Bitmap (BMP), 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/or image formats supported, see imread and imformats.

If the graphics file contains multiple images, imread imports only the first image from the file. To import additional images, you must use imread with format-specific arguments to specify the image you want to import. In this example, imread imports a series of 27 images from a TIFF file and stores the images in a four-dimensional array. You can use imfinfo to determine how many images are stored in the file.

mri = zeros([128 128 1 27],'uint8'); % preallocate 4-D array

for frame=1:27

[mri(:,:,:,frame),map] = imread('mri.tif',frame); end

3-3

3 Reading and Writing Image Data

When a file contains multiple images that are related in some way, you can call image processing algorithms directly. For more information, see “Working with Image Sequences” on page 2-21.

If you are working with a large file, you may want to try block processing to reduce memory usage. For more information, see “Neighborhood or Block Processing: An Overview” on page 15-2.

3-4

Соседние файлы в папке 2read