Converting an image to grayscale

One of the most popular activities in computer vision is converting to and using a grayscale version of an image. In Julia, this is achieved by using the Gray function. This is shown as follows:

using Images
img = load("sample-images/cats-3061372_640.jpg");
img_gray = Gray.(img)
imshow(img_gray)

Grayscale images are widely used in classic computer vision, for tasks such as feature detection, morphology, and so on. The benefit of using grayscale images is that they are represented in a single dimension, which makes it fast for processing and analysis. We will be using this extensively throughout the book.

Keep in mind that Gray returns a single dimension, compared to three-dimensions for an RGB image. Use the following command to convert one channel Gray image to a three-channel grayscale RGB image:

img_gray_rgb = RGB.(Gray.(img_gray))