# Translation of a matrix

43 views (last 30 days)
Angela Ebirim on 22 Oct 2019
Answered: Sai Bhargav Avula on 31 Oct 2019
Hi,
I'm trying to understand translation of an image (from one spatial point to another) and wrote some code in order to do so however the image isn't translating/moving.
I read that a translation matrix would typically be [1 0 tx; 0 1 ty; 0 0 1] where (tx, ty) would be the new spatial co-ordinates that the image would move to,and you would multiply the translation matrix by the C = imread(image), however how would that work if the size of the image was for example 684 X 1024 ?
I tried to do it this way instead.
Can someone please tell me where I'm going wrong ?
PS: I don't want to use imtranslate MATLAB function.
Many thanks
grid on
axis([-1 1 -1 1])
S = [1 -1 -1 1; 1 1 -1 -1; 1 1 1 1]
x=S(1,:); y=S(2,:);
patch(x,y,'r')
%translation matrix
T = [5;4];
%new spatial co-ordinates
new_x = size(S,1) + T(1,1);
new_y = size(S,2) + T(2,1);
% creation of zero padding matrix in order to perform matrix operations
Z = zeros(new_x,new_y);
M = Z(T(1,1):end-1, T(2,1):end-1) + S(:,:);
figure; patch(M(1,:),M(2,:),'r')

Sai Bhargav Avula on 31 Oct 2019
Hi,
Here is a simple translation code
T = [5,5];
% here S is a image hence 3rd dimension
tran_S = uint8( zeros(size(S,1)+T(2)-1, size(S,2)+T(1)-1, size(S,3));
% Translate
tran_S(T(2):end, T(1):end, :) = S;
imshow(tran_S)
Hope this helps!