Computer Vision · Beginner level

Beginner level · Module 2: Digital Image Representation · Lesson 1 of 3

Pixels, Resolution and Coordinates

Learners see that a digital image is a grid of numbers, learn how resolution and coordinates work and load a first image in a notebook.

In this lesson you will

  • Explain pixels, resolution and image coordinates
  • Load and display an image in Python

Key concepts

pixelresolutionrow-column coordinatesorigin at top-leftcv2.imread / plt.imshow

The lesson

A digital image is a grid of pixels. A 640 × 480 image has 640 columns and 480 rows, which is 307,200 pixels. Each pixel stores numbers that describe its brightness or colour.

Coordinates start at the top-left corner. In NumPy, a pixel is addressed as image[row, column], so image[0, 0] is the top-left pixel and rows go down. This is the opposite order to the (x, y) used in mathematics and in many OpenCV drawing functions, which is a common source of bugs.

cv2.imread('leaf.jpg') loads an image as a NumPy array (or returns None if the path is wrong, so always check). Matplotlib's plt.imshow displays it in a notebook.

Step by step

  1. Load a photo with cv2.imread and check that it is not None.
  2. Print its shape and data type.
  3. Print the value of the top-left pixel and of the centre pixel.
  4. Draw a small rectangle at a given (x, y) with cv2.rectangle and check where it appears.

Practice activity

Load three images of different sizes and report their resolution, shape and the value of chosen pixels.

Expected result: Correct shapes and pixel values, and a clear note on row/column versus (x, y) order.

Check your understanding

  1. Where is image[0, 0]?

    Show answer

    The top-left pixel.

  2. What does cv2.imread return if the file path is wrong?

    Show answer

    None.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.