Borrar filtros
Borrar filtros

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

15 visualizaciones (últimos 30 días)
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

Respuestas (1)

Umeshraja
Umeshraja el 17 de Sept. de 2024 a las 8:36
Editada: Umeshraja el 21 de Sept. de 2024 a las 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!

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by