Computer Vision Series

1 posts
1
Image Basics & Getting Started with OpenCV
· 7 min read

What Is a Digital Image

Computer vision operates on digital images. At its core, a digital image is just a 2D array of pixels.

Pixels and Grayscale Images

A grayscale image is the simplest form—each pixel stores a single brightness value from 0 (pure black) to 255 (pure white). In Python, a grayscale image of width W and height H is a 2D array with shape (H, W):

python
1
2
3
4
import numpy as np

# Create a 100x100 gray square (brightness 128)
gray_img = np.full((100, 100), 128, dtype=np.uint8)

uint8 ranges from 0 to 255 because 8 bits can represent 2^8 = 256 unique values. If a pixel value exceeds its range, wrap around occurs: 255 + 1 becomes 0, not 256 (like an odometer rolling over). Use cv2.add() (saturating arithmetic) or np.clip() to prevent wrap around.