AstraAI

Computer vision Β· segmentation

Colour in just the ball

In the curriculum:Computer visionSee the map β†’
πŸŽ“ School maths Β· Years 5–6Coordinates & position β€” Identify a region of a grid by its position and colour.Maths by year β†’

The Case. In a photo of a park, how does a computer pick out just the red ball and ignore the sky and grass? This is how self-driving cars find the road.

Your tools. numpy checks the colour of every pixel at once. Pixels that are very red and not green must be the ball.

Investigate. Press Run. The right image is the mask β€” white where the computer decided ‘this belongs to the ball’.

  • This is semantic segmentation: labelling every pixel by what it belongs to.
  • Try changing the colour rule β€” can you make it grab the sky instead?
your_code.py
Starting Python…
The Reveal

Starting Python… (first time only β€” a few seconds)

πŸ—’οΈ Detective's notes

Bundles your findings, chart and code into one PDF you can keep, print or hand in.

🧩 How this code works

The tools it uses

  • NumPy β€” a row of boxes that holds numbers, so you can do maths to all of them at once.
  • Matplotlib β€” your crayon box β€” it turns numbers into charts and pictures.

How to read it, top to bottom

  1. 1. Import β€” bring in the tools (listed above).
  2. 2. The data β€” the lists and numbers near the top. These are the bits you change.
  3. 3. The work β€” a little maths, or a loop that repeats a step.
  4. 4. Show it β€” print(...) writes words; plt.show() draws the picture.

Use it for your own problems

  • Change the numbers at the top and press Run β€” nothing breaks, so experiment!
  • Ask your own version of the question β€” swap in your family, your scores, your week.
  • The same tools work on any numbers β€” that's the superpower you're learning.
Need a hint?

A mask is just True/False for every pixel. imshow draws True as white, False as black.