Run-length encoding of a pixel image
Compress a black-and-white image by writing each row as counts of same-coloured pixels in a run, starting with white. Row 00000 111 00 becomes 5,3,2. Counts can rebuild the grid.
Understanding Run-length encoding of a pixel image in Years 9–10 Data & Information
What it does: There are two runs: 4 white and 6 black. Writing the lengths in order gives 4,6. Each new count is a run of the opposite colour to the one before it. This is why the starting colour must be agreed. The colours change at every pixel, so every run has length 1. The row is 1 white, 1 black, 1 white, 1 black. A single 4 would rebuild 0000. The first count of 3 is white (000) and the second count of 3 is black (111), so the row is 000111. Encoding each row separately lets you rebuild the grid one row at a time. Without row breaks you could not tell where one row ends.
Common mistakes: The row 0000011100 has 5 white, then 3 black, then 2 white pixels. The runs should be 5,3,2, not 5,2,3. The row starts with black pixels, but the first count always means white. It needs a 0 at the start, so the runs are 0,3,4.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 6–16) and word search (Modules 6–132).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
run-length encodingFill in the Blanks
Spot the Error
Student with a class code? Join your class →