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
vectorized operations (as in Mathcad). The whole procedure can be implemented by the
command inverted=max(max(pic))-pic. One of Matlab’s assets is a ‘profiler’ which
allows you to determine exactly how much time is spent on different parts of your programs.
There is facility for importing graphics files, which is actually rather more extensive (i.e. it
accepts a wider range of file formats) than available in Mathcad. When images are used, this
reveals that unlike Mathcad, which stores all variables as full precision real numbers, Matlab
has a range of datatypes. We must move from the unsigned integer datatype, used for images,
to the double precision datatype to allow processing as a set of real numbers. In these ways
Matlab can and will be used to process images throughout this book. As with the Mathcad
worksheets, there are Matlab scripts available at the website for online tutorial support of the
material in this book; an abbreviated example worksheet is given in Appendix 1 (Section 9.2).
function inverted=invert(image)
%Subtract image point brightness from maximum
%
%Usage:[new image]=invert(image)
%
%Parameters: image-array of points
%
%Author: Mark S.Nixon
%get dimensions
[rows,cols]=size(image);
%find the maximum
maxi=max(max(image));
%subtract image points from maximum
for x=1:cols %address all columns
for y=1:rows %address all rows
inverted(y,x)=maxi-image(y,x);
end
end
Code 1.7 Matlab function (invert.m) to invert an image
1.6 Associated literature
1.6.1 Journals and magazines
As in any academic subject, there are many sources of literature. The professional magazines
include those that are more systems orientated, like Vision Systems Design and Advanced
Imaging. These provide more general articles, and are often a good source of information about
24 Feature Extraction and Image Processing

Get Feature Extraction & Image Processing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.