Skip to content
KinPilot™Learn & Explore
Menu

Grades 6–8 · Computing

When can repeated pixels use a shorter description?

A digital drawing may contain a large patch of perfectly uniform sky. Writing the same blue value again and again seems wasteful when a shorter instruction could say how long the blue stretch lasts. Run-length encoding uses exactly that opportunity: it replaces neighboring repetitions with a count and a value, while keeping enough information to rebuild the original sequence.

Consider a row of twelve pixels: six white followed by six blue. Under the key 0 = white and 1 = blue, its raw description is 000000111111. In a simple count-and-color format, the same row becomes 6W6B. A decoder reads the first count, draws six white pixels, then reads the second count and draws six blue pixels. The order, colors and total length all survive. Nothing has been guessed or discarded.

This is lossless compression: decoding recovers the exact original values. The shorter description works because the sequence has structure. Instead of repeatedly saying white, white, white, the code describes how many neighboring whites occur. The decoder still needs shared rules, including what W and B mean and how counts are separated from values. Without those rules, compact symbols are merely ambiguous marks.

Now change the row to alternating white and blue pixels. Every color change begins a new run, so the code becomes 1W1B1W1B1W1B1W1B1W1B1W1B. That is twenty-four text characters to describe a row whose raw form has twelve. The same method that shortened a block of color has lengthened an alternating pattern. A compression method cannot save space merely by giving data a new name; it needs repetition or some other usable regularity.

The upper sequence shows encoding and exact reconstruction. The lower comparison keeps the pixel count fixed while changing the pattern and the description length.

Repetition can shorten an exact descriptionA row of six white then six blue pixels has the twelve-character raw description 000000111111. Encoding produces four characters 6W6B and decoding restores the same row. An alternating twelve-pixel row instead produces twelve one-pixel runs, written on two lines for space: 1W1B repeated six times, totaling twenty-four characters.Runs preserve the pixelsSix white, then six blue000000111111Encode6W6B4 text charactersDecodeThe exact original rowChange the pattern0101010101011W1B1W1B1W1B1W1B1W1B1W1B12 characters become 24.Counts are characters here,not a real file size in bits.
A two-run row becomes 6W6B and expands back into the same twelve pixels. An alternating row needs twelve one-pixel runs, doubling the character count in this stated text format.

The comparison must also use consistent units. Here 000000111111 has twelve characters and 6W6B has four. That does not prove a real file shrinks from twelve bits to four bits: the count digits and color letters must themselves be encoded, and a file needs information about its format and dimensions. A storage scheme that packs raw black-and-white pixels into individual bits has a different starting cost from one that stores each as a text character.

For drawings with long uniform stretches, runs can capture much with little. For noisy or frequently changing pixels, they may offer little advantage. Compression therefore reveals something about the data itself: a shorter exact description is possible when the encoder and decoder can exploit patterns that are really there.

About this explanation

Starting knowledge: Read ordered strings, group equal adjacent symbols and compare counts while keeping measurement units explicit.

Sources

  • Computer Science Field Guide, University of Canterbury — Run length encoding
  • Microsoft Open Specifications — Run-Length Encoding (RLE) Compression
  • Microsoft Learn — Bitmap Storage
← Grades 6–8 topics