I want to calculate the affine transformation matrix (rotation, translation and scaling) for the binary image

15 次查看(过去 30 天)
I want to calculate this matrix consisting of rotation, translation and scaling of binary image, how can I calculate this matrix using Matlab in one loop
Thanks in advance

回答(1 个)

Umeshraja
Umeshraja 2024-9-17,8:36
编辑:Umeshraja 2024-9-21,12:12
I understand that you wanted to perform an affine transformation on a binary image. You can achieve this using the 'affinetform2d' and 'imwarp' functions of MATLAB's Image Processing Toolbox..
Below is a demonstration of how you can calculate the transformation matrix that includes rotation, scaling, and translation, and then apply it to your binary image.
close all;
% Load a grayscale image
img = imread('cameraman.tif');
% Convert the image to binary using a threshold
% Here, we use a threshold of 128 for demonstration
I = img > 128;
% Define transformation parameters
Theta = 90; % angle of rotation
Scale = 1.5;
a = 2; % translation along x-axis
b = 4; % translation along y-axis
% Calculate the transformation matrix
%Rotation
Thrad = Theta * pi / 180;
R = [ cos(Thrad) -sin(Thrad) 0;
sin(Thrad) cos(Thrad) 0;
0 0 1 ];
%Scaling
S = [Scale 0 0;
0 Scale 0;
0 0 1 ];
%Transform
T = [ 1 0 a;
0 1 b;
0 0 1 ];
% Combine the transformations
RST = R * S * T;
% Create affine transformation object
t_aff = affinetform2d(RST);
% Apply transformation to the binary image
binaryImage_affine = imwarp(I, t_aff);
figure;
imshow(I)
title("Original")
% Display the transformed binary image
figure;
imshow(binaryImage_affine);
title("Transformed Binary Image");
For more information, refer to the following documentation:
I hope it helps!

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by