Search
In this task, we will learn how to register two images which differ by translation and rotation. The registration can be split to two parts:
For estimating the transformation between the two images, we will employ phase correlation [1] and polar transform [2] of the Fourier amplitude, as will be further described. For transforming an image, we will implement bilinear interpolation [3].
In the first week, we will be dealing with geometric image transformations.
Let us take two images from the package (ZIP), A.png and A_t_40_30.png:
The second image differs from the first one by that it is shifted. The translation is (tx = 30 pixels, ty = 40 pixels). The horizontal axis x goes to the right, the vertical axis y goes down.
How can we transform the first image so that it looks the same as the second image? For the case of integer-valued translation, the simple way is like this:
im = imread('A.png'); tx = 30; ty = 40; [M, N] = size(im); out = zeros(M, N); blank_val = 128; in_range = @(x, y) x>=1 && x<=N && y>=1 && y<=M; for x = 1:N for y = 1:M y_ = y - tx; x_ = x - ty; if in_range(x_, y_) out(y, x) = im(y_, x_); else out(y, x) = blank_val; end end end
For more interesting geometric transformations, we will need an interpolation which is able to extract values for points which lie between pixels. Using the provided function translation.m and your implemented function bilinear.m (its signature is in the template provided in the zip package) , it will become
translation.m
bilinear.m
im = imread('A.png'); tx = 30; ty = 40; out = zeros(M, N); blank_val = 128; for x = 1:N for y = 1:M x_, y_ = translation(-tx, -ty) out(y, x) = bilinear(im, x_, y_, blank_val); end end
The function bilinear implements the bilinear interpolation and also checks for valid ranges of x_ and y_.
bilinear
x_
y_
Try your code in an analogous way on the case of rotation, with the base image A.png and rotated image A_r_30.png. The rotation angle is 30 degrees and the center of rotation is cx=257, cy=257. For convenience, function rotation.m is provided for computing the coordinates using these parameter values.
rotation.m
Finally, we will talk about the composition of transformations and their order. Using the same parameters as above, the coordinates of the first image were first rotated and then translated. The result looks as follows (image A_rt.png):
Try to transform first image to the second and then also second the the first. Observe the order of transformations.
First week checklist: understanding image transformations and implemented function bilinear.m (to be submitted together with the 2nd week assignment.)
[1] slide 7 https://dcgi.fel.cvut.cz/home/sykorad/dzo/slides/dzo-l08.pdf
[2] slide 2 https://dcgi.fel.cvut.cz/home/sykorad/dzo/slides/dzo-l09.pdf
[3] slides 10, 11 https://dcgi.fel.cvut.cz/home/sykorad/dzo/slides/dzo-l07.pdf