Applying homogenous transformation matrix to image to demonstrate translation, rotation and scaling. I tried it by using affine3d but getting some errors.

2 views (last 30 days)
file = 'boku-no-hero-academia-head-bang.png';
A = imread(file);
% imshow(A);
% tranformation
z= input("enter angle in Z axis roatation");
z=z*pi/180;
Rz=[cos(z) -sin(z) 0;sin(z) cos(z) 0;0 0 1];
t=zeros(1,3);
for i=1:3
t(i)=input("enter translation vector");
end
T=[Rz;t];
s=input("enter scaling factor");
T(4,4)=s;
tform_transform=affine3d(T);
I=imwarp(A,tform_transform);
image(I);

Accepted Answer

Matt J
Matt J on 30 Sep 2021
Edited: Matt J on 30 Sep 2021
Since the image is 2D, you need to use affine2D() and your T matrix must be 3x3.
file = 'cameraman.tif';
A = imread(file);
z=30*pi/180;
Rz=[cos(z) -sin(z) 0;sin(z) cos(z) 0;0 0 1];
t=[5,10];
s=1.1;
T=Rz;
T(3,1:2)=t;
T(1:2,:)=(1/s)*T(1:2,:);
tform_transform=affine2d(T);
I=imwarp(A,tform_transform);
image(I);

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!