Administrative Notes February 14, 2017 • Feb 17: In the News call #2 • For your lab this week, please have ready a colourful picture you’d like to use (or you can just use the default picture provided) • Conversion tables now updated (see next two slides, also updated in Data Representation Part 1 final slides) Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Decimal to binary conversion (leading 0’s, shown in gray, are useful for some conversions) decimal binary decimal binary 00 0000 08 1000 01 0001 09 1001 02 0010 10 1010 03 0011 11 1011 04 0100 12 1100 05 0101 13 1101 06 0110 14 1110 07 0111 15 1111 Computational Thinking The image part with relationship 2 ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Decimal, binary, and hex (leading 0’s, shown in gray, are useful for some conversions) dec bin hex dec bin hex 00 0000 0 08 1000 8 01 0001 1 09 1001 9 02 0010 2 10 1010 A 03 0011 3 11 1011 B 04 0100 4 12 1100 C 05 0101 5 13 1101 D 06 0110 6 14 1110 E 07 0111 7 15 1111 F Computational Thinking The image part with relationship 3 ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Data Representation: Part 3 Image representation Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Learning goals Image representation • [CT Building Block] Define “bitmap image” and “pixel” and explain how to construct a bitmap image representation • [CT Building Block] Define “vector image” and explain how to construct a vector image representation • [CT Building Block] Compare and contrast the suitability of bitmap and vector representations for different uses of images Computational Thinking The image part with relationship 5 ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation (“bitmap” and “raster” are interchangeable) • A bitmap image representation is a 2D grid of square units called pixels (picture elements) • Each pixel has an associated RGB colour specification 000000 Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation The higher the resolution, i.e., number of pixels, of a bitmap representation, the higher the quality of the image that is produced (on a screen, paper, etc.) at a fixed scale https://f.vimeocdn.com/si/videoschool/app_icon_sizes_large.jpg Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation Choosing the right resolution depends on how the image will be viewed – large poster, laptop screen, phone, … Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation Choosing a good resolution depends on the scale at which it will be viewed Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation For a fixed resolution (number of pixels), we want a representation to specify a unique image, up to rescaling. For this reason, a bitmap image representation must specify • The number of rows and columns in the grid of pixels • The RGB colour specification of each pixel in the grid, say from top left to bottom right Computational Thinking The image part with relationship 10 ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation example 1 2 3 4 5 6 Purple = 5C009A 1 Green = 35A4A0 2 • 2 x 6 (grid dimensions: 2 rows and 6 columns) • 5C009A 35A4A0 5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A ( RGB colour specifications) 5C009A 5C009A Computational Thinking The image part with relationship ID rId20 was not 11 found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation example Suppose we change the grid dimensions • 3 x 4 • 5C009A 35A4A0 5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A Computational Thinking The image part with relationship ID rId20 was not 12 found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation example Clicker question: what image is specified? • 3 x 4 • 5C009A 35A4A0 5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A Computational Thinking The image part with relationship ID rId20 was not 13 found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation example Clicker question: what image is specified? A. B. C. 1 2 3 4 5 6 1 2 3 4 1 2 3 4 5 1 1 1 2 2 2 3 3 • 3 x 4 • 5C009A 35A4A0 5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A Computational Thinking The image part with relationship ID rId20 was not 14 found in the file. www.ugrad.cs.ubc.ca/~cs100
Fun with images Group exercise Draw the image represented as follows: • Grid dimensions: 7 (rows) x 6 (columns) • RGB pixel values: FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF 000000 FFFFFF FFFFFF 000000 FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF 000000 000000 FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF FFFFFF 000000 FFFFFF FFFFFF 000000 FFFFFF FFFFFF FFFFFF 000000 000000 FFFFFF FFFFFF Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
What your image should look like Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
That’s a lot of data for a little information • 252 hex digits are needed to specify the pixel colours, plus more are needed for the grid dimension specification • How might you represent an image with fewer hex digits? Discuss with your groups Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Representing images with fewer digits Student responses • If only two colours, use a system that indicates presence/absence of colour, e.g., 0 and 1 • This could be generalized to more than two colours, e.g. by having a table at the start of the specification listing the colours used in hex, along with the system for representing the colours • If there are “runs” of the same colour, just write the colour once, and also write the length of the run Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Would your method work for this image? Why or why not? Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Compressing bitmap images Two approaches • Lossless compression : collapse “runs" of identical intensities: the image looks exactly the same • Lossy compression : modify areas with similar colour to have the same colour: the image doesn't look exactly the same Computational Thinking The image part with relationship 20 ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation Lossless compression example 1 2 3 4 5 6 Purple = 5C009A 1 Green = 35A4A0 2 • 2 x 6 • 5C009A 1 35A4A0 1 5C009A 2 35A4A01 5C009A 7 ( ordered list of five “maximum-length” runs) Computational Thinking The image part with relationship ID rId20 was not 21 found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation Lossless compression group exercise 1 2 3 4 Purple = 5C009A 1 Green = 35A4A0 2 3 What is the compressed representation of this image? Computational Thinking The image part with relationship ID rId20 was not 22 found in the file. www.ugrad.cs.ubc.ca/~cs100
Bitmap image representation Lossless compression group exercise 1 2 3 4 Purple = 5C009A 1 Green = 35A4A0 2 3 What is the compressed representation of this image? • 3 x 4 • 5C009A 1 35A4A0 1 5C009A 3 35A4A01 5C009A 3 35A4A0 1 5C009A 2 ( ordered list of seven “maximum-length” runs) Computational Thinking The image part with relationship ID rId20 was not 23 found in the file. www.ugrad.cs.ubc.ca/~cs100
Compressing bitmap images Lossy JPEG is capable of a 10:1 compression without detectable loss of clarity simply by keeping the regions small Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
The image part with relationship ID rId15 was not found in the file. Display screen pixels • Typical display screens are also partitioned into pixels, each of which can show Red, Green and Blue lights 1 2 13 1 Pixel (1,13) of a 7 x 13 screen 7 Computational Thinking The image part with relationship ID rId20 was not found in the file. www.ugrad.cs.ubc.ca/~cs100
Recommend
More recommend