Sie sind auf Seite 1von 16

MATLAB for Image Processing

MATLAB Image Processing Toolbox


Built on the computation and function capabilities of MATLAB and the Signal Processing Toolbox. Can read/write image data in a variety of formats. Provides functions for image transforms, filtering, enhancement, image registration, deblurring, feature extraction, etc. Expandable, by adding own functions. Command-line oriented, but adding new GUIs to access tools is possible.

CRD Labs

Cybernetics Research & Development

Color images
Color is critical to human understanding, but has not been widely used, until recently, for IP tasks. Colors, and more generally, multi-spectral images, contain more information than monochromatic images. Four prominent color models: RGB, CMY, YIQ, HIS/HSV The chromatic spectrum varies from 400nm to 700nm, and humans detect primary colors red (700 nm), green (546.1 nm) and blue (435.8 nm). Most display use this RGB model. (0,0,0) = black, (kkk) = white, (k,0,0) = red. Here k is the maximum value the quantization levels can take on, e.g., 256. Thus, for 24 bit color we can represent 2^24 colors.

CRD Labs

Cybernetics Research & Development

CMY Model
Based on secondary colors Realizes a subtractive color scheme. Yellow results when the blue is subtracted from white Red is realized when yellow and magenta are removed from white. This approach is used for hard copy devices.

CRD Labs

Cybernetics Research & Development

YIQ Model
Simple linear transform of RGB:
Y 0.299 0.587 0.114 R I 0.596 0.275 0.321 G Q 0.212 0.523 0.311 B Used in TV broadcasting Y component provides information for monochrome display. Exploits human visual system, since we are particularly sensitive to luminance.
CRD Labs

Cybernetics Research & Development

HIS Model
Most relevant to IP is Hue, Saturation, and Intensity (HIS) model Hue = perceived color which is approximately the dominant wavelength Saturation = dilution of color by white light

CRD Labs

Cybernetics Research & Development

MATLAB Image Types


Indexed Images Intensity Images Binary Images RGB Images Multiframe Image Arrays Image data in MATLAB can be logical, double, uint8, uint16

CRD Labs

Cybernetics Research & Development

Indexed Images

Consists of a data matrix, I and a colormap matrix, C C is an m-by-3 matrix, with each row specifying the R, G, and B components of a single color. Values in C are floating point numbers in the range [0, 1] Color of each pixel is determined by using the corresponding value of I as an index into the colormap R G B
1
1 10

0 1

0 0

1 2

0.5

0.5

0.5

10

Image Example:. >> [x, map] = imread('forest.tif'); >> imshow(x, map) CRD Labs
Cybernetics Research & Development

Map

0.35

0.25 m

Intensity Images

Consists of a data matrix, I, whose values represent intensities within some range.
For double-precision data, the intensity values are in the range [0, 1], where 0 represents black, and 1 represents white.

Use the following to display intensity images. >> imagesc(I, [0, 1]); colormap(gray);
The second input argument [0, 1] to imagesc specifies the desired intensity range. I is displayed by first mapping the first value in the range to the first colormap entry, and second value in the range to the last colormap entry. Values in between are mapped linearly. To use another colormap, use the following >> colormap(hot); To automatically map the min value in I to the first colormap entry, and the max value in I to the last colormap entry, do the following. >> imagesc(I); colormap(gray);

CRD Labs

Cybernetics Research & Development

Truecolor Images (RGB Images)


I(:, :, 1) is the red component of the image I(:, :, 2) is the green component of the image I(:, :, 3) is the blue component of the image

10

Consist of a m-by-n-by-3 data array, I, containing the R, G, and B components for each individual pixel
HumVee(:, :, 3)

To display a truecolor image, do the following >> imshow(I)


HumVee(:, :, 2)

HumVee(:, :, 1)

CRD Labs

Cybernetics Research & Development

A colormap is an m-by-3 matrix of real numbers between 0.0 and 1.0


Each row is an RGB vector that defines one color
>> load flujet >> figure;imagesc(X); >> figure;imagesc(X);colormap gray

Colormap

CRD Labs

Cybernetics Research & Development

Reading Images
BMP, HDF, JPEG, PCX, TIFF, XWD

12

MATLAB can read images of various formats including Use function imread to read image files
imread reads indexed, intensity, and truecolor images Images are read into a uint8 matrix of appropriate size

imread automatically determines the format of the image based on information in the header
You can specify a format as an optional second argument

>> Crusader = imread(Crusader.jpg'); >> image(Crusader)

CRD Labs

Cybernetics Research & Development

Writing Images

13

MATLAB can write images of various formats including the following BMP, HDF, JPEG, PCX, TIFF, PNG, PNM Use function imwrite to write image files imwrite determines the format from extension of filename
You can specify an optional format if extension is absent or to force a particular format

Use imfinfo(filename) to get information on an image file

>> Abrams = imread(Abrams.jpg'); >> image(Abrams) >> whos Abrams Name Size Bytes Class Abrams 511x640x3 981120 uint8 array Grand total is 981120 elements using 981120 bytes >> AbramsGray = rgb2gray(Abrams); >> colormap gray; >> image(AbramsGray) >> imwrite(AbramsGray, 'Abrams.bmp');

CRD Labs

Cybernetics Research & Development

Summary
imread Used to read images imwrite Write matrices to specified image format imshow/image Display images imfinfo Retrieve information about image colormap Set/change colormap used for displaying image

CRD Labs

Cybernetics Research & Development

More on image display


Use subimage to display multiple images in the same figure.

>> >> >> >>

a = imread(kids.jpg); b = imread('SCHOT_CENTER.JPG') subplot(121); subimage(a); subplot(122); subimage(b);

Use colorbar to add a colorbar to the image.. >> imshow(F,[-1 5]); >> colormap(jet),colorbar

CRD Labs

Cybernetics Research & Development

Image Arithmetic
Standard MATLAB arithmetic operators are defined for double data. The IP toolbox provides a set of functions to do arithmetic on other data types.

CRD Labs

Cybernetics Research & Development

Das könnte Ihnen auch gefallen