Um momento
0x00Lesson 1 of 6

Represent an image as data

Connect image dimensions and pixel values to the arrays a computer can process.

14 min 4-question quiz 1 code exercise
By the end of this lesson you can
  • Read a small grayscale image as a grid of pixel intensities.

Computer vision (CV) is the field of building systems that extract useful information from images and video. A digital image is represented by pixel values arranged on a grid. A grayscale image can be modeled as a two-dimensional array; a color image usually stores several channel values per pixel. In the common 8-bit format, grayscale intensities range from 0 (black) to 255 (white).

cv_example.py
1image = [
2    [0, 40, 255],
3    [20, 180, 255],
4]
5print(len(image), len(image[0]))
Output
2 3

This toy grid has two rows and three columns. Real image files also carry format and color metadata, and libraries such as Pillow and OpenCV decode them into arrays. Images can be very large: height × width × channels gives the number of stored channel values.

Key takeaways

  • Read a small grayscale image as a grid of pixel intensities.

  • Small arrays make vision ideas concrete.

  • Check model performance across varied real-world examples.

Lesson quiz

4 questions · pass with 3 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: apply computer vision with Python

Use small pixel arrays to explore vision concepts, run your code against sample images, and connect each result to the larger computer vision idea.

Exercise 1

Measure a tiny image

+25 XP

Read a JSON 2D list of grayscale pixel values. Print its height and width as height width. The image has at least one row.

  • Two by three
  • Three by one
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: