spatial transformations

22
Spatial transformations tiepoints z w y x T f(w,z) g(x,y) original distorted

Upload: kai-rosario

Post on 31-Dec-2015

36 views

Category:

Documents


0 download

DESCRIPTION

Spatial transformations. T. tiepoints. f(w,z). g(x,y). distorted. original. Affine transform. MATLAB code:. T=[2 0 0; 0 3 0; 0 0 1]; tform=maketform('affine', T); tform.tdata.T tform.tdata.Tinv WZ=[1 1; 3 2]; XY= tformfwd (WZ, tform); WZ2= tforminv (XY, tform);. Exercise#1. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Spatial transformations

Spatial transformations

tiepoints

z

w

y

xT

f(w,z) g(x,y)

original distorted

Page 2: Spatial transformations

Affine transform

1

0

0

111

3231

2221

1211

tt

tt

tt

zwzwyx T

MATLAB code:

T=[2 0 0; 0 3 0; 0 0 1];tform=maketform('affine', T);tform.tdata.Ttform.tdata.TinvWZ=[1 1; 3 2];XY=tformfwd(WZ, tform);WZ2=tforminv(XY, tform);

Page 3: Spatial transformations

Exercise#1

% generate a grid image[w, z]=meshgrid(linspace(0,100,10), linspace(0,100,10));wz = [w(:) z(:)];plot(w, z, 'b'), axis equal, axis ijhold onplot(w', z', 'b');set(gca, 'XAxisLocation', 'top');

EX. Apply the following T to the grids, and plot all results

T1 = [3 0 0; 0 2 0; 0 0 1];T2 = [1 0 0; .2 1 0; 0 0 1];T3 = [cos(pi/4) sin(pi/4) 0; -sin(pi/4) cos(pi/4) 0; 0 0 1];

Page 4: Spatial transformations

Apply spatial transformations to images

Inverse mapping then interpolation

original distorted

Page 5: Spatial transformations

Apply spatial transformations to images (cont.)

MATLAB function

Ex#2

g=imtransform(f, tform, interp);

f=checkerboard(50);

Apply T3 to f with ‘nearest’, ‘bilinear’, and ‘bicubic’interpolation method. Zoom the resultant imagesto show the differences.

Page 6: Spatial transformations

original Tiepoints afterdistortion

Nearest neighbor

Bilinear interp.

distorted

distorted

restored

restored

Page 7: Spatial transformations

original distorted

Diff. restored

(UsingPreviousSlide)

Page 8: Spatial transformations

Image transformation using control points

Ex#3, for original f and transformed g in Ex#2, using cpselect tool to select control points:

cpselect(g, f);

With input_points and base_points generated using cpselect, we do the following to reconstruct theoriginal checkerboard.

tform=cp2tform(input_points, base_points, 'projective');gp=imtransform(g, tform);

Page 9: Spatial transformations

Project#3: iris transformation

Polar coordinate to Cartesian coordinate Check the reference paper

Page 10: Spatial transformations

Image Topology

Page 11: Spatial transformations

Motivation How many rice?

Page 12: Spatial transformations

Outline

Neighbors and adjacency Path, connected, and components Component labeling Lookup tables for neighborhood

Page 13: Spatial transformations

Neighborhood and adjacency

4-neighbors

8-neighbors

P QP and Q are 4-adjacent

P

QP and Q are 8-adjacent

Page 14: Spatial transformations

Path, connected and components

P

Q

P and Q are 4-connectedThe above set of pixels are 4-connected.=> 4-component

P

Q

P and Q are 8-connectedThe above set of pixels are 8-connected.=> 8-component

Page 15: Spatial transformations

Component labeling

Two 4-components. How to label them?

Page 16: Spatial transformations

Component labeling algorithm

Scan left to right, top to down.• Start from top left foreground pixel.

2. Check its upper and left neighbors.Neighbor labeled => take the same labelNeighbor not labeled => new label

1

2 1 3

4 3

5 4

Page 17: Spatial transformations

Component labeling algorithm

1

2 1 3

4 3

5 4

{1,2} and {3,4,5} are equivalent classes of labels, which aredefined by adjacent relation.

{1,2} => 1{3,4,5} => 2

1

1 1 2

2 2

2 2

Page 18: Spatial transformations

Ex#4: component labeling MATLAB code

Threshold the rice.tiff image, then count the number of rice. Using 4- and 8-neighbors. Show the label image and the number of rice in the title.

i=zeros(8,8);i(2:4,3:6)=1;i(5:7,2)=1;i(6:7,5:8)=1;i(8,4:5)=1;bwlabel(i,4)bwlabel(i,8)

Page 19: Spatial transformations

Lookup tables for neighborhood

For a 3x3 neighborhood, there are 29=512 possible

For each possible neighborhood, give it a unique number( 類似 2 進位編碼 )

.X

1

2

4

8

16

32

64

128

256

= 3

Page 20: Spatial transformations

Lookup tables for neighborhood (cont.)

Performing any possible 3x3 neighborhood operation is equivalent to table lookupInput Output

0

1

1

2

511 2

… …

Page 21: Spatial transformations

Ex#5: table lookup

Find the boundary that are 4-connected in a binary image

Ex#5: Find the 8-boundary of the rice image using lookup table

f=inline('x(5) & ~(x(2)*x(4)*x(6)*x(8))');lut=makelut(f,3);Iw=applylut(II, lut);

Page 22: Spatial transformations

Ex#6: table lookup

Build lookup tables for the following cases

Show your result with the following matrix

a=zeros(8,8);a(2,2)=1;a(4:8,4:8)=1;a(6,6)=0;