14
CGT 511 Image Transformations Image Transformations dřih š h Bedřich Beneš,Ph.D. Purdue University Department of Computer Graphics Technology Image Transformations Color Transformations (pixels are not changing their positions) Geometric Transformations (pixels can change positions, new can be added, some can be deleted) © Bedrich Benes Image Transformations Color Transformations (pixels are not changing their positions) Geometric Transformations (pixels can change positions, new can be added, some can be deleted) © Bedrich Benes Histogram image with intensity levels 0,1,…,L histogram is a discrete function h(k), where h(k) gives # of pixels of intensity k in the image vector of absolute frequencies of intensities © Bedrich Benes

CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

CGT 511Image TransformationsImage Transformations

dři h š hBedřich Beneš, Ph.D.

Purdue University

Department of Computer Graphics Technology

Image Transformations• Color Transformations 

(pixels are not changing their positions)

• Geometric Transformations(pixels can change positions, new can be added, some can be deleted), )

© Bedrich Benes

Image Transformations• Color Transformations 

(pixels are not changing their positions)

• Geometric Transformations(pixels can change positions, new can be added, some can be deleted), )

© Bedrich Benes

Histogram• image with intensity levels 0,1,…,L 

• histogram is a discrete function h(k), where h(k) gives # of pixels of intensity kin the image

• vector of absolute frequencies of intensities

© Bedrich Benes

Page 2: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

HistogramExample: image resolution: 5 x 6

• Histogram:  image:

1 1 1 1 1

0 10 18

2 32 4

41

5 60 2

7 80 1

92

1 11 2

1 13 3

1 2 3 3

111

1 4 6 6 11 91 1

8 91 1

11

© Bedrich Benes

Histogram

void Histogram (char **image, int x, int y, int *histogram)

{int i,j;for (i=0;i<255;i++) histogram[i]=0; for (i=0;i<x;i++)for (j=0;j<y;j++)for (j=0;j<y;j++)

histogram[image[i][j]]++;}

© Bedrich Benes

Histogram• Different images ‐> different histograms

• RGB, CMY  ‐ three

• CMYK  ‐ four (plus intensity)

• Grayscale ‐ one• Grayscale  ‐ one

In multidimensional cases, luminance is useful

© Bedrich Benes

Histogram

© Bedrich Benes

Page 3: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Histogram properties255

1.

0

.)(i

yxihistogram

2. Different images can have equal histograms

this is a bi‐modal histogram

© Bedrich Benes

Histogram properties3. Histogram carries information about 

intensities of the image

bright dark high contrast bimodalbright dark high contrast bimodal

© Bedrich Benes

Image Classification

low‐key high‐key average‐key high contrast

© Bedrich Benes

low key high key average key high contrast

Image Transformations• Color Transformations 

(pixels are not changing their positions)

• Geometric Transformationsf(pixels can change positions, new can be added, some can be deleted), )

© Bedrich Benes

Page 4: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Convolution• The most important operation with images

• So called convolution kernel (also called mask) is summed with an area of image, result is the value of a new pixel

• Also called sliding window

• The simples case an average• The simples case an average

© Bedrich Benes

Convolution

© Bedrich Benes

Convolution• Continuous 1D convolution

