2 - Greyscale Image Class

Resources

Full tutorial (in Acrobat pdf format):

Tutorial_02.pdf

C# project (zip file):

Tutorial_02_IpTestBed.zip

Summary

Most image processing texts teach image processing with greyscale images. Greyscale images are those that only show the intensity of light in the image without any colour information. They are similar to a black and white photograph.

The most common way in which a greyscale image is stored in a computer is in 8-bit format. This means that each pixel in the image is represented by an 8-bit binary value which can hold the decimal numbers 0-255. So different levels of grey are represented by one of these 256 values with 0 representing black and 255 representing white.

A greyscale image that is 800x600 pixels will have 480,000 pixels with each pixel requiring 1 byte (8 bits = 1 byte). So this image would take up roughly half a megabyte of memory. In comparison, a colour image is usually represented by 3 bytes for each pixel (8 bits for red, 8 for green and 8 for blue) - this is called 24-bit colour. So a colour image of size 800x600 would take up approximately one and a half megabytes of memory.

In this program we will load an image from file and store it in a greyscale object. A greyscale class will be developed for this purpose. The class will be expanded throughout the tutorials so that it can perform other processing techniques. For example, we might load an image as greyscale, filter it, perform edge-detection on it, and threshold the result (if you don't know what these terms mean, you will find out in later tutorials).

The processing technique that we will write first will be to create 'negative' of a greyscale image which looks like an old photographic negative. This is done by simply looping through each pixel in the image and subtracting each value from 255 and replacing the pixel value with the result. For example a black pixel will have a value of 0. This pixel will be set to 255-0=255 which will change it to a white pixel. A value that is close to white might have a value of 212. This pixel will be set to 255-212=43 which will change it to a value close to black.

Please download the tutorial in the Resources section above and work through it using Microsoft C#. If you have any trouble creating the progam from the code given in the tutorial, please download the full C# project and try to work out what has gone wrong with yours.

When you are ready go onto the next tutorial.

Resources

Full tutorial (in Acrobat pdf format):

Tutorial_02.pdf

C# project (zip file):

Tutorial_02_IpTestBed.zip