フィルターのクリア

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

15 ビュー (過去 30 日間)
Haytham Ali
Haytham Ali 2022 年 4 月 14 日
編集済み: Umeshraja 2024 年 9 月 21 日 12:12
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 Center および File ExchangeRead, 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