dttxhxfxhxfxg )()()(*)()(

• Discrete 1D convolution

ikhkfihifig ][][][*][][

• Discrete 2D convolution

kikhkfihifig ][][][][][

k l

jlikhlkfjihjifjig ],[],[],[*],[],[

© Bedrich Benes

Convolution• Convolution kernel should sum to one

1][

h

• Convolution kernel is typically symmetrical

1)( dtth 1][ i

ih

• Convolution kernel is typically symmetrical

© Bedrich Benes

Page 5: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Convolution ‐ 1D discrete example• f(x)  all values = 1

• g(x) all five values = 0 2• g(x) all five values = 0.2

• f(x)*g(x)

© Bedrich Benes

Convolution ‐ 2D discrete examplef(x) h(x) 0 1

1 ‐4

0

1

0 1 0

1 1

1 2

1 1

3 3

1 2 3 3

1

1

1

example for the yellow pixel:

0 1 0

1 4 6 6 11 9

1 1

8 9

1 1

1

1 example for the yellow pixel:

1+1+3+2‐2*4 = 7 ‐ 8 = ‐10 0

0 1

0 0

3 4

0

0

1 1 1 1 1

g(x)

0 ‐1 ‐3 ‐4

0 4

0 2

2 1

‐3 ‐5

0

0

0

© Bedrich Benes

0 ‐22

0 0

‐7 ‐20

0 0

0

0

Noise Reduction  Simple Averaging1/9 1/9 1/9

• h(x,y)=1/9 1/9

1/9 1/9

1/9

1/9

1/9 1/9 1/9

• Introduces heavy blur 

• The bigger the kernel the heavier the blur• The bigger the kernel, the heavier the blur

© Bedrich Benes

Noise Reduction  Gaussian Filtering1/16 2/16 1/16

• h(x,y)=1/16 2/16

2/16 4/16

1/16

2/16

1/16 2/16 1/16

• Introduces heavy blur 

• The bigger the kernel the heavier the blur

1/16 2/16 1/16

• The bigger the kernel, the heavier the blur

© Bedrich Benes

Page 6: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Noise Reduction – Median Filtering• Is not convolution

• Take neighbors, sort them, take the median

Example: 10  12 13 ‐>  sorted 10 10 10 10 10 11 12 13 19 019  11 1010  10 10  

© Bedrich Benes

Image Sharpening• Human perception is sensitive to edges

1) take the image and find the edges

2) add the edges to the image

• G = F + c S• G = F + c S

F ‐ input image, G output imageG ‐ output image, S ‐ edges of Fc coefficient of sharpening

© Bedrich Benes

c ‐ coefficient of sharpening

Image Sharpening• What is an edge?

step line

ramp roof (tent)

Easy for humans, hard for an automatic process

© Bedrich Benes

Image SharpeningGradient

is generalization of derivative

yyxf

xyxfyxf ),(,),(),(

Is the direction of maximum increase of  f(x,y)

it's size (number) is the rate of increase22 ),(),()(

yxfyxff

this is s(x,y)

© Bedrich Benes

),(),(),(

yyf

xyfyxf

Page 7: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Edge Detection – Robert’s operator

s(i,j) = |f(i,j) ‐ f(i+1,j+1)| + |f(i ‐1,j) ‐ f(i,j‐1)| 

• s(i,j) = +i j

i+1j+1 i+1,j

i j+1

• very sensitive to noise

i,j i,j+1

• can be computed very fast

• it is NOT convolution

© Bedrich Benes

Edge Detection – Sobel’s operator

202101

)( jih

101012

)( jih

000121

)( jih

Properties

101202),( jih

210101),( jih

121000),( jih

Properties

• it is convolution

• dependent on the direction (9 variants)

• thick edges

© Bedrich Benes

Edge Detection – Sobel’s operator

© Bedrich Benes

Edge Detection ‐Laplace’s operator

141010

),( jih f(x)

Properties:

010

( )

f(x)

Properties:

• it is convolution x

• approximates second derivative 

• doubles edges 22 )()( ff© Bedrich Benes

• in fact it is: 2

2 ),(),(),(

y

yxfx

yxfyxf

Page 8: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Edge Detection ‐Laplace’s operator

© Bedrich Benes

Image Sharpening

Hint:

© Bedrich Benes

Do not use image sharpening repeatedly...

Painting by numbersImpressionism

• second half of the 19th century

• image is dine by brush strokes of limited amount of colors

• the definitive color rises in the human eye

PointillismPointillism 

• the brush is only put and not stroked.

© Bedrich Benes

Painting by numbers

© Bedrich Benes

Page 9: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Painting by Numbers• Input:  image f ‐ photograph 

Output: image g ‐ empty sheet of paperPalette: of few colors and a brush

1) Divide f into equal squares (e.g., 5x5 pixels)

2) Get average of the colors in every square

3) For every square do:3) For every square do:a) choose closest color in the palette ~ 10%b) put the color stroke under given direction

