Search
In this task, we will learn how to register two images that differ by translation and rotation. The registration can be split into two parts:
To estimate 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. To transform an image, we will implement bilinear interpolation [3].
In the first part, we will be dealing with geometric image transformations. You can start by downloading the homework template.
dzo_hw06_template.zip
Let us take two images, A.png and A_t_40_30.png:
The second image differs from the first one in that it is shifted. The translation is (tx = 30 pixels, ty = 40 pixels). The horizontal axis, x, goes to the right, and the vertical axis, y, goes down.
How can we transform the first image to look the same as the second image? A simple example is provided in the script hw_img_reg_1.m in the “Translation by integer pixel values” section:
hw_img_reg_1.m
im = imread('A.png'); [M, N] = size(im); blank_val = 128; tx = 30; ty = 40; im_trans = zeros(M, N); in_range = @(x, y) x>=1 && x<=N && y>=1 && y<=M; for x = 1:N for y = 1:M [xs, ys] = translation(x, y, -tx, -ty); if in_range(xs, ys) im_trans(y, x) = im(ys, xs); else im_trans(y, x) = blank_val; end end end
For more interesting geometric transformations, we will need an interpolation that can extract values for points that lie between pixels. Your first task is to implement the bilinear interpolation in bilinear.m and use it for image translation in the “Translation with bilinear interpolation” section.
bilinear.m
Remember the image indexing convention - the pixel with coordinates (x, y) means x-th pixel from left, y-th pixel from top. The image matrix is then indexed as image(y, x) (first indexing the row, then the column). On the other hand the bilinear.m function accepts the coordinates in the original order bilinear(im, x, y, blank_val).
(x, y)
image(y, x)
bilinear(im, x, y, blank_val)
The ideal way of interpolation would be reconstruction of the image (as continuous function) from the pixels (samples) using sinc function. The bilinear kernel used in this homework is basically a very efficient approximation of sinc.
The second task is implementing rotation around a center (cx, cy) by angle phi in rotation.m. You can test the rotation in combination with bilinear interpolation in the hw_img_reg_1.m script.
rotation.m
Rotation of a point (x, y) around a center (cx, cy) by angle Φ can be written as:
Finally, you can combine both the translation and rotation. The coordinates of the first image were first rotated and then translated using the same parameters as above. Observe the order of transformations. The result looks as follows (image A_rt.png):
and learn how to combine the transformations with interpolation in hw_img_reg_1.m.
[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