Hour of Code: Image Magic with Python Lesson Plan

Overview

This code activity extends on a basic understanding of the programming language Python to explore the world of image manipulation and data representation using the Python Imaging Library. The activity uses conditions and looping to edit images, and explores how more complex coding constructs can be used to efficiently manipulate every pixel in an image.

It is recommended that students have an understanding of input, if statements and for loops in Python before starting this course. Students who have completed the Beginners stream of the NCSS Challenge, Python for Beginners, or Introduction to Programming (Python) should find this an interesting next course. For new programmers we recommend completing the first 6 modules of Python for Beginners before starting.


Learning Objectives

Students will:

  • Use input to request string and numerical data from the user
  • Learn about opening image files and saving new image files
  • Learn about data representation for greyscale and colour images
  • Use the Python Imaging library to get and set pixel colours in an image
  • Use the Python Imaging library to analyse image size and type
  • Use conditions to make decisions when editing images
  • Use loops to edit multiple pixels at once in a row
  • Use more complex nested looping structures to edit all the pixels of an image

Extended Activities

Mixing colours

When you were dealing with colour images (RGB images) did you notice that it uses red, green and blue as the primary colours? It doesn't use red, yellow and blue like we use for paint.

When mixing light (like the light coming out a computer screen) colours mix differently than when you mix physical things like paint.

Light mixes using an additive colour system - when you add more colour it gets closer to the colour white.
Paint mixes using a subtractive colour system - when you add more colours of paint it gets closer to black.

You can play with mixing different colours of light here.

Analysing photo filters

Take a look at the available filters on an app like Instagram. Compare a filtered image to the original.

  • What would you describe the filter as? (bright, dark, red, grey, etc)
  • What kinds of edits do you think have been made to create this filter?
  • Have the red, green and blue colours been considered together (like we did in our greyscale filter) or does the filter amplify specific colours?

Creating your own filters

Now you know a bit about editing colours can you come up with your own filter? Think about how you want to edit the colours, then try it out in the playground question at the end of the course.

Register as a teacher for free!

Or pick one of our other fun activities. Suitable for Grades 3-12.

Monster Maker! (Blockly)

Use drag-and-drop blocks to write your own programs, learn about sequence and ordering, and create fun monster characters!

Start coding now!

Animal Classifier (Python)

Learn about the differences between animals, and how Biologists use programming to help them do science! You'll use the programming language Python to classify animals based on their characteristics.

Start coding now!

Cyber Security: Defence Against the Dark Hats

This Cyber Security Mini course is a short introduction to staying safe online. You'll learn about secure passwords, phishing, security settings, social media and more!

Start coding now!

Is Eliza Human? (Python)

Use the programming language Python to build a friendly chatbot called "Eliza". Can she fool your friends into thinking she's a human?

Start coding now!

Flags of the World (Python Turtle)

Use the programming language Python and instruct a turtle to draw flags from around the world! How many countries do you know?

Start coding now!

Cyber Live!

A Navy captain is held captive inside his ship. A major landmark has gone dark. And weapons are pointed at Sydney’s busiest sites… It’s all connected, and it’s up to you to free the captain, track down the culprit, and stop them. Students will need to trace clues, solve puzzles, and figure out how to stop a large scale simulated cyber attack before it’s too late.

Start coding now!

Frozen Fractals (Python Turtle)

Use the programming language Python and instruct a turtle to draw fantastic snowflakes with code! Brrr, is it getting cold in here?

Start coding now!

Frozen Fractals (Blockly Turtle)

Build programs using friendly blocks and instruct a turtle to draw fantastic snowflakes with code! Brrr, is it getting cold in here?

Start coding now!

Virtual Pet (Python micro:bit)

Get started with the BBC micro:bit. Use the Python programming language to make a pet that you can feed and play with! No micro:bit required.

Start coding now!

Virtual Pet (Blockly micro:bit)

Get started with the BBC micro:bit. Use friendly blocks to make a virtual pet that you can feed and play with! No micro:bit required.

Start coding now!

Hydrangea Danger (Blockly Turtle)

This activity is designed to introduce branching. Use the Blockly version of Python and its turtle module to draw and colour hydrangea flowers!

Start coding now!

Emoticon Madness (Python)

Ever wanted to create your own emoticon? Use the programming language Python to explore emoticons and text manipulation.

Start coding now!

Space (Blockly Python)

Use the visual programming language Blockly to investigate space and reach for the stars.

Start coding now!

Disease Epidemic (Python)

Use the programming language Python to model a disease outbreak. Can you solve the curious case of the glowing nose?

Start coding now!

The Dark Tunnel (Python)

Use the programming language Python to create a simple game (or MUD). Can you find your way through the dark tunnel?

Start coding now!