## Representing images

 Quick links 3.3.1 Number bases 3.3.2 Converting number bases 3.3.3 Units of information 3.3.4 Binary arithmetic 3.3.5 Character encoding 3.3.6 Representing images 3.3.7 Representing sound 3.3.8 Data compression

### Syllabus content

Understand what a pixel is and be able to describe how pixels relate to an image and the way images are displayed.

Students should know that the term pixel is short for Picture Element. A pixel is a single point in a graphical image.

VDUs display pictures by dividing the display screen into thousands (or millions) of pixels, arranged into rows and columns.

Describe the following for bitmaps:

• size in pixels

• colour depth.

The size of an image is expressed directly as width of image in pixels by height of image in pixels using the notation width x height.

Colour depth is the number of bits used to represent each pixel.

Describe how a bitmap represents an image using pixels and colour depth.

Students should be able to explain how bitmaps are made from pixels.

Describe using examples how the number of pixels and colour depth can affect the file size of a bitmap image.   Students should be able to describe how higher numbers of pixels and higher colour depths can affect file size and should also be able to use examples.

Calculate bitmap image file sizes based on the number of pixels and colour depth.

Students only need to use colour depth and number of pixels within their calculations.

Size in bits = W x H x D

Size in bytes = W x H x D /8

• W = image width;
• H = image height;
• D = colour depth in bits

Convert binary data into a black and white image.   Given a binary pattern that represents a black and white bitmap, students should be able to draw the resulting image as a series of pixels.

Convert a black and white image into binary data   Given a black and white bitmap, students should be able to write down a bit pattern that represents the image.

## Starter 1

Convert 257 and 0.375 to binary

Convert AAF5 to decimal (You will need a calculator!)

Convert 0111 1101 to Decimal

## Explanation

### Digital images

Images can be either bitmaps (a series of dots) or vectors ( a collection of lines and curves).

#### Pixels

These are the dots on the screen - short for "picture element".

#### Resolution

The more pixels per inch in a screen the better the resolution. A bigger screen would have to have more pixels to have the same resolution as a smaller screen.

When the image is expanded the pixels get larger and can be seen. Even an image this small (60 x 60 pixels) takes 55 Kb to store.

#### Memory

The larger the number of pixels the more memory is required to store the screen image.

Interestingly both the images above use the same amount to memory to store them (55Kb) its just the larger one has been stretched.

#### JPEG, GIF, PNG

Common file formats for bitmaps are jpeg, gif and png. When you zoom in or out the number of pixels remains the same, its just the size of the pixel shrinks or grows. Bitmap images do not stretch well. How many times have you seen a PowerPoint slide with a stretched image in it?

Each colour is stored as a binary number so a black and white image is simply a series of 0s and 1s black is a 1 and white is a 0.

#### Vector images

vector image uses 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.

#### Scalable Vector Graphics (SVG)

One of the most common vector file formats is scalable vector graphics (SVG). SVG is an open standard for vector graphics.

It is possible to edit SVG images using numbers to change the size and colour variables in HTML. This is often used for graphs and infographics in HTML5.

Vector graphics are used in:

• AutoShapes in Microsoft Office
• animated movies
• encapsulated postscript (EPS)
• animation programmes such as Blender and Adobe After Effects
• image manipulation programmes such as Adobe Photoshop and GIMP
• Adobe portable document format (PDF)
• Windows meta-file (WMF)

#### Image display

When a monitor or a printer displays a vector image, it is rasterised - converted into a grid of pixels. Regardless of the file type, an image will always be outputted onto a screen or printed in pixels.

#### Colour depth

The colour depth of an image is measured in bits. The number of bits indicates how many colours are available for each pixel. In the black and white image, only two colours are needed. This means it has a colour depth of 1 bit.

A 2-bit colour depth would allow four different values: 00, 01, 10, 11. This would allow for a range of colours such as:

Binary code   Colour
00   White
01   Light grey
10   Dark grey
11   Black

