Computer Laboratory

Raspberry Pi

Introduction and Setup

0 Introduction

Image processing is the algorithms and techniques used to manipulate and analyse images; By applying transformations to an image we can filter out an unwanted elements, alter colours or shapes to produce desirable properties, or extract information about the features and objects in an image. As well as image processing, we will look at parts of Computer Vision and how the two areas tie together.

0.1 Images

So what is an image? For the purpose of image processing, we need to know how images are treated by computers.

Within a Computer, images are stored as a two dimensional array of pixels (picture element). The array can be thought of as a long table of row and columns, where each entry corresponds to a single pixel and each pixel stores the colour of the image at that single point. To understand how each colour is stored we will look at colour spaces.

0.2 Colour Spaces

The value stored for each pixel in the image depends on the colour space and colour model being used. The colour model describes how colours are represented by a set of numbers, where each number corresponds to a different colour 'channel'. The colour space is the mapping of the channels of the colour model to absolute reference values. For example the widely used colour space sRGB is based on an RGB colour model, where each pixel has values in the Red, Green and Blue colour channels. Each value represents the intensity of that colour relative to the absolute reference colours defined by the sRGB colour space.

There are a whole range of colour models and spaces, another widely used colour model is CMYK, standing for Cyan, Magenta, Yellow and Key (Black). This colour model is used in printing and differs from the RGB colour model as it is a subtractive colour model rather than an additive model; So in the RGB colour model, a combination of full intensities in Red, Green and Blue corresponds to white, whereas in CYMK it corresponds to black.

When the colour of a pixel is stored, it is stored as a tuple (ordered list) of values, with values for each channel defined by the colour model. The range each value takes is defined by the colour depth of the image, which is the number of bits used to store the colour of a single pixel. For an image based on the RGB model with a colour depth of 24 bits per pixel, 8 bits are used for each of the 3 channels giving a range of 0 to 255 (inclusive). This decimal value would then be stored internally as its binary equivalent. Sometimes the number of bits per pixel is defined in terms of the number of bits used per colour channel. So a pixel format named RGB565 would use 5 bits for the red and blue channels, and 6 bits for the green.

The next stage is to set up the Raspberry Pi. Afterwards we will move on to implementing some image processing algorithms.

1 Setup

In this series of tutorials, I will be using Python and C to illustrate algorithms used. To avoid the nuances of languages and libraries we will be using a single uniform C library and Python module to provide us useful functionality. The following sections will guide you through the download and installation of the necessary files onto your Raspberry Pi.

1.1 Download

This section covers the download of the necessary libraries for the remaining tutorials

To download this course and all of the necessary files to your Raspberry Pi, you need to first open a terminal window from the desktop (Start-<Accessories-<LXTerminal). In this terminal, navigate to your home directory by typing the command:

cd ~

Now we're in our home directory, we will make a new directory for the tutorials and navigate into it, type these commands in turn:

mkdir image_processing
cd image_processing

Now to download the files to this directory, type this command:

sudo wget http://www.cl.cam.ac.uk/downloads/freshers/image_processing.tar.gz

Now we have all of the files in a compressed format, to extract the files type:

sudo tar -xf image_processing.tar.gz

The wget command grabbed the file from our webpage, and the tar command extracted the resources from the compressed file. Type ls to see the names of all the newly created files.

The current directory ~/image_processing/ contains these tutorial pages, so that you can open and view them from the desktop. It also contains directories called library and examples

The library directory contains the library, python module and C header file. It also contains the install script to place these files into the correct place in the filesystem.

examples contains the code from the examples in these tutorials.

source contains the source code for the library and python module, you can look here if you're interested in how the library works. If you want to alter and build the source, you can look at Makefile to see the build steps. The source depends on python2.7-dev and libsdl1.2-dev to build.

Now we have all of the files, the next section will guide you through installing them.

1.2 Install

Now to installed the our library onto the pi, navigate into the library directory

cd ./library

And to install, type

sudo make install

This will execute a script which will move all of the files and the library into the necessary place in the filesystem.