Image Processing - AL Computer Science
Image Processing - AL Computer Science
2 Images
Images can be broadly categorized as one of two types i.e. bitmap or vector
Bitmap Images
Bitmap also known as raster images are “digital photographs”, they are the most common form
used to represent natural images and other forms of graphics that are rich in detail. Common
bitmap image file types include JPEG, GIF and PNG.
Before we learn how bitmap images are stored, let us first learn some terms
Pixel: (Picture Element). It is the smallest item of information in an image. It is often represented
visually using dots or squares.
Image Resolution: tells us how many pixels an image contains per unit measurement
(inch/cm). The more pixels used to produce an image the more clearer the image can be i.e. the
higher the resolution, the more pixels are used and therefore the clarity of the picture is higher.
Screen resolution: this tell us how many pixels the screen can display horizontally and
vertically. For example an image with a resolution of 800 by 600 pixels (800 x 600) would have
800 pixels in each row and 600 of these rows
Colour Depth: The number of bits used to represent the colour of a single pixel
Bitmap images are organised as a grid of pixels (short for 'picture elements'). The term bitmap
comes from the concept that the bit pattern which makes up the file are mapped to an area in
the main memory.
Each colour of an image is stored as a binary number. You need a binary value for each
different colour. Each pixel will be a particular colour. Each pixel's colour will be represented as
a binary pattern. The contents of the bitmap file will be this sequence of binary colour codes.
1
It is common for colours to be recorded by quantity of Red, Green and Blue (RGB) and this is
stored using 3 bytes per pixel – so we would need 105 bytes to store the image. 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.
Bitmap images can be encoded in several ways
Bitmap Pixel Explanation
encoding representation
Monochrome 1 bit Only two colours needed (Black and white).
One byte can store eight pixels.
16 colour 4 bits Each byte can store two pixels.
256 colour 8 bits (1 byte) Each byte can store one pixel.
24-bit colour 24 bits (3 bytes) The number of different colours possible is
224 (16,777,216).
.
When zooming in or enlarging a bitmap image, the pixels are stretched and made into larger
blocks. This is called the staircase effect. This is why bitmap images appear as poor quality
when enlarged too much.
Bitmaps also have the drawback that they have a larger file size.
Exercise 1
a) What is the resolution of a 30 pixel by 40 pixel image?
b) If I have an image resolution of 700 pixels, and the height is 35, what is the width of the
image?
Metadata - This is a fancy term for 'data about data'. In other words metadata describes the
structure of the data file. Meta data is usually located right at the start of the file.
When a media player opens the file it looks for the metadata which describes the format of the
file e.g. the file type, how many horizontal pixels are there, how many vertical pixels and the
colour depth of the file. Armed with this information the media player reads the file and correctly
displays the image.
The bitmap-file header contains information about the file type, and file size; it also specifies the
dimensions, the resolution, the compression type (if any), and color format for the bitmap.
The color table contains as many elements as there are colors in the bitmap.
The clarity with which a bitmap image is viewed on a monitor screen will depend on two factors:
Resolution of the image. A small image made up from a large number of pixels will
produce a sharper display.
Screen resolution - the number of pixels which can be viewed horizontally and vertically
on the screen.
EXERCISE 2
1) For a colour depth of 8 bits, how many colours could each pixel store?
2) To represent 1024 colours per pixel, what colour depth would I need?
3) For an image of 30 by 40 pixels, what would the file sizes be for the following colour depths:
4 bits
4) How many colours can each pixel store if it has a colour depth of 4bits?
5) How many bits does the colour depth have to be if we want to store 64 colours per pixel?
6) How many bits would an image be that has a size of 20 by 30 pixels, with each pixel able to
display 8 colours?
7) When might one want to decrease the colour depth for an image?
Vector Graphics
A vector image uses drawing objects (scalable shapes) such as straight lines and curves,
using coordinates and geometry to precisely define the parts of the image. It is more efficient
than bitmaps at storing large areas of the same colour because it does not need to store every
pixel as a bitmap does.
Vector graphics can be scaled without losing resolution. They can be enlarged or reduced in
size - but the file size will stay almost exactly the same.
One of the most common vector file formats is scalable vector graphics (SVG).
Vector graphics are made up of objects and their properties. An (drawing) object is a
mathematical or geometrically defined construct such as a rectangle, line or circle
A/L 2020 – Unit 1.1.2 3
<rect ... />
<line ... />
<circle ... />
Each of these objects has properties to tell you the size, colour, position etc.
Take a look at the next example to see how drawing lists are built from objects and properties.
Image
<rect
width="100"
height="80"
x="0" y="70"
fill="green" />
<rect x="14" y="23" <line
<circle cx="100"
width="250" x1="5" y1="5"
cy="100" r="50"
Drawing height="50" x2="250" y2="95"
fill="red"
fill="green" stroke="red" />
List stroke="black" stroke-
stroke="black" stroke- <circle
width="3" />
width="1" /> cx="90" cy="80"
r="50"
fill="blue" />
<text x="180" y="60">
Un texte
</text>
<line
x1="0" y1="0"
x2="6" y2="6"
stroke="red" />
<rect
width="4" height="4"
x="1" y="1"
fill="yellow"
stroke="green"
stroke-width=1 />
<line
x1="6" y1="0"
x2="0" y2="6"
stroke="black" />
Exercise 4
1. You wish to create an image that will be made into a giant banner for the side of a building.
What type should you use and why?
2. You wish to create an image that will be used in a game, that will run on a mobile phone and
a home console. What type should you use and why?
3. You want to take an image of a local cat stuck in a tree. What type should you use and why?