.
9
.
Appendix 1: Example
worksheets
9.1 Example Mathcad worksheet for Chapter 3
The Mathcad worksheet has been typeset in this edition and the worksheets could be made to
look (something) like this (but currently do not).
The appearance of the worksheets depends on the configuration of your system and of the
Mathcad set up. To show you how they look, but as black and white only, here is part of a
typeset version of the shortest worksheet. Note that the appearance of the real worksheet will
depend largely on the setup of your machine.
Chapter 3 Basic image processing operations: CHAPTER3.MCD
This worksheet is the companion to Chapter 3 and implements the basic image processing
operations described therein. The worksheet follows the text directly and allows you to process
the eye image.
This chapter concerns basic image operations, essentially those which alter a pixel’s value
in a chosen way. We might want to make an image brighter (if it is too dark), or to remove
contamination by noise. For these, we would need to make the pixel values larger (in some
controlled way) or to change the pixel’s value if we suspect it to be wrong, respectively. Let’s
start with images of pixels, by reading in the image of a human eye.
eye := READBMP(eye_orig)
We can view (part) of the image as a matrix of pixels
eye
=
0312 456789
0 115 117 130 155 155 146 146 135 115 132
1 135 130 139 155 141 146 146 115 115 135
2 139 146 146 152 152 155 117 117 117 139
3 139 144 146 155 155 146 115 114 117 139
4 139 146 146 152 150 136 117 115 135 139
5 146 146 146 155 149 130 115 137 135 145
6 147 146 142 150 136 115 132 146 146 146
7
146 141 155 152 130 115 139 139 146 146
8 136 145 160 141 115 129 139 147 146 141
9 117 146 155 130 115 115 137 149 141 139
10 132 152 150 130 115 115 142 149 141 118
11 137 149 136 130 130 114 135 139 141 139
12
137 145 130 117 115 115 117 117 132 132
349
or we can view it as an image (viewed using Mathcad’s picture facility) as
This image is a 64 pixels wide and 64 pixels in height. Let’s check:
cols(eye)=64 rows(eye)=64
The gives us 4096 pixels. Each pixel is an eight bit byte (NB. it’s stored in .BMP format),
so this gives us 256 possible intensity levels, starting at zero and ending at 255. It is more
common to use larger (say 256 ×256) images, but you won’t be tempted to use much larger
ones in Mathcad. It’s very common to use 8 bits for pixels, as this is well suited to digitized
video information.
We describe the occupation of intensity levels by a histogram. This is a count of all pixels
with a specified brightness level, plotted against brightness level. As a function, we can calculate
it by:
8 bits give 256 levels, 0..255
Initialize histogram
Cover whole picture
Find level
Increment points at
specified levels
Return histogram
histogram(pic):=
for bright0..255
pixels_at_level
bright
0
for x
0..cols(pic)–1
for y
0 ..rows(pic)–1
levelpic
y,x
pixels_at_level
level
pixels_at_level
level
+1
pixels_at_level
So let’s work out the histogram of our eye image:
eye_histogram := histogram(eye)
To display it, we need a horizontal axis which gives the range of brightness levels
bright := 0..255
0 100 200
0
200
400
eye_histogram
bright
Bright
So here’s the histogram of our picture of the eye image, p. The bright pixels relate mainly
to the skin, the darker ones to the hair.
350 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.