Let's first start by pointing out that the subject
of image digitisation fills many volumes and is quite complex.
This article is intended to give a simple overview of what
compression is and how it works. For those so inclined,
resources are available on the Internet, and in many books,
which can provide an in-depth look at a very complex subject.
The larger the image, and the more precise the sampling
process, the larger the final digital file will be. To
make the use of digitised photographs
more practical be it for transmission over networks, or for storage
on a disk algorithms have been developed to reduce the amount
of data that is used to define the image. When the process is reversed,
the digital image is restored. Compression algorithms are particularly
useful when storage space is at a premium, or when data transmission
speeds are critical. To achieve real savings in the file size, many compression
systems sacrifice some of the information the file contains. The object
is to make a compressed version of the image, so that once restored it
is as indistinguishable as possible from the original image.
Digitisation
When a photo is digitised, its colours are sampled and converted to binary
format. The smallest image element sampled is a pixel. A digitised image
can be better imagined if it is thought of as a map, where the information
concerning the colour value of any given pixel is retained as an XY
(Cartesian) co-ordinates on the map. When the map is converted back to
an image, the pixel regains its position and colour in relationship to
the other pixels making up the image.
The different types of image compression
Many different algorithms have been developed to compress file sizes. For
our purpose here, there is little point in considering all of them, but
we will define two broad categories: lossy compression and non-lossy compression.
A non-lossy compression scheme encodes the data so as to express it in
a more space-saving way. An example of such schemes is LZW compression,
an acronym for the names of its inventors: Lempel, Ziv and Welch, owned
by Unisys. Generally, LZW can compress a photo down to a ratio of 2:1,
and sometimes a bit more. Most non-lossy systems can only offer a small
savings in the file size; However, when a file is saved in this way, it
can be restored accurately, without loss in either image detail or quality.
Lossy compression, on the other hand, discards part of the data entirely.
When the image is restored, it has lost some of the information contained
in the original file. As we will see later, in most cases this is is not
as critical as it sounds.
Lossy compression, depending on the level of compression used, can reduce
the size of the image file to a ratio of 10:1 and even sometimes 20:1.
In digital photography, one lossy compression method has gained favour
over all others, a method devised by the Joint Photographic Experts
Group, and whose initials have become the name of the compression: JPEG.
How it works:
JPEG was created specifically for the transmission and storage of photographic
images. As a lossy compression algorithm it is made to remove a varying
amount of the data that originally made up the image. JPEG compression
is designed to take advantage of a particular aspect of human visual perception:
the fact that we perceive small colour changes less accurately than we
perceive small changes in brightness.
JPEG compression works in three main stages:
transformation
quantization (the lossy stage)
encoding
The first step transformation changes the data so it expresses
the image in terms of chrominance (colour
values) and luminance(brightness).
This step is critical for the next one: quantization.
Quantization is the step that actually discards some
of data, so that the data set needed to define the photo
is smaller.
The entire image is analysed by areas of 8 x 8 pixels, which make up
blocks of 64 pixels each. Through a complex mathematical process the chrominance found
in these blocks is "averaged" so that it requires less data
to express the values in the block. Expressed simply, this means that
the colour variations that existed in the original image are lessened.
Finally, an encoding step, which uses a process
similar to non-lossy compression, is applied to the data
resulting from the quantization so as to use even less space.
When the file is read back, the process is reversed, re-creating an image
that is similar to the original when seen through human eyes.
JPEG compression can achieve very high compression factors. Some of the
images below will demonstrate this. But, as a lossy compression system,
it means that when examined closely, the differences between the original
and the JPEG version can be observed. The images below are magnifications
and are used to demonstrate the effect of compression. At their normal
scale the changes made by the JPEG compression would be much less noticeable.
Some examples:
The image to the right exemplifies what the quantizing
step of the JPEG process does. Faint square blocks are visible
throughout. They show the areas in which the quantization
process took place. The process reduced the chrominance in
these areas, or in other words, the variations in small colour
changes throughout the image.
The result is a loss of image detail or sharpness. This can be hard to
detect when the image is seen at the scale at which it was intended to
be seen. However, a slight change of texture and colour detail is usually
visible.
NOTE:
the images both above and
below are in JPEG format, but at a low compression.
However, because they are taken from magnified views,
they still clearly exhibit what the effect compression.
The uncompressed image: Here, the image to the right is a 200% magnification of the
same wooden object as shown above. A much greater amount of subtle
colours is immediately visible. Also noticeable is a smoother edge
next to the black portion. With digital cameras, the option to
save uncompressed photos can be valuable when these contain a lot
detail. More and more, new digital cameras offer the possibility
of storing photos in an uncompressed format. With the cost of memory
cards dropping, and memory capacity increasing, it is becoming
advantageous to have this capability.
The effect on colour
Below, the same photo below has been saved in two formats. One is very
compressed using JPEG compression, the other uses no compression. To show
the differences both images were opened in a photo editing program and
magnified 300%. A screen capture utility was then used to create these
images. To avoid adding further artefacts, they were then saved in GIF
format. The GIF compression reduces the colour palette of the image to
reduce its file size. Since this image actually contains few colours (blues,
greens and black), the GIF format has a minimal impact on its appearance.
This image shows the effect of the quantizing done by JPEG. For one, the
blue sky is visibly more even in colour than in the image at right, and
exhibits the blockiness created by the quantization. For another, there
is a degradation in the sharpness of the edge of the beam.
This image still shows some variations in the blues of the sky. Similarly,
the edges of the beam are still quite distinct from the sky, not blending
into the sky the way they do in the image at left. The blurring effect
is often the most noticeable in JPEG compression.
The advantages and disadvantages of JPEG compression:
The single most important advantage derived from JPEG compression is the
reduction of file size. For digital cameras, this makes it possible to
store a greater number of images in a given amount of memory. The trade-off
is in image quality: the greater the compression, the greater the loss
in image quality.
JPEG compression is a very useful tool. It makes it possible to send high-quality
images over the Internet, and by e-mail, which would otherwise be too large
to transfer practically. Similarly, image files can be stored on a disk,
without having each take up megabytes of disk space.
The disadvantage of JPEG is that it does not do well with sharp edges,
such as the edges of the beam in the photo above, or with text, which also
presents clear boundaries. It tends to smudge the boundaries in the image.
JPEG compression reduces the colour range of an image. In some situations,
and with high compression, the overall tone of the image can be affected,
emphasising a particular colour.
The effect of JPEG compression on text:
The examples above show the effect of JPEG compression
on text or sharp boundaries. Note that, once again, these
images are considerably magnified. Most of the imperfections
visible in these images would be much less perceptible
at the correct scale. However, they do show the loss of
detail that occurs with lossy compression.
Our opinion
Readers of megapixel.net may have noticed that
we tend to stress the availability of a "no compression" option
when we review cameras that offer it. The reason is simple:
we have found that looking at images as they are, generated
by the lens and sensor of a camera, and without any compression,
tells us much more about the camera's quality than looking
at compressed images.
While compression offers many advantages in digital photography, the
option to get precisely what was captured by the lens and
sensor of a camera should not be ignored. Not only does it help in deciding
whether the camera is able to generate the image quality a potential
purchaser requires, but some images, depending on the subject, can show
a great deal more detail when left uncompressed. If only for these two
things, a "no compression" option should not be discounted.