The greater the colour depth (bits per pixel), the more colours are available.

Colour depth   Available colours
1-bit   2 = 2
2-bit   2x2 = 4
3-bit   2x2x2 = 8
4-bit   2x2x2x2 = 16
5-bit   2x2x2x2x2 = 32
6-bit   2x2x2x2x2x2 = 64
7-bit   2x2x2x2x2x2x2 = 128
8-bit   2x2x2x2x2x2x2x2x2x2 = 256

Most computer systems and digital cameras use 24-bit images. 24 in binary is 1111 1111 1111 1111 1111 1111. This means there are over 16 million possible colours per pixel.

Resolution is a measure of pixel density, usually measured in dots per inch (dpi). Images on websites usually have a resolution of 72 dpi. This means that a 1-inch square contains a grid of pixels that is 72 pixels wide by 72 pixels high. 72 x 72 = 5184 pixels per square inch.

High quality printed images in books and magazines have a higher resolution than computer screens. Magazines often use either 300 dpi or even 600 dpi.

#### Resolution

The resolution of an image is measured in dots per inch (dpi), also known as pixels per inch (ppi). The dpi determines the amount of detail the image has.

If the final image is to be displayed on a computer (web/CD-Rom etc), the resolution should be 72-96 dpi. If the final image is in print, then it is usually best to set the dpi to the highest number you can - around 300 dpi. If you wish to enlarge an image to be used on the web or for print, always scan it at the highest dpi you can, and then enlarge the image size in your graphics software (eg Photoshop). You can then save it to the appropriate file format.

• filename
• file format - eg JPEG, GIF or PNG
• dimensions
• resolution
• colour depth
• time and date the image was last changed
• camera settings when the photo was taken
• GPS

## Exercise

### Making a colour image in Excel

Here is a two bit binary code for encoding an image.

Binary code   Colour
00   White
01   Light grey
10   Dark grey
11   Black

Using Excel create a graphics editor.

Open Excel and select from A1 to N24; right click on the selected space and choose "Format Cells"; change the format to be "Text"

Select the same space and choose "Conditional Formatting" then "Highlight Cell Rules" then "Equal to..."

Type in "00" (Double Zero, including the quotations that tells Excel that this is text not a number so that the leading zero does not vanish) and change the fill and colour to be white writing on a white background.

Repeat this for light grey, dark grey and black.

When you have done this for all four shades then click on "Conditional Formatting" and then "Manage Rules ... " and you should see this:

Now using the numbers you can draw an image in four shades.

## Starter 2

Here is a 4 x 4 1-bit image

Given the convention that white is 0 and black is one, convert this to a bit pattern.

Write this bit pattern as one 16-bit binary number and convert it to decimal.

If you write the number as 4 4-bit binary numbers show that this is 01A4 in hex.

## Exercise

Here are four more 4 x 4 1-bit images.

In each case, given the convention that white is 0 and black is one, convert this to a bit pattern.

If you write the numbers as 4 4-bit binary numbers calculate the four digit hex number for each pattern. (Hint: I would use Excel to help - If you do can you save your working in the usual folder so that it can e be printed please.)

Create the 4 x 1-bit image from the following four character hex numbers

1) 7571

2) 8EAE

3) E8E8

## Extension

1) Here is an 8 x 8 1-bit image.

Generate the bit pattern first as a series of binary digits and then as a series of hex digits.

2) Generate the 1-bit 8 x 8 image from the following hex value

3C 24 04 08 08 10 10 20

3) How many bytes of storage are required to store this 8 x 8 image? (Hint:You could use the formula given at the top of the page in the syllabus content.)

Data compression

Summarise this video in your exercise book.

## Exercise

Summarise this video in your exercise book, you can ask to borrow the headphones when they are required.

This is a longer (slightly American) video that explains a little of the technical detail of lossy and lossless compression. You can ask to borrow the headphones when they are required.