Digital
Image Processing
Course Nos. ECE.09.452 and ECE.09.552
Introduction
to the Matlab Image Processing Toolbox
Basics
- A digital image is equivalent to a matrix.
- Displaying an image essentially involves placing a
pixel of the correct color or brightness, depending on the value of the
matrix element, at the correct location, corresponding to the position of
the element in the matrix.
- The matrix-to-display mapping is as shown in this
figure:
- Since the MATLAB Image Processing Toolbox is a complete
color image processing system, for this Digital Image Processing class, we
have to ensure that we use its monochromatic capabilities only.
Types of Images in Matlab
For
this class, will use the following three image types:
- RGB or True-Color Images: There are three
matrices associated with a true-color image of size M x N - the Red
matrix, the Green Matrix and the Blue matrix, each of size M x N.
Typically, each of these matrices contain values between 1 and 256; 1
indicating the least intensity and 256 the highest for each of the colors.
The three matrices are combined into a single M x N x 3 multidimensional
matrix with 3 planes - the R plane, the G plane and the B plane.
- Indexed Images: Although indexed images are used for displaying color
images, we shall use them for displaying gray-level images. There are two
matrices associated with an indexed image of size M x N to be diplayed using G gray levels:
- The image matrix which
contains elements corresponding to the pixel intensities. The elements
take on values from between 1 and infinity.
- The colormap
matrix is G x 3 matrix, with each row containing the Red, Blue and Green
components for each level of intensity. For a monochromatic gray-level
image, this matrix starts with [0 0 0] for black and ends with [1 1 1]
for white. Each row in between contains equal numbers between 0 and 1 for
various shades of gray.
An image matrix element with a value of, say 5, will be
displayed with the graylevel corresponding to the 5th
row of the colormap matrix.
- Intensity Images: These are the actual graylevel
images. There is only one matrix, the image matrix, but the elements of
the matrix must have values between zero and 1 only.
- Binary Images: Again, only one image matrix with elements being 1 or
0.
Importing and
Exporting Image Files
- To import an image into MATLAB:
>> [x,map] = imread('filename.fmt', 'fmt');
where fmt refers to an image file format such as
jpeg, pcx, etc.
Then, matrix [x] will contain the intensity information and matrix [map] the colormap information.
- To export an image matrix [x] and a colormap
matrix [map] in a specified format, use:
>> imwrite(x, map, 'filename.fmt');
- Occasionally, data may be in other formats; I will
provide commands and m-files to read them.
Conversions between
Different Image Types
Displaying
Different Types of Images
- Indexed Images: If [x] is the image
matrix and [map] is the colormap matrix,
>> imshow(x, map);
- Intensity Images: If [x] is the image
matrix and G is the no. of gray levels,
>> imshow(x, G);
- Binary Images: If [x] is the image
matrix,
>> imshow(x, 2);
Pre-Lab
Assignment
- Download a true-color
(RGB) image off the web. Import this image into Matlab
and display it. Save the image to a file; open with any other imaging
software and display it.
>> imread, >> imshow and >> imwrite
commands.
- Convert this image into
a gray-level indexed image and display it. Save the image to a file; open
with any other imaging software and display it.
>> rgb2gray, >> imshow and >>
imwrite commands.
- Convert the indexed image
into an intensity image and display it. Save the image to a file; open
with any other imaging software and display it.
>> mat2gray, >> imshow and >>
imwrite commands.
- Convert the intensity
image into a binary image and display it. Save the image to a file; open
with any other imaging software and display it.
>> im2bw, >> imshow and >>
imwrite commands.
- Generate a 256x256
matrix of numbers; convert this to an intensity image and display it.
Save the image to a file; open with any other imaging software and
display it.
>> mat2gray, >> imshow and >>
imwrite commands.
- Generate a column
profile and a row profile of the intensity image you have downloaded
earlier.
- Convert the indexed
image you have downloaded earlier into an intensity matrix. Save this matrix
in Matlab's native format (.mat file).
Read this file and display image.
>> mat2gray, >> imshow and >>
save and >> load commands.