28
1 computer graphics • images © 2008 fabio pellacini • 1 images computer graphics • images © 2008 fabio pellacini • 2

imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

1

computer graphics • images © 2008 fabio pellacini • 1

images

computer graphics • images © 2008 fabio pellacini • 2

Page 2: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

2

computer graphics • introduction © 2008 fabio pellacini • 3

what is an image?

• a photographic print?• a photographic negative?• a display image?• the in-memory bits?

computer graphics • introduction © 2008 fabio pellacini • 4

image definition

• image: 2D continuous distribution of colors– mathematically: function from the real plane to color

• for graphics applications– represent images numerically– display images

colorI !"2:

Page 3: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

3

computer graphics • introduction © 2008 fabio pellacini • 5

digital image representation

• digital image: 2D array of color values (pixels)– pros: can represent any image

computer graphics • introduction © 2008 fabio pellacini • 6

digital image representation

• pixel: color sample from the continuous function– not a little square

Page 4: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

4

computer graphics • introduction © 2008 fabio pellacini • 7

digital color representation

• color: how humans perceive light– light: physical quantity (electromagnetic energy)– color: visual system response to light– complex phenomenon: covered later

• observation: humans are trichromatic– match any color by blending other three

• implication: represent digital color using threevalues– [red, green, blue] are good ones

– used for display devices

computer graphics • introduction © 2008 fabio pellacini • 8

digital images are approximations

• representing images digitally introduces artifacts– number of pixels: image resolution– number of color channels: image type– number of color gradations: color depth

Page 5: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

5

computer graphics • introduction © 2008 fabio pellacini • 9

effects of image resolution

computer graphics • introduction © 2008 fabio pellacini • 10

effect of image type

• color images: 3 color samples (red/green/blue)• grayscale images: 1 sample• bitmap images: 1 boolean sample

Page 6: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

6

computer graphics • introduction © 2008 fabio pellacini • 11

effect of color depth

computer graphics • introduction © 2008 fabio pellacini • 12

image data structure

• digital images are 2D arrays of colors

• dataType defines type of image and color depth• xres x yres is the image resolution

dataType image[xres][yres]

Page 7: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

7

computer graphics • introduction © 2008 fabio pellacini • 13

image data types

• bitmap: boolean per pixel– range: black/white value only

• grayscale: integer per pixel– range: shades of gray– precision: 8bpp (sometimes higher)

• color: integer[3] per pixel– range: most reproducible colors– precision: 8x3bpp (sometimes higher)

}1,0{: 2 !"I

]1,0[:2 !"I

32]1,0[: !"I

computer graphics • introduction © 2008 fabio pellacini • 14

image data types

• high-dynamic range (HDR): float[3]– range: unconstrained– used for computation

• clipping and white point– compute in floating points, convert to integer for display– simple conversion: choose a value for white, clip to it

32: +!"!I

Page 8: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

8

computer graphics • introduction © 2008 fabio pellacini • 15

storage requirements

• 1024x1024 in-memory image– bitmap: 128KB– grayscale 8bpp: 1MB– color 24bpp: 3MB– HDR color: 12MB

• often compressed on disk– lossless compression (e.g. PNG)

– data is redundant fit in smaller space– lossy compression (e.g. JPG)

– loose “non-that-visible” information

computer graphics • introduction © 2008 fabio pellacini • 16

interpretation of image values

• what do numbers in images mean?– determine how bright a pixel is

• color images: values are relative to a displaydevice– (0,0,0) is “black”: darkest color possible on display– (1,1,1) is “white”: lightest color possible on display

• HDR images: values encode “light” distribution– can represent light intensity that cannot be displayed

– e.g. sun is brighter than a white wall

Page 9: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

9

computer graphics • introduction © 2008 fabio pellacini • 17

HDR example

-8 stops +8 stopsexposure

[Paul Debevec]

computer graphics • introduction © 2008 fabio pellacini • 18

transfer function

• transfer function: map pixel values to displayvalues– input: digital image intensity– output: light emitted by the display device

• physics of display device constrains transferfunction– Im: minimum displayable intensity (not 0)– IM: maximum displayable intensity (not the sun)– k: ambient light reflected by display– actual output reaching our eyes:

],[]1,0[: Mm IIf !

],[ kIkI Mm ++

Page 10: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

10

computer graphics • introduction © 2008 fabio pellacini • 19

dynamic range

• dynamic range:– determine maximum image contrast– dynamic range affects perceived image quality

– since humans are sensitive to contrast

• rough values– low-quality monitor: 20:1– photographic print: 30:1– high-quality monitor: 100:1– plasma display: 1000:1– HDR display: 10000:1

( ) ( )kIkIR mMd ++=

computer graphics • introduction © 2008 fabio pellacini • 20

typical transfer function

!xIIxf Mm +=)(

Page 11: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

11

computer graphics • introduction © 2008 fabio pellacini • 21

non-linear transfer function motivation

• historical reasons– analog displays work this way (intensity = k voltage2)

• current reason– inertia: backward compatibility with old way– efficient: humans perceive images intensity prop. to

log(x)– power formula is close enough to ideal exponential– make 8bit images feasible

• what values for gamma?– sRGB standard: 2.2

computer graphics • introduction © 2008 fabio pellacini • 22

effect of transfer function

linear γ = 2

Page 12: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

12

computer graphics • introduction © 2008 fabio pellacini • 23

gamma correction

• problem: need to display image values linearly– especially for graphics applications

• solution: undo non-linearity in transfer function– for an ideal monitor (0 black level):– given– we have

• “gamma correction” in practice– compute images linearly– apply inverse of gamma before sending image to

display

!xIxf M=)(!/1

' xx =xxIxf M !=

"')'(

computer graphics • introduction © 2008 fabio pellacini • 24

typical display pipeline for 24bpp

• display expects 8bit gamma corrected values– note: this is an overly simplified view– typical gamma

• integer image formats– store values in the range [0..M]– where M is max value for the datatype

• floating-point image formats– store unconstrained values– pick a white point w for display

!/1

255 "#

$%&

'(=M

cc

id

!/1

255 ""#

$%%&

'(=w

cc

fd

dc

fc

2.2=!

Page 13: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

13

computer graphics • introduction © 2008 fabio pellacini • 25

desirable color depth

• minimize perceived intensity change betweenconsecutive image levels when displaying images– avoids visible color banding– introduced by quantization

no visible banding visible banding

computer graphics • introduction © 2008 fabio pellacini • 26

desirable color depth

• humans perceive error prop. to 2% intensity– need more levels in the dark regions

• depends on dynamic range– lower quality display may not show problems

• linear encoding: equal steps– ~10bits print, ~12bits for monitor, ~18bits for HDR

display• nonlinear encoding: bigger steps in brighter areas

– ~ 8bits ok, ~12 bits better• many digital camera have 12bits linear sensors

– output: 8bit nonlinear JPEG or 12bits linear RAW

Page 14: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

14

computer graphics • introduction © 2008 fabio pellacini • 27

what is a pixel, really?

• color around a point (“area” sample)– not the color at the point (point sample)– intuitive definition only; formal definition not covered in

class

area

point

computer graphics • introduction © 2008 fabio pellacini • 28

what is a pixel, really?

• color around a point (“area” sample)– not the color at the point (point sample)– intuitive definition only; formal definition not covered in

class

area

point

Page 15: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

15

computer graphics • images © 2008 fabio pellacini • 29

image display

computer graphics • introduction © 2008 fabio pellacini • 30

image display

• display– cathode ray tube (CRT)– liquid crystal display (LCD)– plasma display

• print– laser printer– inkjet printer

Page 16: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

16

computer graphics • introduction © 2008 fabio pellacini • 31

cathode ray tube

• electron beam scans a screen• intensities by modulation of beam energy

[H&

B fi

g. 2

-7]

computer graphics • introduction © 2008 fabio pellacini • 32

liquid crystal display

• each pixel has a switch that can block light• intensities by how much light gets blocked

[H&

B fi

g. 2

-16]

Page 17: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

17

computer graphics • introduction © 2008 fabio pellacini • 33

color displays

• humans are trichromatic– match any color by blending three primaries– display color image by blending three monochromatic

images• additive color

– overlap “dots” from each image– eye will blend them to form one color– (red, green, blue) and good primaries

computer graphics • introduction © 2008 fabio pellacini • 34

color cathode ray tube

• multiple beams for color

[H&

B fi

g. 2

-10]

Page 18: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

18

computer graphics • introduction © 2008 fabio pellacini • 35

color liquid crystal display

• multiple pixels for color

[Mar

schn

er 2

003]

computer graphics • images © 2008 fabio pellacini • 36

compositing

Page 19: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

19

computer graphics • introduction © 2008 fabio pellacini • 37

compositing

[Tita

nic

– D

igita

lDom

ain

-imag

es v

fxhq

.com

]

computer graphics • introduction © 2008 fabio pellacini • 38

compositing

• combine two images by overlaying

over

Page 20: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

20

computer graphics • introduction © 2008 fabio pellacini • 39

compositing

• encode transparency: alpha channel

over

computer graphics • introduction © 2008 fabio pellacini • 40

compositing

overA α BC =

!"#

=otherwise

opaque is

B

AA

Cc

cc

$

Page 21: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

21

computer graphics • introduction © 2008 fabio pellacini • 41

compositing two layers

• pixel on the edges are partially transparent– i.e. α encodes the degree of “transparency”

BAAACccc !"+!= )1( ##

overA α BC =

BAC over=

computer graphics • introduction © 2008 fabio pellacini • 42

compositing two layers

BAAAC

BAAAC

BAAAC

BAAAC

bbb

ggg

rrr

ccc

!"+!=

!"+!=

!"+!=

#

!"+!=

)1(

)1(

)1(

)1(

$$

$$

$$

$$ color composite

compositeeach channel

Page 22: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

22

computer graphics • introduction © 2008 fabio pellacini • 43

compositing: definition of coverage

• α is the fractional area covered by a fragment

BAAACccc !"+!= )1( ##

computer graphics • introduction © 2008 fabio pellacini • 44

compositing - premultiplied colors

• given the compositing equation

• if we multiply the coverage by the colors

• we can rewrite the compositing result as

– since coverage of B is 1, i.e. fully opaque– slightly faster, but much cleaner

BAAACccc !"+!= )1( ##

cc !=" #

BAACccc !"#+!=! )1( $

Page 23: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

23

computer graphics • introduction © 2008 fabio pellacini • 45

compositing multiple layers

• Need to composite multiple layers– Special effects, Photoshop …

[Tita

nic

– D

igita

lDom

ain

– im

ages

from

vfx

hq.c

om]

computer graphics • introduction © 2008 fabio pellacini • 46

compositing multiple layers

Page 24: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

24

computer graphics • introduction © 2008 fabio pellacini • 47

compositing multiple layers

( )CBAD overover=

( ) ( )[ ]

( ) ( )[ ]CBBAAD

CCBBBAAAD

cccc

cccc

!"+!"+!=!

"+"+=

##

#####

11

11

computer graphics • introduction © 2008 fabio pellacini • 48

compositing multiple layers

• working assumption: independent covered areas– sometimes not true– but it works well enough and it is fast– so we use it all the times

Page 25: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

25

computer graphics • introduction © 2008 fabio pellacini • 49

compositing multiple layers - associativity

•• need to define αA over B

( )BAABA

!!!! "+= 1over

( ) ( ) CBACBA overoveroverover =

computer graphics • introduction © 2008 fabio pellacini • 50

compositing multiple layers - associativity

( ) CBAD overover=

( )( ) ( )[ ]

CBAABAA

CBABAD

ccc

ccc

!"""+!"+!=

=!"+!=!

####

#

111

1overover

( ) ( ) CBACBA overoveroverover =

this proves that

Page 26: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

26

computer graphics • introduction © 2008 fabio pellacini • 51

coverage vs. transparency

• opaque objects compose with coverage• transparent objects blend with transparency

– example: thin sheets of colored glass– same equations that compositing uses

opaque objects transparent objects

computer graphics • introduction © 2008 fabio pellacini • 52

other image manipulations

• convolution and resampling– resizing, blurring, artistic filters

• painting• object removal

Page 27: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

27

computer graphics • images © 2008 fabio pellacini • 53

image generation

computer graphics • introduction © 2008 fabio pellacini • 54

image generation

• by acquisition– scanner– digital cameras

• by manipulation– image operations– painting/editing

• by synthesis– graphic art– realistic synthesis

• often a mixture of all

Page 28: imagespellacini.di.uniroma1.it/teaching/graphics08/lectures/02_Images_Web.pdf8 computer graphics • introduction © 2008 fabio pellacini • 15 storage requirements •1024x1024 in-memory

28

computer graphics • introduction © 2008 fabio pellacini • 55

image generation

• by acquisition– scanner– digital cameras

• by manipulation– image operations– painting/editing

• by synthesis– graphic art– realistic synthesis

• often a mixture of all