All tutorials & guides

Computer Vision

How Do Computers See? Pixels and Colours Explained for Kids

6 min read · beginner

When you look at a photo of the Gateway of India, you see stone arches, the sea and maybe some pigeons. When a computer looks at the same photo, it sees... numbers. Only numbers. Millions of them.

So how can a phone recognise your face, or an app read the text on a signboard? It all starts with understanding how a picture turns into numbers. That is the first step of computer vision, the part of AI that works with images.

A picture is a grid of tiny squares

Zoom very far into any digital photo and it breaks into tiny coloured squares. Each square is called a pixel, short for "picture element".

The pixels are arranged in a grid of rows (going down) and columns (going across). A picture that is 7 rows by 7 columns has 49 pixels. A phone photo can have millions of pixels, but each one works the same way.

Greyscale: one number per pixel

In a black-and-white (greyscale) image, each pixel holds a single number for its brightness:

  • 0 means black
  • 255 means white
  • Anything in between is a shade of grey

Why stop at 255? Computers often store each pixel value in one byte, and a byte can hold 256 different values, from 0 to 255.

Colour: three numbers per pixel

A colour pixel mixes three lights: red, green and blue, or RGB. Each one is again a number from 0 to 255.

  • (255, 0, 0) is bright red.
  • (0, 0, 0) is black, because all lights are off.
  • (255, 255, 255) is white, because all lights are fully on.
  • (255, 153, 51) is a saffron orange, like the top band of the Indian flag.

Your screen really does this. Each pixel on your display has tiny red, green and blue parts that glow at different strengths.

The big idea

If a picture is just numbers, then changing a picture means doing maths on numbers. Want a photo negative? Subtract each value from 255. Want to make it brighter? Add a little to every number. Edge detection, filters and even face recognition all build on this idea.

Try it: draw a smiley with numbers

  1. Open Python on your computer or an online Python editor.
  2. Type the program below. It stores a 7-by-7 greyscale smiley as a list of rows.
  3. Run it. The show function prints dark pixels as ##, grey ones as ++ and light ones as .., so you can "see" the picture in text.
  4. Look at the negative version, made by doing 255 - value for every pixel.
  5. Find the file smiley.pgm in the same folder. PGM is a very simple image format; many image viewers (and free editors such as GIMP) can open it. It will be tiny, so zoom in. If you are using an online editor, you can skip this step.
# A picture is a grid of numbers: 0 = black, 255 = white
smiley = [
    [255, 255, 255, 255, 255, 255, 255],
    [255,   0, 255, 255, 255,   0, 255],
    [255, 255, 255, 255, 255, 255, 255],
    [255, 255, 255, 120, 255, 255, 255],
    [255,   0, 255, 255, 255,   0, 255],
    [255, 255,   0,   0,   0, 255, 255],
    [255, 255, 255, 255, 255, 255, 255],
]

def show(grid):
    for row in grid:
        line = ""
        for value in row:
            if value < 85:
                line += "##"     # dark pixel
            elif value < 170:
                line += "++"     # grey pixel
            else:
                line += ".."     # light pixel
        print(line)

print("Rows:", len(smiley), " Columns:", len(smiley[0]))
show(smiley)

print()
print("Negative (255 minus every pixel):")
negative = [[255 - v for v in row] for row in smiley]
show(negative)

# Colour pixels have three numbers: (red, green, blue)
saffron = (255, 153, 51)
r, g, b = saffron
grey = round(0.299 * r + 0.587 * g + 0.114 * b)
print()
print("Saffron", saffron, "as one grey number:", grey)

# Save the smiley as a real image file (PGM format, opens in many image viewers)
with open("smiley.pgm", "w") as f:
    f.write("P2\n7 7\n255\n")
    for row in smiley:
        f.write(" ".join(str(v) for v in row) + "\n")
print("Saved smiley.pgm")

The first picture printed looks like this:

Rows: 7  Columns: 7
..............
..##......##..
..............
......++......
..##......##..
....######....
..............

Can you see the face? The top pair of dark dots are the eyes, the ++ in the middle is a grey nose, and the lower dots plus the bottom row make a smile curving up at the corners.

At the end, the program turns saffron into a single grey value: 172. Notice the formula gives green the biggest weight. That is because human eyes are most sensitive to green light, so green affects how bright a colour looks to us the most.

Experiment

  • Change some 255s to 0 to draw your own initial or a simple shape.
  • Make the nose darker or lighter and see when it switches from ++ to ##.
  • Try other RGB colours, such as India green (19, 136, 8), and print their grey values.

For parents

This activity shows that computers do not "see" the way people do. They process numbers, and AI vision systems learn which number patterns usually mean "face" or "road sign". That is a useful, grounded way to talk about what technologies like face unlock or number-plate readers are actually doing.

What you learned

  • Digital images are grids of pixels arranged in rows and columns.
  • A greyscale pixel is one number from 0 (black) to 255 (white).
  • A colour pixel is three numbers: red, green and blue.
  • Editing a picture means doing maths on its numbers, like 255 - value for a negative.
  • Computer vision, the AI that works with images, starts from these number grids.

See further

Pixels are just the beginning. In a full computer vision course, students adjust brightness and contrast, blur and sharpen images, trace edges, find coloured objects and look inside the neural networks that recognise things in photos. Want to build more? Book a free demo class and explore how computers learn to see.

Want your child to build more like this?

Book a free 1:1 demo class with a Curiovio teacher. Your child builds a real project live, and you see how we teach.

Book a free demo class

Free: build your child's first AI project in 7 days

One short, fun task a day for you and your child. Only a web browser needed.