Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Digital Images
A digital image is a rectangular grid of pixels stored as numbers. Understanding this structure is the foundation for every image processing operation you will learn.
What is a Digital Image?
A digital image is a two-dimensional grid of picture elements, called pixels, where each pixel stores a colour value.
The grid has:
- Height: the number of rows of pixels (vertical)
- Width: the number of columns of pixels (horizontal)
- Channels: the number of colour values per pixel (1 for grayscale, 3 for colour)
A 1920×1080 image (Full HD) has:
- 1920 pixels across
- 1080 pixels down
- 1920 × 1080 = 2,073,600 pixels total
For a colour image, each pixel stores three values (R, G, B), so the total data is:
2,073,600 × 3 = 6,220,800 numbers.
Machine Learning follows a structured pipeline from data to deployment
Inspecting an Image With Python
import cv2
import numpy as np
# Load an image
image = cv2.imread("photo.jpg")
# Inspect its structure
print(f"Shape: {image.shape}")
# Output: (height, width, channels) e.g. (480, 640, 3)
height, width, channels = image.shape
total_pixels = height * width
total_values = total_pixels * channels
print(f"Width: {width} pixels")
print(f"Height: {height} pixels")
print(f"Channels: {channels} (3 = colour image)")
print(f"Total pixels: {total_pixels:,}")
print(f"Total numbers stored: {total_values:,}")
print(f"Data type: {image.dtype}") # uint8 = values 0-255