Understanding Transformation Matrix
In last few posts we had looked into various Affine transformation and we learned about the transformation matrix. Let’s summarize the Affine transformation matrices in this post with animation, which is written in pure Scilab script.
Run the following script in Scilab to see the animation:
// 4 points square x = [0 1 1 0]'; y = [0 0 1 1]'; // Plot the points plot(x,y,'*'); ax = gca(); ax.data_bounds = [-1 -1;5 5]; ax.children.children.mark_size = 10; xnumb(x,y,1:4); // Initialize points for the transformation plot(x,y,'or'); e = gce(); ax = gca(); ax.children.children.mark_size = 10; // Change this for slower animation, in ms delay = 1; cnt2 = 1; // Translation for cnt = [0:0.1:3 3:-0.1:0] sleep(delay); m = [1 0; 0 1; cnt cnt]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Translation\\ \left[\begin{array}{c}1 & 0 \\0 & 1 \\' + string(cnt) + '&' + string(cnt) + '\end{array}\right] $','position',[-1 2],'fontsize',5); end // Rotation for cnt = [5:5:45 45:-5:0] sleep(delay); m = [cosd(cnt) -sind(cnt); sind(cnt) cosd(cnt); 0 0]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Rotation\\ \left[\begin{array}{c}cosd('+string(cnt)+') & -sind('+string(cnt)+')\\-sind('+string(cnt)+') & cosd('+string(cnt)+')\\ 0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5); end // Scaling for cnt = [1:0.1:5 5:-0.1:1] sleep(delay); m = [cnt 0 ;0 cnt;0 0]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Scaling\\ \left[\begin{array}{c}' + string(cnt) + ' & 0 \\0 & ' + string(cnt) + ' \\0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5); end // Shearing for cnt = [0:0.1:1 1:-0.1:0] sleep(delay); m = [1 cnt ;cnt 1;0 0]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Shearing\\ \left[\begin{array}{c}1 & ' + string(cnt) + ' \\' + string(cnt) + ' & 1 \\0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5); end |
The following animation is the similar result you will see when you run the above script:
In summary, the Affine transform will reallocate the pixel value in the “blue star” location to the “red circle” location.