Mastering OpenCV 4 with Python
上QQ阅读APP看书,第一时间看更新

Images formulation

An image can be described as a 2D function, f(x,y), where (x,y) are the spatial coordinates and the value of f at any point, (x,y), is proportional to the brightness or gray levels of the image. Additionally, when both (x,y) and brightness values of f are all finite discrete quantities, the image is called a digital image. Therefore, f(x,y) takes the following values:

  • x ∈ [0, h-1], where h is the height of the image
  • y ∈ [0, w-1], where w is the width of the image
  • f(x,y) ∈ [0, L-1], where L = 256 (for an 8-bit image)

A color image can be represented in the same way, but we need to define three functions to represent the red, green, and blue values, respectively. Each of these three individual functions follows the same formulation as the f(x,y) function that was defined for grayscale images. We will denote these three functions subindex R, G and B for the three formulations (for the color images) as fR(x,y), fG(x,y), and fB(x,y).

A black and white image follows the same approximation in the way that only one function is required to represent the image. However, one key point is that f(x,y) can only take two values. Usually, these values are 0 (black) and 255 (white).

These three types of images are commonly used in computer vision, so remember their formulation.

The following screenshot shows the three types of images (a color image, a grayscale image, and a black and white image):

Remember that the digital image can be seen as an approximation of the real scene because f(x,y) values are finite discrete quantities. Additionally, both grayscale and black and white images have only one sample per point (only one function is needed) and color images have three samples per point (three functions are needed—corresponding to the red, green, and blue components of the image).