Sub topic 2
Width, Height, and Resolution
Assume you know basic Python and arrays. You should also be familiar with pixels, bytes, and common image files such as JPEG and PNG.
Width and height are pixel counts
A digital image is a rectangular grid of samples called pixels. Width is the number of pixels in each row. Height is the number of rows.
An image with width 640 and height 480 contains:
640 × 480 = 307,200 pixelsIn an array, the usual image shape is written as (height, width, channels), not (width, height, channels). Therefore, a colour image with 640 columns, 480 rows, and three colour channels has shape (480, 640, 3).
import numpy as np
height, width, channels = 480, 640, 3
image = np.zeros((height, width, channels), dtype=np.uint8)
print(image.shape)
print(image.size) # 921600 individual channel valuesimage.size counts channel values, not pixels. The pixel count is height * width.
Resolution has two meanings
In computer vision, resolution often means the image dimensions, such as 1920 × 1080. In printing and display hardware, resolution can mean pixel density, measured in pixels per inch (PPI). These meanings are related but different.
A 1920 × 1080 image always has 2,073,600 pixels. Its physical size depends on the display or print density. At 100 PPI, it is 19.2 × 10.8 inches. At 200 PPI, it is 9.6 × 5.4 inches.
| Term | Meaning | Example |
|---|---|---|
| Dimensions | Pixel width and height | 1920 × 1080 |
| Pixel count | Total pixels | 2,073,600 |
| Pixel density | Pixels per physical inch | 100 PPI |
A camera can capture many pixels, but that does not guarantee sharp detail. Lens quality, focus, motion, lighting, and sensor noise also affect useful resolution.
Aspect ratio and resizing
The aspect ratio is width divided by height. A 1920 × 1080 image has an aspect ratio of 16:9. Resizing should normally preserve this ratio. Changing only the width or height stretches objects and produces geometric distortion.
For example, resizing 640 × 480 to 320 × 240 preserves 4:3. Resizing it to 320 × 320 changes the ratio and makes circles appear elliptical.
Exercise
Exercise
An image array has shape (720, 1280, 3). What are its width, height, aspect ratio, and pixel count?
Show answer
The width is 1280 pixels, the height is 720 pixels, the aspect ratio is 16:9, and the pixel count is 921,600.