
The one shown above is bumpy because we've only used four sine waves to describe it. In fact, if you were to continue the pattern with more than four sine waves, this shape would become a "square wave", which is one that suddenly goes to the maximum value, and then suddenly to the minimum. When the above four waves are added together, they interfere with each other, and produce a shape that has sharper transitions: This should produce the following four sine waves:

Now set the "amplitude" (equivalent to volume level) of the four to 0.5, 0.25, 0.125 and 0.0625 respectively (each is half of the previous one).

Try setting the four sine waves to frequencies that are 3, 9, 15, and 21 times the fundamental frequency respectively (the "fundamental" is the lowest frequency). In this spreadsheet, the yellow region on the first sheet allows you to choose which sine waves to add. This would be lossy because you can't reproduce the original exactly, but it would be good enough for a lot of purposes, and save a lot of space. Instead of storing 5 pixel values, only 2 are needed, yet someone viewing it probably might not notice any difference. You could use a variation that specifies a pixel's colour, and then says how many of the following pixels are the same colour, but although most adjacent pixels are nearly the same, the chances of them being identical are very low, and there would be almost no runs of identical colours.īut there is a way to take advantage of the gradually changing colours.įor the pixels in the red box above, you could generate an approximate version of those colours by specifying just the first and last one, and getting the computer to calculate the ones in between assuming that the colour changes gradually between them. Run length encoding wouldn't work in this situation. Notice that the colours in adjacent pixels are often very similar, even in this part of the picture that has a lot of detail.įor example, the pixels shown in the red box below just change gradually from very dark to very light. Image compression methods like JPEG, GIF and PNG are designed to take advantage of the patterns in an image to get a good reduction in file size without losing more quality than necessary.įor example, the following image shows a zoomed in view of the pixels that are part of the detail around an eye from the above (high quality) image. Reducing the number of bits (the colour depth) is sufficiently crude that we don't really regard it as a compression method, but rather just a low quality representation. This is the advantage of JPEG: it removes information in the image that doesn't have so much impact on the perceived quality.įurthermore, with JPEG, you can choose the tradeoff between quality and file size. The right hand one has had the number of colours reduced to 256, so there are 8 bits per pixel instead of 24, which means it is also stored in a third of the original size.Įven though it has lost just as many bits, the information removed has had much more impact on how it looks.

The left hand image has been compressed to one third of the original size using JPEG while it is a "lossy" version of the original, the difference is unlikely to be perceptible. The middle image is the original, which was 24 bits per pixel. The following three images show the difference between reducing bit depth and using a specialised image compression system. However, image compression methods such as JPEG take advantage of patterns in the image to reduce the space needed to represent it, without impacting the image unnecessarily.

In the data representation chapter we looked at how the size of an image file can be reduced by using fewer bits to describe the colour of each pixel. There are other situations where images need to be stored exactly as they were in the original, such as for medical scans or very high quality photograph processing, and in these cases lossless methods are used, or the images aren't compressed at all (e.g. This kind of compression is called lossy compression. This can lead to considerable savings in space, especially if the details that are missing are the kind that people have trouble perceiving. With a lot of images (especially photographs), there's no need to store the image exactly as it was originally, because it contains way more detail than anyone can see. Images can take up a lot of space, and most of the time that pictures are stored on a computer they are compressed to avoid wasting too much space.
