Fundamentals of Data Representation Graphics Compression Computer Science

































- Slides: 33

Fundamentals of Data Representation Graphics & Compression Computer Science

Bitmaps • Binary needs to be able to represent images • Different ways of doing this • Simplest is using bitmaps Bitmap Created when pixels of an image are mapped to positions in memory that store binary codes representing colour of each pixel 2 Map of bits A spatially mapped array of bits Graphics & Compression Pixel Smallest addressable area or smallest solid block of colour in an image

Bitmaps • Each individual pixel represents a single colour • Created from binary code • Different images can have different amounts of pixels – More pixels usually leads to a better image 3 Graphics & Compression

Bitmaps • Changing this resolution can lead to drastic effects in the image – Typically shown as Pixel Width x Pixel Height Bitmap Images JPEG, TIFF, PNG, and GIF Not referred to as bitmaps, because of internal compression 4 Graphics & Compression

Bitmaps These binary codes set pixel colour Binary codes mapped to a bitmapped image 5 Graphics & Compression

Colour Depth • A bitmap is made up of pixels • Pixels are made up of binary • We can change how large the binary numbers are per pixel • This changes the amount of available colours – Called colour depth 6 Graphics & Compression

Colour Depth • Here are some examples of the same image – Just using different colour depths 7 Graphics & Compression

Colour Depth • They represent the number of bits per pixel 1 -bits 8 12 -bits 24 -bits Graphics & Compression 32 -bits

Colour Depth • Binary values are encoded to create a single colour • They typically follow the same format • Take this example: 0110 9 1101 Graphics & Compression 0110

Image Memory Size • As pixels are made up of binary, images have a total size – Called memory size • Calculated from the following – The result is in bytes 10 Graphics & Compression

• Calculate the memory size of the following bitmap images – Each row uses a different colour depth – Use an ‘appropriate’ unit for each answer 11 1 -bit 800 x 600 1280 x 720 12 bit 800 x 600 1280 x 720 24 bit 800 x 600 1280 x 720 Graphics & Compression

Bitmap file metadata • If the files for which the memory size was calculated in previous slide, are created in graphics software – File size calculated manually will be smaller than calculated by computer • Why? – Because computer has to store some other information about its bitmap data inside the file. – In a section called Header 12 Graphics & Compression

Bitmap file metadata • The header part of the bitmap file contains information about the bitmap data part of the file • For example – Image width – Image height – Colour depth – Compression technique used • Known as Metadata – As it is data about data 13 Graphics & Compression

Vector Graphics • The other image type is vector • Does not store pixel data in a file • Instead, stores objects in a file – The image is then recreated from those objects • Objects include circles, rectangles, brush strokes, etc. 14 Graphics & Compression

Vector Graphics • Bitmap images have a big problem – ‘Zooming in’ causes pixels to become more visible – Makes a pixelated effect • Vector images don’t have this – The images are recreated for any zoom level – Based off the stored objects – So no pixelation 15 Graphics & Compression

Vector Graphics Drawing list List of drawing commands that recreate a vector graphic 16 Graphics & Compression

Vector Graphics • The objects in a vector image have different properties – Change how these objects will look in the image Vector object properties Position Curve (mathematical description) Size Filled? Direction (endpoint coordinates) Fill colour Line thickness Border? Font size and typeface Border colour Shading Border thickness 17 Graphics & Compression

Bitmap vs Vector Graphics Bitmap Advantage • Great at representing images with ‘continuous tones’ (like photographs Vector Advantages • Usually take less memory (as objects are stored, not individual pixels) • Do not pixelate on scaling • Can be loaded faster over the internet (due to smaller memory size) 18 Graphics & Compression

Compression • Saving high-quality images in their raw pixel format can be quite memory costly Full HD Image (1920 x 1080), with a 32 -bit colour depth Memory Size: 8. 294 MB • So, we need to work out a way of reducing memory size, but keeping most of the image quality 19 Graphics & Compression

Compression • There are two types of compression techniques – Lossy – Lossless • They relate to image quality – Lossy compression: some image quality is lost – Lossless compression: no image quality is lost 20 Graphics & Compression

Lossless Compression • Lossless compression is great when the whole data is needed – I. e. for computational needs (using images as training data for a computer) • One of the more basic lossless compression techniques is Run-Length Encoding • Works best on images with long runs of continuous colour 21 Graphics & Compression

Run-Length Encoding • There are different versions of Run-Length Encoding • Simplest method does the following Storing an image with the following colours: rrrrbbgg bbbggggg rrrr 22 We can compress that to: (4, r) (2, b) (2, g) (3, b) (5, g) (8, r) Graphics & Compression

• Perform the Run-Length Compression technique on the following strings aaaaabbbbbccccccbbbbbbccccccaaaacccccc bbbcccccbbbbaaaaaaccccbbbbaaacccc 23 Graphics & Compression

Dictionary Compression • Run-Length Encoding is a style of repetitive sequence suppression It takes long, repeating sequences and converts it into a small piece of data • There is another technique we’ll look at (but not do ourselves) Dictionary compression • This is a branch of techniques that all do the same thing Substitute the original data with smaller data (thus compressing it) 24 Graphics & Compression

Dictionary Compression • To generalise these techniques, they all follow a similar pattern Analyse the original data to look for commonly occurring data (and patterns of data) Come up with a simple substitute Create a table (the dictionary) that lists the substitute next to the pattern Replace all occurrences of the pattern with the substitute • To decompress the data, simply replace the substitute with the pattern in the dictionary 25 Graphics & Compression

Dictionary Compression Example The following text is the source (uncompressed). I don’t know what I don’t know, and I know that I know nothing. Know what I mean? This can be compressed to the following. < @ <, and > that > nothing. Know @ I mean? 26 Graphics & Compression Symbol Pattern < I don’t know > I know @ what

Lossy Compression • Lossy compression achieves the same result as lossless compression – Usually gets better results • However, detail in images can suffer greatly 27 Graphics & Compression

Lossy Compression • Clarity – Brightness over relatively large areas – Gradual changes in pixel brightness over many pixels • Deficiency – Exact strength of high-frequency brightness variation – Drastic changes in pixel brightness over narrow range of pixels • Compression – Greatly reduce information in high-frequency components – Exploit eye sensitivity, by reducing bits per pixel for least sensitive colours (blue) 28 Graphics & Compression

Different Image Types • JPEG: Joint Photographic Experts Group – Specifies: Codec and File format – Lossy compression • Loss of visual quality – Photographic images 29 Graphics & Compression

Different Image Types • GIF: Graphics Interchange Format – 8 bit per pixel bitmap • 256 colours (24 -bit RGB colour space) • 1 byte per pixel – Value is address of cell in 256 colour table – LZW lossless compression • Reduces file size • Doesn’t degrade visual quality – Wide web use • Graphics and logos with solid colour • Supports animations – Different palette of 256 colours for each frame 30 Graphics & Compression

Different Image Types • PNG: Portable Network Graphics – Improve on and replace GIF – 24 -bit RGB – Lossless compression – Web transfers • SVG: Scalable Vector Graphics – 2 D graphics and XML – Text based – Web page vector graphics 31 Graphics & Compression

• Exam style questions – Sample paper 2 • Question 5 – Graphics + Compression – Comp 1 June 2012 • Question 5 – Graphics • Time permitting
