Digital Image Processing –DIP- LAB 2
Objective: Introduction to image processing functions in Matlab.
Fundamentals:
A digital image is composed of pixels which can be thought of as small dots on the
screen. A digital image is an instruction of how to color each pixel.
Image Processing Toolbox:
Overview
The Image Processing Toolbox provides a comprehensive set of reference-standard
algorithms and graphical tools for image processing, analysis, visualization, and
algorithm development. You can restore noisy or degraded images, enhance images for
improved intelligibility, extract features, analyze shapes and textures, and register two
images. Most toolbox functions are written in the open MATLAB® language. This
means that you can inspect the algorithms, modify the source code, and create your own
custom functions.
The Image Processing Toolbox supports engineers and scientists in areas such as
biometrics, remote sensing, surveillance, gene expression, microscopy, semiconductor
testing, image sensor design, color science, and materials science. It also facilitates the
learning and teaching of image processing techniques.
Key Features:
Image enhancement, including linear and nonlinear filtering, filter design, deblurring, and
automatic contrast enhancement Image analysis, including texture analysis, line detection, morphology, edge detection, segmentation, region-of-interest (ROI) processing, and feature measurement Color image processing, including color space conversions and device-independent ICC profile import and export Spatial transformations and image registration, including a graphical tool for control-point selection Image transforms, including FFT, DCT, Radon, and fan-beam projection
DICOM import and export Interactive image display and modular tools for building image GUIs Support for multidimensional image processing
Image formats supported by Matlab
The following image formats are supported by Matlab:
• BMP
• HDF
• JPEG
• PCX
• TIFF
• XWB
Working formats in Matlab
Intensity image (gray scale image)
This is the equivalent to a “gray scale image”. It represents an image as a matrix where
every element has a value corresponding to how bright/dark the pixel at the
corresponding position should be colored. There are two ways to represent the number
that represents the brightness of the pixel: The double class (or data type). This assigns a
floating number (“a number with decimals”) between 0 and 1 to each pixel. The value 0
corresponds to black and the value 1 corresponds to white. The other class is called uint8
which assigns an integer between 0 and 255 to represent the brightness of a pixel. The
value 0 corresponds to black and 255 to white. The class uint8 only requires roughly 1/8
of the storage compared to the class double. On the other hand, many mathematical
functions can only be applied to the double class.
Binary image
This image format also stores an image as a matrix but can only color a pixel black or
white (and nothing in between). It assigns a 0 for black and a 1 for white.
Indexed image
This is a practical way of representing color images. An indexed image stores an image
as two matrices. The first matrix has the same size as the image and one number for each
pixel. The second matrix is called the color map and its size may be different from the
image. The numbers in the first matrix is an instruction of what number to use in the
color map matrix.
RGB image
This is another format for color images. It represents an image with three matrices of
sizes matching the image format. Each matrix corresponds to one of the colors red, green
or blue and gives an instruction of how much of each of these colors a certain pixel
should use.
Conversion between different formats
The following table shows how to convert between the different formats.
Image format conversion
(Within the parenthesis type the name of the image you wish to
convert.)
Operation:
Matlab
command:
Convert between intensity/indexed/RGB formats to binary format. dither()
Convert between intensity formats to indexed format. gray2ind()
Convert between indexed formats to intensity format. ind2gray()
Convert between indexed formats to RGB format. Ind2rgb()
Convert a regular matrix to intensity format by scaling. Mat2gray()
Convert between RGB formats to intensity format. Rgb2gray()
Convert between RGB formats to indexed format. Rgb2ind()
Reading Image files
Operation:
Matlab
command:
Read an image.
(Within the parenthesis type the name of the image file you wish to read.
Put the file name within single quotes ‘ ‘.)
imread()
Write an image to a file.
(As the first argument within the parenthesis type the name of the image
you have worked with.
As a second argument within the parenthesis type the name of the file
and format to write the image to.
Put the file name within single quotes ‘ ‘.)
imwrite( , )
Displaying an image in Matlab
Here are a couple of basic Matlab commands (do not require any tool box) for displaying
an image.
Displaying an image given on matrix form
Operation: Matlab command:
Display an image represented as the matrix X. imagesc(X)
Adjust the brightness. S is a parameter such that
-1<s<0 gives a darker image, 0<s<1 gives a brighter image.
brighten(s)
Change the colors to gray. colormap(gray)
Displaying an image given on matrix form (with image processing
tool box)
Operation:
Matlab
command:
Display an image represented as the matrix X. imshow(X)
Zoom in (using the left and right mouse button). zoom on
Turn off the zoom function. zoom off