lezione 03b warping - homes.di.unimi.ithomes.di.unimi.it/lanzarotti/pdf/lezione_03b_warping.pdf ·...
TRANSCRIPT
Raffaella Lanzarotti
2
• Image Enhancement: – Color values modified– Pixel positions unchanged
• Geometric transformation– Pixel positions modifed– Colors unchanged
• Goal:– To create special effects– To register two images taken of the same scene at different times or different positions
– To morph one image to another
3
• Let be an image• is a warping image of if
• and are called the warpingfunctions
4
B(k, l) = A(x(k), y(l))
A(i, j)A(i, j)B(k, l)
x(...) y(...)
5
x(k) = k + 100
y(l) = l + 20
6
x = k+ t
x =
x(k)y(l)
, k =
k
l
, t =
t
x
t
y
7
8
• T = maketform('affine',[1 0 0;0 1 0; 100 20 1]);
• J = imtransform(img,T,'XData',[1,size(img,2)],'YData',[1 size(img,1)]);
9
The translationvector occupies the last row in the transformation matrixin MATLAB!!!
10
x(k) = k · sky(l) = l · sl
11
x = S · k
x =
x(k)y(l)
, k =
k
l
, S =
s
x
00 s
y
,
12
13
T = affine2d([1.5 0 0; 0 .5 0; 0 0 1]);J = imwarp(img,T);
14
15
16
17
18
19
x(k, l) = (k x0) cos() + (l y0) sin() + x0
y(k, l) = (k x0) sin() + (l y0) cos() + y0
(x0, y0) = the center of the image
Where:
= rotation angle
20
x = Rk, where:
R =
cos sin sin cos
,
x =
x(k)y(l)
, k =
k x0
l y0
Theta= pi/6;T = affine2d([cos(Theta) sin(Theta) 0;
-‐sin(Theta) cos(Theta) 0;0 0 1]);
J = imwarp(img, T);
21
22
=
!!!
"
#
$$$
%
&
!!!
"
#
$$$
%
&
!!!
"
#
$$$
%
& −
=
1yx
1000s000s
100tθcossinθtinθsθcos
y
x
y
x
!!!
"
#
$$$
%
&
!"
#$%
&=
!!!
"
#
$$$
%
&
!"
#$%
&!"
#$%
&=
110
1100
10yx
tSRyx
StR
• A generalization of geometric transformations:
23
Q =
C d0T 1
C = any non singular 2 2 matrix
d = any vector in R2
• Maps straight lines into strainght lines• Affine mapping coefficients uniquelydetermined from displacements of 3 vertices
24
A =
a1 a2b1 b2
, d =
a0b0
25
x = a0 + a1k + a2l
y = b0 + b1k + b2l
• Construct the transformation matrix T, givencouples of control points:
T = fitgeotrans(movingPts, fixedPts, ‘affine’); %takes the 3 pairs of control points, movingPts and fixedPts, and uses them to infer the affine transformation
• Example-------Create an affine transformation that maps the triangle with vertices(0,0), (6,3), (-2,5) to the triangle with vertices (-1,-1), (0,-10), (4,4):X= [ 0 0;;
6 3;;-2 5];;
Y = [-‐1 -‐1;0 -‐10;4 4];
T =fitgeotrans(X,Y, 'affine');26
• Construct the struct corresponding to the affine transformation matrix T:
tform = affine2d(T) % builds a TFORM struct for an Ndimensional affine transformation. T defines a forward transformation such thatTFORMFWD(U,T), where U is a 1-‐by-‐N vector, returns a 1-‐by-‐N vector X such that X = U * T(1:N,1:N) + T(N+1,1:N).T hasboth forward and inverse transformations. N=2 for 2D image transformation
27
tform =
C
T0
d
T 1
T
B = IMWARP(A,TFORM, INTERP) %transforms the image A according to the 2-‐D spatialtransformation defined by TFORM; INTERP specifies the interpolation filter
• Example 1---------Apply a horizontal shear to an intensity image.
I = imread('cameraman.tif');tform = affine2d([1 0 0; .5 1 0; 0 0 1]);J = imwarp(I,tform);figure, imshow(I), figure, imshow(J)
28
29
30
Goal: map a square (or more generally a quadrangle) to a quadrangle
It requires 8 parameters:
x = a0 + a1k + a2l + a3kl
y = b0 + b1k + b2l + b3kl
31
• Includes all deformations that can be modeled by polynomial transformations(affine and bilinear are special cases)
32
y = b0 + b1k + b2l + b3kl + b4k2 + b5l
2 + ...x = a0 + a1k + a2l + a3kl + a4k
2 + a5l2 + ...
• Polynolial:
tform = fitgeotrans(movingPts,fixedPts,'polynomial',degree)
• OR more in general:
tform = fitgeotrans(movingPts,fixedPts,transformationType)
takes the pairs of controlpoints, ”movingPts” and ”fixedPts”, and uses them to infer the geometric transformation specifiedby transformationType.
Where “transformationType”…
33
34
35
Wave1: x(k, l) = k + 20 sin
2
128l
; y(k, l) = l
36
Wave2: x(k, l) = k + 20 sin
2
30k
; y(k, l) = l
37
Warp: x(k, l) =sign(k x0)
x0 (k x0)
2 + x0; y(k, l) = l
(x0, y0) = the center of the image
38
(x0, y0) = the center of the image