View
38
Download
0
Category
Preview:
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
Citation preview
Spatial transformations
tiepoints
z
w
y
xT
f(w,z) g(x,y)
original distorted
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);
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];
Apply spatial transformations to images
Inverse mapping then interpolation
original distorted
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.
original Tiepoints afterdistortion
Nearest neighbor
Bilinear interp.
distorted
distorted
restored
restored
original distorted
Diff. restored
(UsingPreviousSlide)
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);
Project#3: iris transformation
Polar coordinate to Cartesian coordinate Check the reference paper
Image Topology
Motivation How many rice?
Outline
Neighbors and adjacency Path, connected, and components Component labeling Lookup tables for neighborhood
Neighborhood and adjacency
4-neighbors
8-neighbors
P QP and Q are 4-adjacent
P
QP and Q are 8-adjacent
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
Component labeling
Two 4-components. How to label them?
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
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
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)
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
Lookup tables for neighborhood (cont.)
Performing any possible 3x3 neighborhood operation is equivalent to table lookupInput Output
0
1
1
2
511 2
… …
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);
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;
Recommended