24-01-2013, 01:01 PM
Image Processing with MATLAB
Image Processing.pdf (Size: 721.95 KB / Downloads: 23)
Introduction
MATLAB is being used as a platform for laboratory exercises and the problems classes in the Image
Processing half of the Computer Graphics and Image Processing course unit. This handout describes
the MATLAB development environment you will be using, you are expected to have read it and be
familiar with it before attempting the Laboratory and Coursework Assignments.
MATLAB is a data analysis and visualisation tool designed to make matrix manipulation as simple as
possible. In addition, it has powerful graphics capabilities and its own programming language. The
basic MATLAB distribution can be expanded by adding a range of toolboxes, the one relevant to this
course is the image-processing toolbox (IPT). The basic distribution and all of the currently available
toolboxes are available in the labs. The basic distribution plus any installed toolboxes will provide a
large selection of functions, invoked via a command line interface.
MATLAB’s basic data structure is the matrix1. In MATLAB a single variable is a 1 x 1 matrix, a string
is a 1 x n matrix of chars. An image is a n x m matrix of pixels. Pixels are explained in more detail
below. Matrix operations are discussed in the appendix.
The handout summarises how the image processing operations discussed in lectures may be achieved in
MATLAB, it summarises the MATLAB programming environment. Further help is available online,
by either clicking on the “Help” menu item, or typing helpbrowser at the command prompt.
MATLAB’s Development Environment
MATLAB is started from within the Windows environment by clicking the icon that should be on the
desktop. (MATLAB is also available for Linux and MacOS, but these environments are not supported
in the laboratories, and these versions have their own licensing arrangements which are not covered by
the University’s licence.)
MATLAB’s IDE has five components: the Command Window, the Workspace Browser, the Current
Directory Window, the Command History Window and zero or more Figure Windows that are active
only to display graphical objects.
The Command window is where commands and expressions are typed, and results are presented as
appropriate.
The workspace is the set of variables that have been created during a session. They are displayed in the
Workspace Browser. Additional information about a variable is available there, some variables can also
be edited.
The current directory window displays the contents of the current working directory and the paths of
previous working directories. The working directory may be altered. MATLAB uses a search path to
find files. The search path includes the current directory, all of the installed toolboxes plus any other
paths that the user has added – via the Set Path dialogue accessed from the File menu.
The command history window gives a historical view of the current and previous sessions. Commands
appearing here can be reexecuted.
Image Format
An image is a rectangular array of values (pixels). Each pixel represents the measurement of some
property of a scene measured over a finite area. The property could be many things, but we usually
measure either the average brightness (one value) or the brightnesses of the image filtered through red,
green and blue filters (three values). The values are normally represented by an eight bit integer, giving
a range of 256 levels of brightness.
We talk about the resolution of an image: this is defined by the number of pixels and number of
brightness values.
A raw image will take up a lot of storage space. Methods have been defined to compress the image by
coding redundant data in a more efficient fashion, or by discarding the perceptually less significant
information. MATLAB supports reading all of the common image formats. Image coding is not
addressed in this course unit.
Number of Pixels
Images come in all sizes, but are (almost) always rectangular. MATLAB gives several methods of
accessing the elements of an array, i.e. the pixels of an image.
An element can be accessed directly: typing the array name at the prompt will return all the array
elements (which could take a while), typing the array name followed by element indices in round
brackets, will return that value.
Colour Transforms
Multiple methods of representing colour data exist. Whilst RGB is most widely used for capture and
display, it is not always the best for image processing, since it is a perceptually non-uniform
representation. This means that if we change the RGB values by a fixed amount, the observed
difference depends on the original RGB values. One way of observing this is to mix the output of
standardised coloured lights to generate a colour, then alter the brightness of the input until an observer
just notices a change in the light’s colour. The original colour and the colour of the just noticeable
difference can be plotted. By making measurements systematically over the whole colour space, we can
generate a MacAdam diagram. The points represent the original colour, the ellipses the just noticeable
difference contours.
Interpolation
It would seem natural to take a pixel in the input image and compute its location in the distorted image.
But, the values of the affine transform parameters, or the distortion equations are generally non-integer.
So the computed co-ordinates may be non-integer. Rounding errors can result in some output pixels not
being populated. Therefore, the distortion is performed in reverse. We use the inverse of the
transformation to compute the source of each pixel in the distorted image. The source pixel may well
have non-integer co-ordinates, but we can estimate its value by taking the nearest pixel, or interpolating
over the nearest pixels.