Bits of Bytes.co

IGCSE / GCSE Computer Science

  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
Picture
MENU
  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
1 - Computer Systems / Image Files

Image Files


Bitmap Files (Raster)

Bitmap files are images that are made up from a number of tiny square pixels.
A Pixel is known as the smallest identifiable part of an image.
Each pixel can only be one single colour at a time, however when thousands of pixels are used together they can create very detailed images.
Each pixel can determine what colour to display as it is represented by a binary value that corresponds to a colour e.g. 11101 might be dark green. 
​Resolution is the concentration of pixels that are within a specific area i.e. an image.  The greater the  number of pixels within a specific area, the higher the image quality.

Representing colours

As already mentioned, bitmap images have each pixel represented with a binary number and this binary number will correspond to a colour. For simple black and white images like this yin yang only 1 bit is require to represent each pixel. This is because 1 bit offers 2 different states... 1 or 0.

As the image only has 2 colours, black and white, 1 bit is enough to offer 2 different representations.

In this case

​1 = black
​0 = white
Picture

Increasing the number of colours

To increase the detail of an image, you may find it necessary to add colour.  It is possible to add many colours to an image, however, to do so you must increase the number of bits that represent each pixel.

Using the Mario image to the right as an example we can see that there are 7 different colours.  To represent 7 different colours we will need to use 3 bits per pixel as a combination of 3 bits can offer up to 8 different states:

111 = Black
110 = White
101 = Blue
011 = Yellow
010 = Black
011 = Brown
100 = Creme
000 = Spare for an additional colour
Picture

Number of colours - Number of bits

Each time you increase the number of colours in an image you will need to increase the number of bits being used to represent each pixel. Below is a table illustrating how increasing the bits increases the number of available colour options.
Number of Colours
Bits Required
2
1
4
2
8
3
16
4
32
5
64
6
128
7
256
8
512
9
1024
10
2048
11
4096
12
8192
13
16384
14
32768
15
65536
16
Effect on file size
​Increasing the number of pixels
​It is important to note that if you increase the resolution of an image it will increase its quality, however it will also increase the file size as there will be more pixels each represented by bits (data)

Increasing the number of colours
​It is also important to note that increasing the number of colors will improve the quality of the image, however it will also increase the file size as each pixel will now be represented by more bits (data)
​


Calculating File Size

Picture
If you understand what a pixel is, how many of them are user to create an image, and that each pixel is represented by binary numbers, it is possible to calculate the size of the image file.

Step 1 - Have an image to use, we will use this duck image

Step 2 - Determine how many pixels the image has. This image has 308 Pixels

Step 3 - Determine how many bits are being used to represent each pixel.  This image has 4 colours so it is using 2 bits.

Step 4 - Multiply the number of bits by the number of pixels.

308 (Pixels) X 2 (Bits) = 616 bits

​616 / 8 = 77 Bytes

Meta Data

Even if you are a perfect mathematician and have correctly calculated an image file size, you may be frustrated to find that your result does not match the actual file size.

The reason for this is meta data. Meta data is essentially data about data.

​Image files (and others) will often store information about the file along with the file, this information will of course increase the file size.

Examples of information held in image metadata are:
File name
Author
Created date
Resolution
Number of colours
​GPS location data

Picture

Compressing Images


​Compression is the process of reducing the amount of data used to represent a file. This is useful for a number of reasons...  first of all it reduces the amount of space needed to be stored on your hard drive, secondly if somebody has a slower internet connection (Bandwidth), it will reduce the time taken to load or transmit.

Types of Compression
There are two types of compression used with image these are
  • Lossy Compression
  • Lossless Compression
Each of these are explained below:

Lossy Compression
​In order for lossy compression to work it must permanently remove data from the image
It will then try to reconstruct the image without the missing data.
This will result in a file size that is smaller, however, the quality will be much lower.

If you have an image that has been compressed with lossy compression it is NOT possible to restore the file to its original quality.

Lossless compression

Lossless compression does not remove any data from the file instead it uses algorithms to spot patterns of similarly coloured pixels. It then stores the pattern as an instruction so that the image can be reconstructed to its original quality.

One popular lossless compression method is RLE (Run Length Encoding)

Run length encoding involves counting the number of pixels of similar colour and stating how many of each are needed.
Example:
If we use this duck image as an example we can see that it has 4 colours therefor has a bit depth of 2.

If green is 00 the first line would look like this:

00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

With RLE the algorithm would count that there are 17 green pixels and simply represent this like below:

10001 - 00       (This means 17 x white)
As you can see this only takes 7 bits instead of 34

The second line is a little different, lets assume that black is 11. Here RLE would have to account for two different colours, this would look like:

1010 - 00, 11 - 11 , 100 - 00     -  10 x White, 3 x Black , 4 x white
Picture


Est. 2015 - Copyright © 2020