Translation of a matrix

조회 수: 39 (최근 30일)
Angela Ebirim
Angela Ebirim 2019년 10월 22일
답변: Sai Bhargav Avula 2019년 10월 31일
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')

답변 (1개)

Sai Bhargav Avula
Sai Bhargav Avula 2019년 10월 31일
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!

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by