Representing an image in binary notes
Introduction
We can think of an image on a computer as being stored as a series of squares. These squares are known as 'pixels' and are defined as 'a single dot in an image' . Exactly how does the computer use pixels to store an image?
Displaying pictures using bitmaps
Consider the image above. The smallest unit element that can be displayed is the 'pixel' which is a shortened word that originates from the phrase 'picture element'. If we want to store the picture, we have to start in the top-left hand corner and store the colour (often referred to as the ‘colour depth’) of each pixel down to the bottom right-hand square. We also need to store how many pixels there are in a particular area (known as the ‘resolution’). If we store the information about each of the pixels together and the resolution of the picture, we end up with a picture file known as a 'bitmap file'. This is the raw file that you get when you scan a picture using a scanner, for example.
To recap, you always need two pieces of information to store a picture:
-
- the colour depth of each pixel.
- the resolution of the picture.
In addition to the above pieces of information, you may have additional information stored about a picture. This additional information is called ‘metadata’. Metadata is looked at in more detail in section 2.1.4l and colour depth and resolution are covered in more detail in section 2.1.4m.
Bitmap files
If you have ever used the application called Paint in Windows (in Accessories), this application can save any picture you create as a bitmap file (amongst other file types) and it has the file extension bmp. That means that when you save the file, Windows automatically adds .bmp to the end of your file name.
JPG, GIF and other 'codecs'
There is problem with bitmap files. They are very large. That means they take up a lot of storage space, take a while to open and also take a long time to transmit across networks. This is very important with the Internet. You don't want to be waiting for your computer to download and open large bitmap files.
For this reason, image files are usually stored as a different file type. Two common ones are GIF and JPG. These are known as 'codecs' (short for 'coder / decoder') and you can think of each codec as a clever Maths formula. If you take a bitmap and apply the GIF codec to it, it becomes a GIF file and is much smaller than the original bitmap. You can do the same thing using the JPG, or TIFF formats or any of the other image codecs. GIFs are great for icons and drawings that use up to 256 colours and are widely used for icons in software and for pictures on web sites. For more detail such as in photos, JPGs are used. They can use about 65000 colours so you get a lot of detail. So, when you draw a picture on a computer and save it as a particular file type, you are telling the computer to take the raw bitmap file and apply a particular Maths formula or codec to it, and add the correct file extension - .gif or .jpg or whatever it is you saved it as.
Vector images
There is another type of file apart from bitmaps. These are known as 'vector images'. If you drew a circle in Paint or any other drawing application, rather than storing the information as a bitmap pixel by pixel, you store the information that allows the drawing to be recreated instead. You store the formula for a circle, the radius, the line thickness, where the circle should be drawn, colour information and so on. If the image needs to be displayed, this information is taken by the drawing program and the drawing is reconstructed from the information given.
-
- Vector images are much smaller than bitmaps.
- They are great for shapes and mathematical drawings.
- They can't show the detail that bitmaps can.
- You can zoom in and out of vector images without losing detail
If you have ever used Google's excellent program called SketchUp then you will have used a program that produces vector drawings rather than bitmaps. Do a search for it and try it out. There are lots of 'Getting started' videos available.