Computer and Information Engineering dept.
Digital Images Processing
4 Class
th
Dr. Majid
Dhirar
For a practical example of using matrices, we will now look at and
manipulate multidimensional data in the form of images. Monitor
screens and images are inherently matrices with rows and columns,
where each element (pixel) can be addressed by a particular row and
column index.
MATLAB stores most images as two-dimensional arrays
(i.e., matrices), in which each element of the matrix
corresponds to a single pixel in the displayed image.
When we get to images, we are still working with matrices
that can be accessed through indices. The upper left-hand
corner of the image is indexed by (1,1). The general format
of indexing is (row, col) or (y,x).
Color Format (Type of data stored in the image array or matrix).
Images can be represented in several color spaces.
• Binary:- 0 is black and 1 is white.
• Gray Scale:- Values between 0 and 255 are shades of gray.
• True Color (RGB) or (CMYK):-
RGB can be thought of as 3-layers of intensity representing
red, green, and blue components.
The extra dimension is the color
component.
255 represents the
highest intensity, and 0
represents the lowest
intensity. For instance,
to make a pure red,
red would be 255,
green would be 0, and
blue would be 0.
A wide range of colors can be created
by the primary colors of pigment
(Cyan(C), Magenta (M), Yellow(Y), and Black(K)).
Those colors then define a specific color space.
To create a three-dimensional representation of a
color space, we can assign the amount of magenta
color to the representation's X axis, the amount of
cyan to its Y axis, and the amount of yellow to its Z
axis. The resulting 3-D space provides a unique
position for every possible color that can be
created by combining those three pigments.
HSV
Another way of making
the same colors is to
use their Hue (X axis),
their Saturation(Y axis), and their
brightness Value (Z axis). This is called the
HSV color space. Many color spaces can be
represented as three-dimensional (X,Y,Z)
values in this manner, but some have more,
or fewer dimensions, and some, such as
Pantone, cannot be represented in this way
at all.
Images File Format
In MatLab, we can load a large number of image file types,
including .jpg (Jay beg), .bmp( Bitmap), .gif( Graphic
interchange format), .png (Portable Network Graphic).
Examples
(‘autumn.tif’)
('football.jpg')
('coins.png')
Images Data Types
Images are represented with a specific kind of data type,
which allows for non-negative, full integer intensity values
between 0 and 255. The corresponding data type is named
uint8 (unsigned integer with 8 bit representation).
The use of different data types requires a facility for
conversion, which are available with the following type
conversion functions:
uint8(x) converts matrix x to uint8 data type (0-255)
double(x) converts matrix x to double data type
logical(x) converts matrix x to logical data type (0s and 1s)
Reading and Displaying Images
If we want to modify or enhance one of these
pictures, we should store it in a temporary array by
using imread.
>> I=imread(‘onion.png’)
To then view the image in I
>> imshow(I)
>> imtool(I)
>> i = imread(‘football.jpg');
subplot(2,2,1), image(football), title('Tasty Pomegranate Seeds (RGB)');
subplot(2,2,2), imshow(football(:,:,1)), title('Intensity Image: Red Layer');
subplot(2,2,3), imshow(football(:,:,2)), title('Intensity Image: Green Layer');
subplot(2,2,4), imshow(football(:,:,3)), title('Intensity Image: Blue Layer');
Converting Between Different Formats
rgb2gray() Convert from RGB format to intensity format.
img=imread('onion.png');
imshow('onion.png')
%Convert to grayscale
img_gray=rgb2gray(img);
imshow(img_gray)
Saving Images
When saving a binary, grayscale or truecolor image, all you need to
specify are the matrix and filename. For example:
imwrite(img_bin, 'onion_bw.png')