3.1.10 Representing Images

Table of Contents

Fork me on GitHub

1 Representing Images

Learn It

  • When an image is displayed on a computer monitor, pixels (which are the smallest addressable point on a display) are illuminated in different colours.

Pixel-example.png

  • In a standard bitmap image file (.bmp), each of these pixels is represented by three 8 bit binary numbers.
  • The first binary number represents the amount of red, the second the amount of green and the third the amount of blue.
  • So this colour here is:
    • 1101 0101 Red (213)
    • 1111 1111 Green (255)
    • 1100 0000 Blue (192)
  • Strings of binary numbers are difficult to read however, so we use hex instead.

Try It

  • Convert each of the binary integers above into hexadecimal notation.

Learn It

  • Bitmap images are made up of two parts.
  • The first part is the header. This contains information such as the size of the image and the type of file.
  • The second part is the image data itself.

Try It

  • Download this file to your computer - small.bmp
  • View it in an image viewer. You'll need to zoom in as it's a very small image.
  • Now visit this site - online hex editor
  • Now Open the bitmap file in the site.
  • The first few hex codes are just the header file.
  • Look for the codes 04 00 04 00. This is identifying the image as a 4 x 4 pixel file.
  • The long sting of FF codes is where each pixel colour is identified.

Build It

  • Try and edit the hex to produce an alternate pattern of red, blue and green pixels.
  • Export the image and open it in your viewer.
  • What other patterns can you make?

Learn It

  • The bitmap image format is a simple one.
  • There is very little metadata in the file - that is data that isn't coding pixel colours.
  • Other image formats such as jpg, png, gif will contain far more meta data, such as dates, authors, even the type of camera that the image was taken with.
  • Bitmap images are also uncompressed. This means every pixel is individually coded.
  • In other image formats, compression means that groups of similar pixels can be encoded, which reduces the size of the image file.