Chapter 4. Working with Color Images

Up to now, we have only worked with grayscale images. Even in the few cases where our photographs were in color, we first transformed them to grayscale and then processed them. However, color image processing is a much more frequent task in everyday life. It is not that different to what we have already covered; the basic thing we have to remember is that instead of two-dimensional matrices, we have to deal with three-dimensional matrices. In this chapter, we will introduce the concept of color, and expand the techniques covered so far to color images. Many of the image processing methods presented in previous chapters will be revisited, while covering specialized color image processing techniques. All these methods will be analyzed using practical examples of color image enhancement and artistic color manipulation.

In this chapter, we will cover:

  • Some basic knowledge of color image processing and its differences from grayscale image processing
  • How to manipulate and/or threshold the pixel values in color images
  • How to perform color masking
  • What color spaces are and why they are important
  • To use color spaces other than RGB
  • To achieve color isolation in images
  • How to perform red eye reduction

So, let's dive right in!

An introduction to color image processing

Before we begin examining the differences of color image processing to grayscale image processing techniques, we must first understand the difference between color and grayscale images. As explained in previous chapters, a grayscale image can be represented as a two-dimensional, m-by-n matrix (m rows and n columns). Its elements, called pixels, have values spreading from 0 to 255 (in the case of 8-bit images). A value of zero represents black, a value of 255 represents white, while all the values in between represent different shades of gray.

In the case of color images, the matrices become three-dimensional. The first two dimensions, as in the case of grayscale images, are the number of rows and the number of columns (m-by-n). The difference is that the third dimension typically comprises three layers, representing colors. That is, color images are three-dimensional (usually m-by-n-by-3) matrices and can be thought of as three grayscale images combined together. Each image typically represents one of the colors (that is, Red, Green, and Blue) of the image, which is therefore characterized as RGB. These three layers are also called color channels of the color space (RGB in our case).

Similarly to the grayscale image case, when we have a case of color images of 8-bits per channel, a zero value in one channel represents non-presence of the color, while a 255 value suggests full color presence. The three color channels are mixed together to produce the final color for each pixel in the image. A pure fundamental color occurs when one of the three color channels has the maximum value and the two others are equal to zero. This means that a pixel with {R, G, B} values equal to {255, 0, 0} will be pure red. Similarly, a pixel with values {0, 255, 0} will be pure green and a pixel with values {0, 0, 255} will be pure blue. Different mixtures of values in the three basic color channels will ultimately produce different colors.

Note

A more extensive description of the basic concepts of RGB color images can be found in Chapter 2, Introduction, of the manual of the Image Processing Toolbox. It can be found freely available in pdf format on the website of Mathworks, at http://www.mathworks.com/help/pdf_doc/images/images_tb.pdf.

What you may have deduced from the previous description of color images, is the fact that in order to apply the methods covered in previous chapters for color image processing, we will have to repeat the same process three times (one for each color channel). This is typically correct, as we will see in the rest of this chapter. Let's start with the basic image manipulations covered in Chapter 1, Basic Image Manipulations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset