Computer Graphics Si Lu Fall 2017 - - PowerPoint PPT Presentation

computer graphics
SMART_READER_LITE
LIVE PREVIEW

Computer Graphics Si Lu Fall 2017 - - PowerPoint PPT Presentation

Computer Graphics Si Lu Fall 2017 http://www.cs.pdx.edu/~lusi/CS447/CS447_547_Comput er_Graphics.htm 10/04/2016 1 Last Time Image file formats Color quantization 2 Today Dithering Signal Processing Homework 1 due today


slide-1
SLIDE 1

Computer Graphics

Si Lu

Fall 2017

http://www.cs.pdx.edu/~lusi/CS447/CS447_547_Comput er_Graphics.htm 10/04/2016

1

slide-2
SLIDE 2

Last Time

 Image file formats  Color quantization

2

slide-3
SLIDE 3

Today

 Dithering  Signal Processing  Homework 1 due today in class  Homework 2 available, due in class on October 18

3

slide-4
SLIDE 4

Dithering to Black-and-White

 Black-and-white is still the preferred way of displaying images in many areas

 Black ink is cheaper than color  Printing with black ink is simpler and hence cheaper  Paper for black inks is not special

4

slide-5
SLIDE 5

Dithering to Black-and-White

 To get color to black and white, first turn into grayscale: I=0.299R+0.587G+0.114B

 This formula reflects the fact that green is more representative

  • f perceived brightness than blue is

 NOTE that it is not not the equation implied by the RGB->XYZ color space conversion matrix

 For all ll dit itherin ring we we wil will l assume me that t the im image is g is gray and that t int intensiti sities are represe resent nted d as a v value lue in [ in [0, , 1.0)

 Define new array of floating point numbers  new_image[i] = old_image[i] / (float)256;  To get back:

  • utput[i]=(unsigned char)floor(new_image[i]*256)

5

slide-6
SLIDE 6

Sample Images

6

slide-7
SLIDE 7

Threshold Dithering

 For every pixel: If the intensity < 0.5, replace with black, else replace with white

 0.5 is the threshold  This is the naïve version of the algorithm

7

slide-8
SLIDE 8

Naïve Threshold Algorithm

8

slide-9
SLIDE 9

Threshold Dithering

 For every pixel: If the intensity < 0.5, replace with black, else replace with white

 0.5 is the threshold  This is the naïve version of the algorithm

 To keep the overall image brightness the same, you should:

 Compute the average intensity over the image  Use a threshold that gives that average  For example, if the average intensity is 0.6, use a threshold that is higher than 40% of the pixels, and lower than the remaining 60%

9

slide-10
SLIDE 10

Brightness Preserving Algorithm

10

slide-11
SLIDE 11

Random Modulation

 Add a random amount to each pixel before thresholding

 Typically add uniformly random amount from [-a,a]

 Pure addition of noise to the image

 For better results, add better quality noise  For instance, use Gaussian noise (random values sampled from a normal distribution)

 Should use same procedure as before for choosing threshold  Not good for black and white, but OK for more colors

 Add a small random color to each pixel before finding the closest color in the table

11

slide-12
SLIDE 12

Random Modulation

12

slide-13
SLIDE 13

Ordered Dithering

13

 Break the image into small blocks  Define a threshold matrix

 Use a different threshold for each pixel of the block  Compare each pixel to its

  • wn threshold

 The thresholds can be clustered, which looks like newsprint  The thresholds can be “random” which looks better

Threshold matrix

            5 9 8 12 15 1 14 4 7 11 6 10 13 3 16 2 16 1

            25 . 25 . 25 . 25 . 25 . 5 . 5 . 5 . 25 . 5 . 75 . 75 . 25 . 5 . 75 . 1

            1 1 1 1 1

Result

slide-14
SLIDE 14

Clustered Dithering

            6875 . 3125 . 5625 . 1875 . 125 . 9375 . 8125 . 5 . 4375 . 875 . 1 0625 . 25 . 625 . 375 . 75 .

slide-15
SLIDE 15

Dot Dispersion

            3125 . 5625 . 5 . 75 . 9375 . 0625 . 875 . 25 . 4375 . 6875 . 375 . 625 . 8125 . 1875 . 1 125 .

slide-16
SLIDE 16

Comparison

Clustered Dot Dispersion

slide-17
SLIDE 17

Pattern Dithering

 Compute the intensity of each sub-block and index a pattern  NOT the same as before

 Here, each sub-block has one of a fixed number of patterns – pixel is determined only by average intensity of sub-block  In ordered dithering, each pixel is checked against the dithering matrix before being turned on

 Used when display resolution is higher than image resolution – not uncommon with printers

 Use 3x3 output for each input pixel

17

slide-18
SLIDE 18

Pattern Dither (1)

18

slide-19
SLIDE 19

Pattern Dither (2)

19

slide-20
SLIDE 20

Floyd-Steinberg Dithering

 Start at one corner and work through image pixel by pixel  Usually scan top to bottom in a zig-zag  Threshold each pixel  Compute the error at that pixel: The difference between what should be there and what you did put there  If you made the pixel 0, e = original; if you made it 1, e =

  • riginal-1

 Propagate error to neighbors by adding some proportion of the error to each unprocessed neighbor  A mask tells you how to distribute the error  Easiest to work with floating point image  Convert all pixels to 0-1 floating point  More detail in class reading materials

e 3/16 5/16 1/16 7/16

slide-21
SLIDE 21

Floyd-Steinberg Dithering

21

slide-22
SLIDE 22

Color Dithering

 All the same techniques can be applied, with some modification  Example is Floyd-Steinberg:

 Uniform color table  Error is difference from nearest color in the color table  Error propagation same as that for greyscale

 Each color channel treated independently

22

slide-23
SLIDE 23

Color Dithering

23

slide-24
SLIDE 24

Comparison to Uniform Quant.

24

Same color table!

slide-25
SLIDE 25

Today

 Dithering  Signal Processing  Homework 2 available, due October 18

25

slide-26
SLIDE 26

Image Manipulation

 We have now looked at basic image formats and color, including transformations of color  Next, operations involving image resampling

 Scaling, rotating, morphing, …

 But first, we need some signal processing

 Also important for anti-aliasing, later in class

26

slide-27
SLIDE 27

Enlarging an Image

27

 To enlarge an image, you have to add pixels between the old pixels  What values do you choose for those pixels?

slide-28
SLIDE 28

Rotating an Image

 Pixels in the new image come from their rotated positions in the

  • riginal image

 These rotated locations might not be in “nice” places

28

New image The positions of the new pixels in the original image

slide-29
SLIDE 29

Images as Samples of Functions

 We can view an image as a set of samples from an ideal function  If we knew what the function was, we could enlarge the image by resampling the function  Failing that, we can reconstruct the function and then resample it

29

reconstruct resample

slide-30
SLIDE 30

Why Signal Processing?

 Signal processing provides the tools for understanding sampling and reconstruction

30

slide-31
SLIDE 31

Function representations

 A function can be represented as a sum of sin’s and cos’s

  • f (possibly) all frequencies:

 F() is the spectrum of the function f(x)

 The spectrum is how much of each frequency is present in the function  We’re talking about functions, not colors, but the idea is the same

31

  

   

 d

e F x f

x i

) ( 2 1 ) (

x i x e

x i

 

sin cos  

slide-32
SLIDE 32

Fourier Transform

 F() is computed from f(x) by the Fourier Transform:

32

   

 dx e x f F

x i

 ) ( ) (

slide-33
SLIDE 33

Example: Box Function

33

        2 1 2 1 1 ) ( x x x f

f f f f F sinc 2 sin ) (        

slide-34
SLIDE 34

Box Function and Its Transform

34

 Two different representations of the same function

 f(x) spatial domain  F() frequency domain

  • 0.5
  • 0.3
  • 0.1

0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5

  • 0.5
  • 0.3
  • 0.1
0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5
slide-35
SLIDE 35

Cosine and Its Transform

35

1

  • 1

If f(x) is even, so is F()

  • 1.5
  • 1
  • 0.5

0.5 1 1.5

slide-36
SLIDE 36

Sine and Its Transform

36

1

  • 1

If f(x) is odd, so is F()

  • 1.5
  • 1
  • 0.5
0.5 1 1.5
slide-37
SLIDE 37

Constant Function and Its Transform

37

The constant function only contains the 0th frequency – it has no wiggles

slide-38
SLIDE 38

Delta Function and Its Transform

38

slide-39
SLIDE 39

Gaussian and Its Transform

39

2

2

2 1

x

e

They are the same

  • 0.02

0.03 0.08 0.13 0.18

  • 0.02

0.03 0.08 0.13 0.18

slide-40
SLIDE 40

Qualitative Properties

 The spectrum of a function tells us the relative amounts of high and low frequencies

 Shar arp p edge ges s giv ive e hig igh h frequ quencies encies  Smoot

  • oth

h var ariat iations ions giv ive lo low frequ quencies encies

 A function is bandlimited if its spectrum has no frequencies above a maximum limit

 sin, cos are band limited  Box, Gaussian, etc are not

40

slide-41
SLIDE 41

Functions to Images

 Images are 2D, discrete functions  2D Fourier transform uses product of sin’s and cos’s  Fourier transform of a discrete, quantized function will

  • nly contain discrete frequencies in quantized

amounts

 In particular, we can store the Fourier transform of a discrete image in the same amount of space as we can store the image

 Numerical algorithm: Fast Fourier Transform (FFT) computes discrete Fourier transforms

41

slide-42
SLIDE 42

Next Time

 Filtering  Resampling  Aliasing  Compositing

42