Image Processing Reference
In-Depth Information
actually works: you can compare the results of your final application code with those of the
original mathematical description. If your final application code and the Mathcad
implementation are both correct, the results should be the same. Naturally, your application
code will be much faster than in Mathcad, and will benefit from the GUI you've developed.
1.5.3
Hello Matlab!
Matlab is rather different from Mathcad. It is not a WYSIWYG system but instead it is
more screen-based. It was originally developed for matrix functions, hence the 'Mat' in the
name. Like Mathcad, it offers a set of mathematical tools and visualisation capabilities in
a manner arranged to be very similar to conventional computer programs. In some users'
views, a WYSIWYG system like Mathcad is easier to start with but there are a number of
advantages to Matlab, not least the potential speed advantage in computation and the
facility for debugging, together with a considerable amount of established support. Again,
there is an image processing toolkit supporting Matlab, but it is rather limited compared
with the range of techniques exposed in this text. The current version is Matlab 5.3.1, but
these systems evolve fast!
Essentially, Matlab is the set of instructions that process the data stored in a workspace,
which can be extended by user-written commands. The workspace stores the different lists
of data and these data can be stored in a MAT file; the user-written commands are functions
that are stored in M-files (files with extension .M). The procedure operates by instructions
at the command line to process the workspace data using either one of Matlab's own
commands, or using your own commands. The results can be visualised as graphs, surfaces
or as images, as in Mathcad.
The system runs on Unix/Linux or Windows and on Macintosh systems. A student
version is available at low cost. There is no viewer available for Matlab, you have to have
access to a system for which it is installed. As the system is not based around worksheets,
we shall use a script which is the simplest type of M-file, as illustrated in Code 1.6 . To start
the Matlab system, type MATLAB at the command line. At the Matlab prompt (>>) type
chapter1 to load and run the script (given that the file chapter1.m is saved in the
directory you are working in). Here, we can see that there are no text boxes and so
comments are preceded by a %. The first command is one that allocates data to our variable
pic . There is a more sophisticated way to input this in the Matlab system, but that is not
available here. The points are addressed in row-column format and the origin is at co-
ordinates y = 1 and x = 1. So we then access these point pic 3,3 as the third column of the
third row and pic 4,3 is the point in the third column of the fourth row. Having set the
display facility to black and white, we can view the array pic as a surface. When the
surface, illustrated in Figure 1.16 (a), is plotted, then Matlab has been made to pause until
you press Return before moving on. Here, when you press Return , you will next see
the image of the array, Figure 1.16 (b).
We can use Matlab's own command to interrogate the data: these commands find use in
the M-files that store subroutines. An example routine is called after this. This subroutine
is stored in a file called invert.m and is a function that inverts brightness by subtracting
the value of each point from the array's maximum value. The code is illustrated in Code
1.7 . Note that this code uses for loops which are best avoided to improve speed, using
Matlab's vectorised operations (as in Mathcad), but are used here to make the implementations
clearer to those with a C background. The whole procedure can actually be implemented
by the command inverted=max(max(pic))-pic . In fact, one of Matlab's assets is
Search WWH ::




Custom Search