22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Images and Channels

In case you’re not familiar with the meaning of channels, pixel values, and

how images are represented as tensors, this is a brief overview of these

topics.

To illustrate how images are represented, let’s create three separate images

first:

image_r = np.zeros((5, 5), dtype=np.uint8)

image_r[:, 0] = 255

image_r[:, 1] = 128

image_g = np.zeros((5, 5), dtype=np.uint8)

image_g[:, 1] = 128

image_g[:, 2] = 255

image_g[:, 3] = 128

image_b = np.zeros((5, 5), dtype=np.uint8)

image_b[:, 3] = 128

image_b[:, 4] = 255

Each of these images is five-by-five pixels and is represented by a five-byfive

matrix. It is a two-dimensional representation, which means it is a

single-channel image. Moreover, its dtype is np.uint8, which only accepts

values from zero to 255.

If an image has only one channel, it is a grayscale image.

The range of pixel values goes from zero (black) to 255

(white), and everything in between is a shade of gray.

Classifying Images | 269

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!