© Bedrich Benes

b) put the color stroke under given directionb) (pointillism) fill the square by circles

Painting by Numbers

© Bedrich Benes

Non‐Photorealistic Rendering• NPR – anything that displays 3D objects non‐

realistically

• Includes art, painting, drawing, sketching, 

• Is helpful in visualizations e.g.,  displaying p g , p y gmedical data as sketches

• Includes• Includes cartoon‐like rendering

© Bedrich Benes

Geometric Transformations• How can we zoom an image [1.2,0.7]x?

• Continuous image  ‐ easily.

• Discrete image  ‐ hardly

• 1*1 2 = 1 2• 1 1.2 = 1.2 we get non‐integernon‐integer coordinates!

© Bedrich Benes

Page 10: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Geometric TransformationsDiscrete images are transformed by resampling

1) reconstruct the continuous original of the function

2) transform )it

3) sample it3) sample it again

© Bedrich Benes

Geometric Transformations• Transformation and Sampling is easy

• How do we reconstruct?

• We need to find a continuous representation of a discrete imageg

• Is it possible?

• Few known points• Few known points

• Convolution is the solution

© Bedrich Benes

Reconstruction• Problem – what should be between samples?

© Bedrich Benes

Nearest Neighbor Interpolation• Sample & hold

• Resamples with the closest value

• Fast, bad results (especially for text)

© Bedrich Benes

Page 11: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Nearest Neighbor

© Bedrich Benes

Linear Interpolation• Linearly interpolates between values

• Good and fast results

• Blurs

© Bedrich Benes

Bilinear Interpolation• In 2D we need to interpolate 3x

• Linear interpolation is separable

• Linearly interpolate AB‐>P

• Linearly interpolate CD‐>R• Linearly interpolate CD‐>R

• Linearly interpolate PR‐>Q

© Bedrich Benes

Bilinear

© Bedrich Benes

original bilinear nearest neighbor

Page 12: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Higher order interpolation• Approximates the values by a higher order 

function 

• Usually preserves edges

• May be slowy

© Bedrich Benes

Reconstruction and Convolution• Discrete f(x)

• Continuous h(x)• Continuous h(x)

• Continuous h(x)*f(x)

© Bedrich Benes

The Box Filter

otherwise

rirrihbox 0

)12/(1][

r r

1/(2r+1)

‐r r

otherwise

rxrrxhbox 0

)2/(1)(

1/(2r)

otherwise0 ‐r r

The filter is C0 continuous – no jumps

© Bedrich Benes

The filter is C continuous  no jumps

The Tent Filter

xr

xxhtent

1||||1)(

1/(2r)

otherwisertent

0 ‐r r

• The filter is C0 continuous – no jumps

© Bedrich Benes

Page 13: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

Gaussian Filter

2/2

21)( x

Gauss exh

• Does not have finite support• Does not have finite support

• Good sampling, expensive to calculate

© Bedrich Benes

B‐Spline Cubic Filter

h ixxxxxx

xh splineB

02||1|)|2(111|)|1(3|)|1(3|)|1(3

61)( 3

23

otherwise0

© Bedrich Benes

Filter properties• Can be interpreted as weights that are 

assigned to each sample

• Filter can be interpolatingor approximating

• Soma can have overshootgood for enhancing edgesg g g

• Separability – 2D can be done as multiple runs of 1D

© Bedrich Benes

as multiple runs of 1D 

Summary• continuous and discrete image

• digitalization ‐ sampling and quantizationdigitalization  sampling and quantization

• raster and vector image, rasterization, OCR

© Bedrich Benes

Page 14: CGT 511 Transformations Image Transformationshpcg.purdue.edu/bbenes/classes/CGT511/lectures/CGT511-05...CGT 511 Image Transformations Bedřihich Beneš hš, Ph.D. Purdue University

ReadingsRafael Gonzales, Richard Woods, Digital Image 

Processing, Addison Wesley Publishing, 1993, pages 307 ‐>

Peter Shirley et al, Fundamentals of Computer dGraphics 2nd edition, pp 71‐118

© Bedrich Benes