Administrative Notes February 14, 2017 Feb 17: In the News call - - PowerPoint PPT Presentation

administrative notes february 14 2017
SMART_READER_LITE
LIVE PREVIEW

Administrative Notes February 14, 2017 Feb 17: In the News call - - PowerPoint PPT Presentation

Administrative Notes February 14, 2017 Feb 17: In the News call #2 For your lab this week, please have ready a colourful picture youd like to use (or you can just use the default picture provided) Conversion tables now


slide-1
SLIDE 1

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

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)

slide-2
SLIDE 2

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

decimal binary 00 0000 01 0001 02 0010 03 0011 04 0100 05 0101 06 0110 07 0111 decimal binary 08 1000 09 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

Decimal to binary conversion

(leading 0’s, shown in gray, are useful for some conversions)

2

slide-3
SLIDE 3

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

dec bin hex 00 0000 01 0001 1 02 0010 2 03 0011 3 04 0100 4 05 0101 5 06 0110 6 07 0111 7 dec bin hex 08 1000 8 09 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F

Decimal, binary, and hex

(leading 0’s, shown in gray, are useful for some conversions)

3

slide-4
SLIDE 4

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Data Representation: Part 3

Image representation

slide-5
SLIDE 5

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Learning goals Image representation

5

  • [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

slide-6
SLIDE 6

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • A bitmap image representation is a 2D grid of

square units called pixels (picture elements)

  • Each pixel has an associated RGB colour

specification

000000

Bitmap image representation (“bitmap” and “raster” are interchangeable)

slide-7
SLIDE 7

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

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

Bitmap image representation

https://f.vimeocdn.com/si/videoschool/app_icon_sizes_large.jpg

slide-8
SLIDE 8

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Choosing the right resolution depends on how the image will be viewed – large poster, laptop screen, phone, …

Bitmap image representation

slide-9
SLIDE 9

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Choosing a good resolution depends on the scale at which it will be viewed

Bitmap image representation

slide-10
SLIDE 10

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

10

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

Bitmap image representation

slide-11
SLIDE 11

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Bitmap image representation example

  • 2 x 6 (grid dimensions: 2 rows and 6 columns)
  • 5C009A 35A4A0

5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A (RGB colour specifications) Purple = 5C009A Green = 35A4A0

11

5 3 4 2 6 1 1 2

slide-12
SLIDE 12

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

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

12

slide-13
SLIDE 13

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • 3 x 4
  • 5C009A 35A4A0

5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A

13

Bitmap image representation example Clicker question: what image is specified?

slide-14
SLIDE 14

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • 3 x 4
  • 5C009A 35A4A0

5C009A 5C009A 35A4A0 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A 5C009A

14

Bitmap image representation example Clicker question: what image is specified?

3 4 2 1 1 2 3 3 4 5 2 1 1 2 3 5 3 4 2 6 1 1 2

A. B. C.

slide-15
SLIDE 15

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

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

slide-16
SLIDE 16

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

What your image should look like

slide-17
SLIDE 17

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

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

slide-18
SLIDE 18

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

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

slide-19
SLIDE 19

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Would your method work for this image? Why or why not?

slide-20
SLIDE 20

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Compressing bitmap images Two approaches

20

  • 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

slide-21
SLIDE 21

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Bitmap image representation Lossless compression example

  • 2 x 6
  • 5C009A 1 35A4A0 1 5C009A 2 35A4A01 5C009A 7

(ordered list of five “maximum-length” runs) Purple = 5C009A Green = 35A4A0

21

5 3 4 2 6 1 1 2

slide-22
SLIDE 22

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Bitmap image representation Lossless compression group exercise

What is the compressed representation of this image? Purple = 5C009A Green = 35A4A0

22

3 4 2 1 1 2 3

slide-23
SLIDE 23

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Bitmap image representation Lossless compression group exercise

What is the compressed representation of this image? Purple = 5C009A Green = 35A4A0

23

3 4 2 1 1 2 3

  • 3 x 4
  • 5C009A 1 35A4A0 1 5C009A 3 35A4A01 5C009A 3

35A4A0 1 5C009A 2 (ordered list of seven “maximum-length” runs)

slide-24
SLIDE 24

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

JPEG is capable of a 10:1 compression without detectable loss of clarity simply by keeping the regions small

Compressing bitmap images Lossy

slide-25
SLIDE 25

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • Typical display screens are also partitioned into

pixels, each of which can show Red, Green and Blue lights

Display screen pixels

Pixel (1,13) of a 7 x 13 screen

The image part with relationship ID rId15 was not found in the file.

1 7 1 2 13

slide-26
SLIDE 26

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • The size of a screen “pixel” depends on how the

display’s resolution is set (measured as “dots per inch”, dpi)

  • The lower the resolution, the poorer the quality of

images displayed (at a given scale)

Display screen pixels

The image part with relationship ID rId5 was not found in the file.
slide-27
SLIDE 27

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • Bitmap images can be mapped on to screen pixels

in a natural way

Display screen pixels

The image part with relationship ID rId134 was not found in the file. 173 173 173 235 235 235 173 173 173 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235 173 173 235

1 2 3 4 5 1 2 3 4

173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 235 235 235 235 235 235 235 173 173 235 173 235 173 173 173 173

Pixel (1,2) of a 4x5 screen

slide-28
SLIDE 28

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

28

Suppose that a bitmap image is specified as a 10 x 20 grid of pixels and is displayed on a section of a screen with 100 x 200 pixels. How many screen pixels are used to display each image pixel?

Mapping a bitmap image to a screen Clicker question

slide-29
SLIDE 29

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

29

Suppose that a bitmap image is specified as a 10 x 20 grid of pixels and is displayed on a section of a screen with 100 x 200 pixels. How many screen pixels are used to display each image pixel?

  • A. 1
  • B. 10
  • C. 100
  • D. 1000

Mapping a bitmap image to a screen Clicker question

slide-30
SLIDE 30

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Great! But bitmaps are not the best choice for all images

Bitmap images can look “pixelated” when you zoom in Vector representations avoid this problem!

University

slide-31
SLIDE 31

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • A vector image representation is a collection of
  • Dot sequences (connected by lines or curves)
  • Simple shapes, such as rectangles or circles
  • The thickness of each line
  • The colour, or fill, of each line and closed area

Vector image representation (very basic, 2D)

slide-32
SLIDE 32

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Vector image representation

  • Let’s focus for now on one dot sequence, connected

by lines, and ignore colour

slide-33
SLIDE 33

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Vector image representation Discuss with your groups

  • Let’s focus for now on one dot sequence, connected

by lines, and ignore colour and thickness

  • What information should a vector representation

contain, to specify a unique image (at a given scale)?

slide-34
SLIDE 34

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

How to ensure that a vector representation specifies a unique image (up to scaling)?

Student responses:

  • Specify the points using coordinates, and also

specify which points are connected to each other

slide-35
SLIDE 35

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

4 3 2 1 0 1 2 3 4

We’ll use two axes

  • X axis numbered 0, 1, … from left to right
  • Y axis numbered 0, 1, … from bottom to top

X Y

Vector image representation Example

slide-36
SLIDE 36

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

4 3 2 1 0 1 2 3 4

X Y

first dot x,y second dot third dot fourth dot fifth dot

2,1 , 1,2 , 2,3 , 3,2 , 2,1

Vector image representation Example

slide-37
SLIDE 37

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

2,1, 2,3, 3,2, 1,2, 2,1

Which image is represented by the following sequence?

37

Vector image representation Clicker exercise

4 3 2 1

X Y

slide-38
SLIDE 38

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

4 3 2 1 0 1 2 3 4 4 3 2 1 0 1 2 3 4

2,1, 2,3, 3,2, 1,2, 2,1

  • A. B. C.

4 3 2 1 0 1 2 3 4 38

Vector image representation Clicker exercise

Which image is represented by the following sequence?

slide-39
SLIDE 39

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

first dot x,y,colour, thickness second dot

1 2,1, FF,6 , 1,2,00,2, …

Vector image representation Example

What if we also want to control line colour and thickness (relative to the grid size)?

  • Use hex colour code
  • Introduce a new convention to

measure line thickness (e.g. “pt”)

4 3 2 1 0 1 2 3 4 dimension

  • f the grid

(in cm) colour and thickness

  • f first line
slide-40
SLIDE 40

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

40

Mapping a vector image to a bitmap display Consider a red line on a white background

This task is called rasterization. Here’s one approach: Scale: first, scale the line representation to match the display area size (thickening the line accordingly) Map: imagine laying the screen on top of the line

  • colour each pixel that lies fully on top of the line red
  • colour each pixel that does not lie on the line white
  • colour each pixel that lies partly on the line pink
slide-41
SLIDE 41

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

4 3 2 1 00 1 2 3 4 0 1 2 3 4 4 3 2 1

Mapping a vector image to a bitmap display Consider a red line on a white background

slide-42
SLIDE 42

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

4 3 2 1 00 1 2 3 4 0 1 2 3 4 4 3 2 1

Mapping a vector image to a bitmap display Consider a red line on a white background

slide-43
SLIDE 43

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Why is a pixelated look avoided with vector representation?

4 3 2 1 00 1 2 3 4 0 1 2 3 4 4 3 2 1

slide-44
SLIDE 44

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Why is a pixelated look avoided with vector representation?

4 3 2 1 00 1 2 3 4 0 1 2 3 4 4 3 2 1

slide-45
SLIDE 45

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Why is a pixelated look avoided with vector representation?

4 3 2 1 00 1 2 3 4 0 1 2 3 4 4 3 2 1

When we repeatedly zoom in, we run the "scale then map" algorithm repeatedly!

slide-46
SLIDE 46

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

46

Vector image representation Extensions of basic approach

  • Use curves instead of lines
  • Add shading to objects
  • Specify which objects overlay others
  • … and much more
  • Try out Powerpoint shapes to see

more options

slide-47
SLIDE 47

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Image representation formats

Vector graphics:

  • CGM (Computer Graphics Metafile)
  • SVG (Scalable Vector Graphics)
  • AI (Adobe Illustrator Artwork)

Bitmap (raster) graphics:

  • JPEG (Joint Photographic Experts Group; lossy compression)
  • TIFF (Tagged Image File Format; may use lossy or lossless)
  • GIF (Graphics Interchange Format): limited palette, supports

animation

slide-48
SLIDE 48

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Image representation formats

As with .docx and .txt files, image files of different types have distinguishing header information, enabling applications to interpret the representation (or decline to open the file)

slide-49
SLIDE 49

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

What representation is used for PDF documents? Clicker question

  • A. Bitmap images
  • B. Vector images
  • C. It depends
slide-50
SLIDE 50

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

50

What representation is used to photocopy documents? Clicker question

  • A. Bitmap images
  • B. Vector images
  • C. It depends
slide-51
SLIDE 51

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.
  • A. Bitmap images
  • B. Vector images
  • C. It depends

What representation is used by 3D printers? Clicker question

slide-52
SLIDE 52

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Check out a few recent In the News articles:

  • “The code side of colour” describes fun ways you

can use your knowledge of colour codes to improve the look and feel of digital artifacts: https://www.smashingmagazine.com/2012/10/the- code-side-of-color/

slide-53
SLIDE 53

Computational Thinking www.ugrad.cs.ubc.ca/~cs100

The image part with relationship ID rId20 was not found in the file.

Check out a few recent In the News articles:

“Google uses AI to sharpen low-res images” describes how the “Google Brain team has developed a system that uses neural networks to fill in the details on very low- resolution images.”

https://www.engadget.com/2017/0 2/07/google-ai-image-enhancement/