- affinetform2d : https://www.mathworks.com/help/images/ref/affinetform2d.html
- imwrap: https://www.mathworks.com/help/images/ref/imwarp.html
I want to calculate the affine transformation matrix (rotation, translation and scaling) for the binary image
조회 수: 11 (최근 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
댓글 수: 0
답변 (1개)
Umeshraja
2024년 9월 17일
편집: Umeshraja
2024년 9월 21일
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File 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!