image transformations - uclimage processing. 25 unassessed exercise •write matlab functions for...

48
GV12/3072 Image Processing. 1 Image Transformations

Upload: others

Post on 31-May-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

1

Image Transformations

Page 2: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

2

Outline

• Grey-level transformations

• Histogram equalization

• Geometric transformations

• Affine transformations

• Interpolation

• Warping and morphing.

Page 3: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

3

Grey-level transformations

• Changes the image grey level in each pixel

by a fixed mapping f::

• I2(x, y) = f(I1(x,y))I2

I1

Page 4: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

4

Linear – contrast stretching

• f is a linear function: f(x) = x +

• We must preserve the range of grey level

values as {0, 1, …, 255}.

Page 5: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

6

=1.0, =-40

Page 6: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

8

=1.0, =40

Page 7: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

11

=0.5, =0

Page 8: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

12

=2.0, =0

Page 9: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

14

Non-linear – Gamma Correction

• Some non-linear grey-level transformations are useful.

• Gamma correction adjusts for differences between camera sensitivity and the human eye.

• f(x) = Ax

• A=255(1- ) ensures that the grey scale range is unchanged.

Page 10: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

16

=0.5

Page 11: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

18

=2

Page 12: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

20

Histogram Equalization

• Tries to use all the grey levels equally often.

• The grey level histogram is then flat.

• Use the cumulative histogram for f.

Page 13: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

21

Cumulative histogram

Page 14: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

22

Histogram Equalization

function eqIm = histEq(image)

[X,Y] = size(image);

% Construct the cumulative histogram

for i=0:255

cumHist(i) = sum(sum(image <= i))/(X*Y);

end

% Use it to transform the grey level in each pixel.

eqIm = fix(255*cumHist(image));

Page 15: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

23

Equalized Image

Page 16: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

24

Equalized histograms

Page 17: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

25

Unassessed Exercise

• Write matlab functions for linear grey-level

transformations and gamma correction. Try

moderate and extreme settings on an image

and observe the effects they have. Plot the

grey-level histograms before and after the

grey-level transformations.

Page 18: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

26

Geometric transformations

• Change the location of image features

Page 19: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

27

Geometric Transformations

• I1 is the original image, I2 is the warped image.

• I2(x’, y’) = I1(x, y)

• (x’, y’) = T(x, y)

I1 I2

(x, y)

(x’, y’)T

Page 20: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

28

Affine Transformations

• x’= ax + by + tx

• y’= cx + dy + ty

• Translation, scaling, rotation, shear.

y

x

t

t

y

x

dc

ba

y

x

'

'

Page 21: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

29

Translation

4/

4/,

10

01

Y

X

t

t

dc

ba

y

x

Page 22: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

30

Scaling

2/

2/,

20

02

Y

X

t

t

dc

ba

y

x

Page 23: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

31

Stretch

0

4/,

10

05.0 X

t

t

dc

ba

y

x

Page 24: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

32

Rotation

2/))1(cossin(

2/)sin)1(cos(

,4/,cossin

sincos

YX

YX

t

t

dc

ba

y

x

Page 25: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

33

Shear

2/

0

1,1

01

sYt

t

ssdc

ba

y

x

Page 26: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

34

Implementation

• Always use the inverse transformation:

function warpedImage = transform(image, T)

[X,Y] = size(image);

warpedImage = zeros(X,Y);

invT = invert(T);

for x=1:X

for y=1:Y

warpedImage(x,y)=image(invT(x,y));

end

end

Page 27: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

35

Interpolation

• Usually, (x’, y’) = T-1(x, y) are not integer

coordinates.

• We estimate I1(x’, y’) by interpolation from

surrounding positions.

Page 28: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

36

Nearest Neighbour Interpolationx’

y’

x

y

T

Take the value at the nearest grid point:

I1(x’, y’) = I1(x1, y1)

x1

y1

Page 29: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

37

Bilinear interpolationx’

y’

Weighted average from neighbouring

grid points:

I1(x’, y’) = x y I1(x2, y2)

+ x (1 – y) I1(x2, y1)

+ (1 – x) y I1(x1, y2)

+ (1 – x) (1 – y) I1(x1, y1)

x = x’ – x1, y = y’ – y1.

x1

y1

x2

y2

Page 30: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

38

Higher order interpolation

• Quadratic interpolation fits a bi-quadratic

function to a 3x3 neighbourhood of grid

points

• Cubic interpolation fits a bi-cubic function

to a 4x4 neighbourhood.

Page 31: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

39

interp2

• The matlab function interp2 does

nearest neighbour, linear and cubic

interpolation.

• Look it up and try it out!

Page 32: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

40

Interpolation comparison

Nearest

neighbour

Bilinear Cubic

Page 33: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

41

Warps

• Polynomial transformations, e.g., quadratic

transformations:

• x’= a0 + a1x + a2y + a3x2 + a4xy + a5y

2

• y’= b0 + b1x + b2y + b3x2 + b4xy + b5y

2

• Affine transformations map lines to lines.

• They are first-order polynomial transformations.

• Higher-order polynomials can bend lines.

Page 34: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

42

Quadratic warp example

Page 35: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

43

Control point warps

• Moves some pixels to specified locations.

• Interpolate the displacement at intermediate

positions.

• Find a polynomial warp P that maps:

),(),(

:

),(),(

),(),(

''

'

2

'

222

'

1

'

111

mmmm yxyx

yxyx

yxyx

Page 36: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

44

Control point warps

• A = X P

• Least squares estimate of P is (m >= 6):

• P = (XT X)-1 XT A.

55

44

33

22

11

00

22

2

222

2

222

2

111

2

111

''

'

2

'

2

'

1

'

1

1

::::::

1

1

::

ba

ba

ba

ba

ba

ba

yyxxyx

yyxxyx

yyxxyx

yx

yx

yx

mmmmmmmm

Page 37: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

45

Example – Two pixel displacement

Page 38: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

46

Five Pixel Displacement

Page 39: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

47

Extreme warp

Page 40: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

48

Overdetermined

Page 41: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

49

Applications

• Special effects

• Film industry

• Computer games

• Image registration

• Medical imaging

• Security

Page 42: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

50

Image Morphing

How do we get

the i-th image in

the sequence?

Page 43: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

51

Landmarks

Page 44: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

52

Image Registration

• Determines the transformation that aligns

two similar images

Page 45: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

53

Image Similarity

• We find the transformation that maximises

the similarity of the images.

• A simple similarity measure is:

• Many others are used including the cross-

correlation and mutual information.

2

1

2

2121

1

))()((),(

Ix

xIxIIIS

Page 46: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

54

Registration example

Page 47: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

55

Registration

• We have to search for the transformation

the minimizes S.

• Simple in the 1D example.

• For more complex transformations, we use

numerical optimization (see the matlab function fminunc for example).

Page 48: Image Transformations - UCLImage Processing. 25 Unassessed Exercise •Write matlab functions for linear grey-level transformations and gamma correction. Try moderate and extreme settings

GV12/3072

Image Processing.

56

Unassessed Excercise

• Write a registration program, in matlab using the function fminunc, that will determine the translation and rotation that best aligns two images. Test your program using the BrainSliceH4.png (from the website). Create an artificial target image by rotating BrainSliceH4.png and see if your program finds the correct transformation.