Chapter 1 Introduction (Hello Mathcad) CHAPTER1.MCD

Feature Extraction & Image Processing in Computer Vision

M. S. Nixon and A. S. Aguado

Academic Press, 3rd Edition 2012

This worksheet is the companion to Chapter 1 and is an introduction. It is the source of Section 1.5.2 Hello Mathcad, Hello Images. The worksheet follows the text directly and allows you to process basic images.

Let's define a matrix of pixels (picture elements), a synthetic computer image called pic.

This is Figure 1.12(a).

Pixels are addressed in row-column format. Using x for the horizontal axis (a column count), and y for the vertical axis (a row count) then picture points are addressed as pic y,x. The origin is at co-ordinates y = 0 and x = 0, so the point pic 2,2 is on the third row and third column; the point pic 3,2 is on the fourth row, at the third column. Let's print them:

Now try accessing other pixels.

We can view the matrix as a surface plot from the Graphics menu, as a surface (or function), or as an image.

Figure 1.12(b). Note that interpolation gives

the slope at the edges of the square. We'll

only use this format occasionally.

Figure 1.12(c). This is the format we'll use more often.

Note that since the origin is at co-ordinates (0,0), the top left hand corner of the image. For this image which has 8 rows and 8 columns, the bottom right hand point is pic 7,7. The number of rows and the number of columns can be derived by the Mathcad rows and columns functions (Code 1.1):

We can define a subroutine to invert the image, by subtracting the value for each point from the maximum value of the points in the image. The maximum is given by the max function:

To access image points, we will need x and y co-ordinates. The columns index x starts at the origin (0) and addresses points up to the number of columns - 1. The index y does the rows. The new picture new_pic is then calculated by the routine (Code 1.2):

address points in all rows

address points in all columns

subtract pixel value from maximum

deliver new picture

And the new picture is:

This is Figure 1.13(a)

And this can be seen as:

Figure 1.13(b)

Figure 1.13(c)

The addition process can be formulated as a function, which requires an input picture, and a value, as arguments. The result is a new picture where each pixel is the corresponding point in the input picture plus the value. The function add_value is then (Code 1.3):

address whole picture

add point to value

return picture

This can be invoked by:

Giving a new picture:

We usually need to demonstrate algorithms on real images which are much bigger than this synthetic one. To do this, we need to read a Windows bitmap image using the READBMP command. Let's read in the image of a face.

The actual data in the image is, for the top left corner (Figure 1.14(a)):

Viewing a small bit gets round version compatibility problems

To see different areas, view the whole matrix and you can then change the viewed portion

We can view it as an image (Figure 1.14(c)) too using Mathcad's picture facility

Mathcad's picture facility gives us a much faster way of viewing images, simply because they are displayed as a picture, rather than as a specially arranged surface plot. This way, you don't have to wait for the image to be recalculated when you zoom up and down the worksheet. The only problem is that if you apply the algorithms to a picture a different size and then view it as the same picture, you'll need to re-size the picture (click on the background, drag the cursor over the picture and then make it bigger - like in Word). If you want to see what's been sent to the picture, just click on it and the variables will show up.

Sometimes, it's prudent to write big images as bitmaps using the WRITEBMP command and view them with a bitmap viewer.

Let's do some simple processing. First, let's make the image brighter:

Now let's write it:

and the look at the new image (Fig. 1.14(d):

Let's have a peep at the new values (Figure 1.14(b)):

Yes! They have the right amount added.

Finally, let's generate the banded image for the Mach band effect. We need to create an image, so let's assign the image face to an image mach

Now we need to define the intensity bands (Code 1.5):

The Mach bands stand out clearly between regions of constant grey level.

To display a cross-section as a graph, we'll need a pointer:

So a cross-sectional slice through our banded image is (Fig 1.4(b)):

What we see is actually different, since we perceive black lines between the bands. To generate a cross-section through the perceived image, we generate a function called seen.

Giving a cross-section as (Figure 1.4(c)):

So you should now be familiar with Mathcad and its operation. You've seen procedures and functions, graphs and images. Try changing the value of any parameter to see its effect. How about writing a routine to generate the circles image, Fig. 1.2(a)?