The Digital Image — An Introduction to Image Processing Basics

Matt Maulion

--

Eye Digital Image | Wolfsdorf Rosenthal

As a recap to my previous article, images are more than just keepers of memoirs. It has been used in various applications out there, making significant impact in day-to-day processes in society. Now, we are going to look at images as numbers under the lens of matrices.

Wow! How can that be? Well, stick around and I am going to tell you the basic image processing techniques you should know as a starter.

But first, what is an Image?

Before digging deep into the technicalities, let us first dwell on the definition of the basic building block of image processing — images.

Generally, images are visual representations of external objects or artifacts around us. It can be produced through via analog and digital means. The analog way involves the use of photo-chemical reactions to record patterns of light (e.g. television images, photographs, paintings, and medical images). On the other hand, digital images are made through the use electronic sensors which records attributes of light falling upon tiny sub-sensor spots called pixels and recorded in a computer file for further interpretation.

What is the advantage of one over the other? It boils down to cost, speed, and quality. Digital images are way cheaper and faster to produce than analog ones. While in the context of photography, analog images remain superior over images that are produced digitally. Which is better over the other? It depends on the use-case at hand. For the purpose of this blog, we will only focus on digital images. Hence, for a simplified geeky and techy context which will drive our discussion later, you may think of images as arrays (or matrices) of pixels arranged in rows and columns.

An image — an array or a matrix of pixels arranged in rows and columns.

However, images that we encounter and interact with in real life are mostly analog (continuous sensed data) in nature. Hence, for images to be fit for digital processing, introduced herein are techniques that will be used for digitizing such images — sampling and quantization.

Sampling VS Quantization

Sampling involves the reduction of a continuous-time signal to a discrete-time signal. Meaning it takes the value of the image at regular spatial intervals. Below we illustrate how sampling is being done with a sample analog image (i.e. diamond).

Note: N is the number of pixels per side of the image

It can be observed that as we increase the number N by a factor of 2 in 6 iterations, the true form of the diamond becomes more apparently vivid. Hence, telling us that large values of N create a denser image and provides improved resolution.

Quantization on the other hand involves the process of mapping input values from a large set to output values in a smaller set, often with a finite number of elements. In other words, it discretizes the intensity values of an analog image. Below we show how quantization is being done with a sample analog image (i.e. a diamond)

Note: The number of bits 𝑘 used to represent an intensity value is known as its bit depth.

It can be observed that as the value of k increases by a factor of 2 in 6 iterations (similar with sampling), more colors were uncovered. Hence, this enables analysts to decide how granular the mode of image analysis is to be conducted (depending on what research question/use-case is to be answered).

For a deep-dive explanation on the difference between sampling and quantization, a tabular comparison is presented below:

Image Type Conversion

Now that we have successfully processed analog images to its digital representation, it is possible to convert these to various image types through the use of readily-available programming packages — sci-kit image (skimage).

Let us consider this image of my yeobo (just kidding). Using this image, let us convert it to other

Im Yoona (Love of my life) | Viki

We are going to implement this in Python! You can follow along by downloading Yoona’s image in the link provided in the image caption or you can use any digital image you want.

But before that, why is there a need for image conversion?

Compiled below are various reasons for image conversion specifically to grayscale:

First let us convert the RGB image to grayscale using skimage rgb2gray function. Implementation is seen below:

from skimage.color import rgb2gray
yoona_gray = rgb2gray(yoona)
imshow(yoona_gray);
Grayscale Image of Yoona

Next, let us convert the grayscale image into its monochromatic/binarized form. Intuitively, to convert a grayscale image to monochrome or binary image, we apply thresholding such that pixel values that are less than the threshold will be changed to the minimum allowed value (0) and those that are above the threshold will be replaced by the maximum allowed value (1.0 or 255). We can do that by using skimage’s img_as_uint function.

from skimage import img_as_uint
# for this demo, set threshold to average value
yoona_binary = img_as_uint(yoona_gray > yoona_gray.mean())
imshow(yoona_binary);
Binarized Image of Yoona

Brilliant! You know how to convert images to its grayscale and binarized format. I have been mentioning RGB earlier. Ever wondered what does it mean? Stay still, we will talk about that next part of this article.

Image Color Space

A ‘color space’ describes the range of colors that are available within any system, such as a computer, an image file, and a printed photograph. It is a standard way of holding these colors, so that when this color standard is known, other systems can reproduce the correct colors.

In this piece of writing, RGB and HSV color spaces are presented as follows:

RGB (Red, Green, Blue)

RGB Color Space | Changing Minds

The RGB (red, green , blue) colour space relates very closely to the way we perceive colour with the r, g and b receptors in our retinas. RGB uses additive colour mixing and is the basic colour model used in television or any other medium that projects colour with light.

HSV (Hue, Saturation, Value)

HSV Color Space | Lifewire

HUE

Hue is the color portion of the model, expressed as a number from 0 to 360 degrees:

  • Red falls between 0 and 60 degrees.
  • Yellow falls between 61 and 120 degrees.
  • Green falls between 121 and 180 degrees.
  • Cyan falls between 181 and 240 degrees.
  • Blue falls between 241 and 300 degrees.
  • Magenta falls between 301 and 360 degrees.

SATURATION

Saturation describes the amount of gray in a particular color, from 0 to 100 percent. Reducing this component toward zero introduces more gray and produces a faded effect. Sometimes, saturation appears as a range from 0 to 1, where 0 is gray, and 1 is a primary color.

VALUE (OR BRIGHTNESS)

Value works in conjunction with saturation and describes the brightness or intensity of the color, from 0 to 100 percent, where 0 is completely black, and 100 is the brightest and reveals the most color.

Uses of HSV

Designers use the HSV color model when selecting colors for paint or ink because HSV better represents how people relate to colors than the RGB color model does.

The HSV color wheel also contributes to high-quality graphics. Although less well-known than its RGB and CMYK cousins, the HSV approach is available in many high-end image editing software programs.

Selecting an HSV color begins with picking one of the available hues and then adjusting the shade and brightness values.

And that’s it! You have been acquainted with the basic image processing techniques. You now have an armor in your journey towards becoming an image processing expert! Stay tuned for my next articles. See you!

--

--

Matt Maulion
Matt Maulion

Written by Matt Maulion

A kid who uses data to make a difference.

Responses (1)