1.1.2 Images
1.1.2 Images
1.1.2 Images
1.1.2 IMAGES
Representing images
Images also need to be converted into binary in order for a computer to process them so that they can be seen on our
screen. Digital images are made up of pixels. Each pixel in an image is made up of binary numbers.
If we say that 1 is black (or on) and 0 is white (or off), then a simple black and white picture can be created using
binary.
To create the picture, a grid can be set out and the squares coloured (1 – black and 0 – white). But before the grid can
be created, the size of the grid needs be known. This data is called metadata and computers need metadata to know the
size of an image. If the metadata for the image to be created is 10x10, this means the picture will be 10 pixels across
and 10 pixels down. This example shows an image created in this way:
Adding colour
The system described so far is fine for black and white images, but most images need to use colours as well. Instead of
using just 0 and 1, using four possible numbers will allow an image to use four colours. In binary this can be
represented using two bits per pixel:
00 – white
01 – blue
10 – green
11 – red
While this is still not a very large range of colours, adding another binary digit will double the number of colours that
are available:
1 bit per pixel (0 or 1): two possible colours
2 bits per pixel (00 to 11): four possible colours
3 bits per pixel (000 to 111): eight possible colours
4 bits per pixel (0000 – 1111): 16 possible colours
…
16 bits per pixel (0000 0000 0000 0000 – 1111 1111 1111 1111): over 65 0000 possible colours
The number of bits used to store each pixel is called the colour depth. Images with more colours need more pixels to
store each available colour. This means that images that use lots of colours are stored in larger files.
Image quality
Image quality is affected by the resolution of the image. The resolution of an image is a way of describing how tightly
packed the pixels are.
https://www.facebook.com/groups/OAComputers/ Page 1
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
In a low-resolution image, the pixels are larger so fewer are needed to fill the space. This results in images that look
blocky or pixelated. An image with a high resolution has more pixels, so it looks a lot better when you zoom in or
stretch it. The downside of having more pixels is that the file size will be bigger.
Bitmaps
A large part of using modern computers involves sending pictures and films to each other, along with using a graphical
user interface. All of this involves computers saving and processing images. This section will cover the two main image
types: vector and bitmap, along with some compression techniques.
Bitmap Graphics - a collection of pixels from an image mapped to specific memory locations holding their binary
colour value.
Pixel - the smallest possible addressable area defined by a solid colour, represented as binary, in an image.
Resolution
Image Resolution - how many pixels an image contains per inch/cm
Screen Resolution - the number of pixels per row by the number of pixels per column
https://www.facebook.com/groups/OAComputers/ Page 2
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
https://www.facebook.com/groups/OAComputers/ Page 3
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
Colour depth - The number of bits used to represent the colour of a single pixel
Colour
1 bit 2 bit 4 bit
depth
Example
stores 4 colours:
Description Mono-chrome, only stores RGB (70,61,55), RGB(79,146,85) Stores limited colours
black and white RGB(129,111,134),
RGB(149,146,166)
Number of
colours
per pixel
It seems pretty obvious that the higher the colour depth, the closer the picture will look to reality. Why then don't we
just ramp up the colour depth on every image that we make? The answer should be obvious, for a fixed resolution, the
higher the colour depth, the larger the file size.
https://www.facebook.com/groups/OAComputers/ Page 4
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
If the first image uses 1 bit to store the colour for each pixel, then the image size would be:
Number of Pixels * Colour Depth = Image Size
67500 * 1 bit = 67500 bits
For the second image uses 2 bits to store the colour for each pixel, then the image size would be:
Number of Pixels * Colour Depth = Image Size
67500 * 2 bit = 135000 bits
Vector graphics
Vector graphics are graphics in which the image is represented in a mathematical fashion. What this allows one to do is
to zoom in an image to infinite precision. They are ideal for situations in which an image might be used at various
resolutions and dimensions.
Raster graphics
Raster graphics are of a fixed dimension, somewhat like a grid pattern with specified values at each point. These
graphics are the default for things from the real world (IE, scanned images, photographs, etc). They are ideal for use
when an image will only be used once, and will never need to be enlarged, or if portions are coming from a photograph
or other real-world image.
https://www.facebook.com/groups/OAComputers/ Page 5
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
The resolution of the photographs is reduced from A to E. Photographs A and B are very sharp whilst photograph D is very
fuzzy and E is almost unrecognisable. This is the result of changing the number of PIXELS per centimetre used to store the
image (that is, reducing the PICTURE RESOL TION).
When a photographic file undergoes file compression, the size of the file is reduced. The trade-off for this reduced file
size is reduced quality of the image. One of the file formats used to reduce photographic file sizes is known as JPEG.
This is another example of lossy file compression. As with MP3 format, once the image is subjected to the jpeg
compression algorithm, a new file is formed and the original file can no longer be constructed. Jpeg will reduce the R
W BITMAP image by a factor of between 5 and 15 depending on the quality of the original.
An image that is 2048 pixels wide and 1536 pixels high is equal to 2048 × 1536 pixels; in other words, 3 145 728 pixels. This
is often referred to as a 3-megapixel image (although it is obviously slightly larger). A raw bitmap can often be referred to as
a TIFF or BMP image (file extension .TIF or .BMP). The file size of this image is determined by the number of pixels. In the
previous example, a 3-megapixel image would be 3 megapixels × 3 colours. In other words, 9 megabytes (each pixel occupies
3 bytes because it is made up of the three main colours: red, green and blue). TIFF and BMP are the highest image quality
because, unlike jpeg, they are not in a compressed format. The same image stored in jpeg format would probably occupy
between 0.6 megabytes and 1.8 megabytes.
Jpeg relies on certain properties of the human eye and, up to a point, a certain amount of file compression can take
place without any real loss of quality. The human eye is limited in its ability to detect very slight differences in
brightness and in colour hues. For example, some computer imaging software boasts that it can produce over 40 million
different colours – the human eye is only able to differentiate about 10 million colours.
https://www.facebook.com/groups/OAComputers/ Page 6
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
Header
Palette
Bitmap Index
Palette 1
File Identifier
File Version
Compression Type
X Origin of Image
Y Origin of Image
Text Description
Unused Space
Later in this chapter we will present examples of headers from several actual formats, containing fields similar to
those presented above.
File Identifier
A header usually starts with some sort of unique identification value called a file identifier, file ID, or ID value. Its
purpose is to allow a software application to determine the format of the particular graphics file being accessed.
ID values are often magic values in the sense that they are assigned arbitrarily by the creator of the file format. They
can be a series of ASCII characters, such as BM or GIF, or a 2- or 4-byte word value, such as 4242h or 596aa695h, or
any other pattern that made sense to the format creator. The pattern is usually assumed to be unique, even across
platforms, but this is not always the case, as we describe in the next few paragraphs. Usually, if a value in the right
place in a file matches the expected identification value, the application reading the file header can assume that the
format of the image file is known.
Three circumstances arise, however, which make this less than a hard and fast rule. Some formats omit the image file
identifier, starting off with data that can change from file to file. In this case, there is a small probability that the data will
accidentally duplicate one of the magic values of another file format known to the application. Fortunately, the chance of
this occurring is remote.
https://www.facebook.com/groups/OAComputers/ Page 7
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
The second circumstance can come about when a new format is created and the format creator inadvertently
duplicates, in whole or in part, the magic values of another format. In case this seems even more unlikely than
accidental duplication, rest assured that it has already happened several times. Probably the chief cause is that,
historically, programmers have borrowed ideas from other platforms, secure in the belief that their efforts would be
isolated behind the "Chinese Wall" of binary incompatibility. In the past, confusion of formats with similar ID fields
seldom came about and was often resolved by context when it did happen. Obviously this naive approach by format
creators is no longer a survival skill. In the future, we can expect more problems of this sort as users, through local area
networking and through advances in regional and global interconnectivity, gain access to data created on other
platforms.
This third circumstance comes about when a vendor--either the format creator or format caretaker or a third party--
changes, intentionally or unintentionally, the specification of the format, while keeping the ID value specified in the
format documentation. In this case, an application can recognize the format, but be unable to read some or all of the
data. If the idea of a vendor creating intentional, undocumented changes seems unlikely, rest assured that this, too, has
already happened many times. Examples are the GIF, TIFF, and TGA file formats. In the case of the GIF and TGA
formats, vendors (not necessarily the format creators) have extended or altered the formats to include new data types.
In the case of TIFF, vendors have created and promulgated what only can be described as convenience revisions,
apparently designed to accommodate coding errors or application program quirks.
File Version
Following the identification value in the header is usually a field containing the file version. Naturally enough,
successive versions of bitmap formats may differ in characteristics such as header size, bitmap data supported, and
color capability. Once having verified the file format through the ID value, an application will typically examine the
version value to determine if it can handle the image data contained in the file.
The number of bits per pixel indicates the size of the data needed to describe each pixel per color plane. This may also
be stored as the number of bytes per pixel, and is more properly called pixel depth. Forgetting the exact interpretation
of this field when coding format readers is a common source of error. If the bitmap data is stored in a series of planes,
the number of color planes indicates the number of planes used. Often the value defaults to one. There is an increasing
tendency to store bitmaps in single-plane format, but multi-plane formats continue to be used in support of special
hardware and alternate color models.
The number of bits in a line of the image can be calculated by multiplying the values of number of bits per pixel,
number of pixels per line, and number of color planes together. We can determine the number of bytes per scan line by
then dividing the resulting product by eight. Note that there is nothing requiring number of bits per pixel to be an
integral number of 8-bit bytes.
Compression Type
If the format supports some sort of encoding designed to reduce the size of the bitmap data, then a compression type field
will be found in the header. Some formats support multiple compression types, including raw or uncompressed data. Some
format revisions consist mainly of additions or changes to the compression scheme used. Data compression is an active
field, and new types of
https://www.facebook.com/groups/OAComputers/ Page 8
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
compression accommodating advances in technology appear with some regularity. TIFF is one of the common
formats which has exhibited this pattern in the past.
x and y Origins
x origin of image and y origin of image specify a coordinate pair that indicates where the image starts on the output
device. The most common origin pair is 0,0, which puts one corner of the image at the origin point of the device.
Changing these values normally causes the image to be displayed at a different location when it is rendered.
Most bitmap formats were designed with certain assumptions about the output device in mind, and thus can be said to
model either an actual or virtual device having a feature called the drawing surface. The drawing surface has an
implied origin, which defines the starting point of the image, and an implied orientation, which defines the direction in
which successive lines are drawn as the output image is rendered. Various formats and display devices vary in the
positioning of the origin point and orientation direction. Many place the origin in the upper-left corner of the display
surface, although it can also appear in the center, or in the lower-left corner. Others, although this is far less common,
put it in the upper- or lower-right corner.
Orientation models with the origin in the upper-left corner are often said to have been created in support of hardware,
and there may be some historical and real-world justification for this. People with backgrounds in mathematics and
the natural sciences, however, are used to having the origin in the lower-left corner or in the center of the drawing
surface. You might find yourself guessing at the background of the format creator based on the implied origin and
orientation found in the format. Some formats include provisions for the specification of the origin and orientation.
An image displayed by an application incorporating an incorrect assumption about the origin point or orientation
may appear upside down or backwards, or may be shifted horizontally some fraction of the width of the drawing
surface on the output device.
Sometimes the header will contain a text description field, which is a comment section consisting of ASCII data
describing the name of the image, the name of the image file, the name of the person who created the image, or the
software application used to create it. This field may contain 7-bit ASCII data, for portability of the header
information across platforms.
Unused Space
At the end of the header may be an unused field, sometimes referred to as padding, filler, reserved space, or reserved
fields. Reserved fields contain no data, are undocumented and unstructured and essentially act as placeholders. All we
know about them are their sizes and positions in the header. Thus, if the format is altered at some future date to
incorporate new data, the reserved space can be used to describe the format or location of this data while still
maintaining backward compatibility with programs supporting older versions of the format. This is a common method
used to minimize version problems--creating an initial version based on a fixed header substantially larger than
necessary. New fields can then be added to reserved areas of the header in subsequent revisions of the format without
altering the size of the header.
Often format headers are intentionally padded using this method to 128, 256, or 512 bytes. This has some
implications for performance, particularly on older systems, and is designed to accommodate common read and write
buffer sizes. Padding may appear after the documented fields at the end of the header, and this is sometimes an
indication that the format creator had performance and caching issues in mind when the format was created.
Reserved fields are sometimes only features left over from early working versions of the format, unintentionally frozen
into place when the format was released. A vendor will normally change or
https://www.facebook.com/groups/OAComputers/ Page 9
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885
1.1 INFORMATION REPRESENTATION AHMED THAKUR
1.1.2 IMAGES
extend a file format only under duress, or as a rational response to market pressure typically caused by an
unanticipated advance in technology. In any case, the upgrade is almost always unplanned. This usually means that
a minimal amount of effort goes into shoehorning new data into old formats. Often the first element sacrificed in
the process is complete backward compatibility with prior format versions.
https://www.facebook.com/groups/OAComputers/ Page 10
COMPUTER SCIENCE
9608 ahmed_thakur@hotmail.com, 0300-8268885