


💡 회전변환이 선형변환인 이유
회전 변환은 벡터 공간에서 벡터의 방향을 변경하는 변환으로 회전 행렬을 사용하여 수행된다.
이때, 이 행렬은 벡터에 곱하여 해당 벡터를 회전시키며, 선형 변환의 두가지 핵심 성질을 만족한다.
선형 변환의 핵심 성질
덧셈에 대해 닫힘 : 두 벡터 v1와 v2의 합을 먼저 회전한 결과와, 각 벡터를 회전한 후 그 합을 구하는 것이 동일
스칼라 곱에 대해 닫힘 : 벡터 v와 스칼라 α에 대해 스칼라 배수를 곱한 후 회전한 결과는, 벡터를 회전시킨 후 스칼라 배수를 곱한 것과 동일
닫힘: 특정연산을 적용한 후 결과가 원래 벡터 공간에 여전히 속한다.
- 따라서, 회전변환의 경우 선형 변환으로 볼 수 있다.
예시
p = [1 0; 2 0; 2 1; 1 1; 1 0];
plot(p(:,1), p(:,2), '.-', 'markersize', 20, 'linewidth', 2)
axis([-4 4 -4 4]); hold on
thetas = [30 70 180 225 270];
for i = 1:length(thetas)
theta = thetas(i);
ang = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
trans = ang*p';
trans = trans';
plot(trans(:,1), trans(:,2), '.-', 'markersize', 20, 'linewidth', 2)
end
hold off

cosd(), sind()를 사용하였다.응용 (집 그림 회전)
X = [-6 -6 -7 0 7 6 6 -3 -3 0 0;
-7 2 1 8 1 2 -7 -7 -2 -2 -7]
subplot(1, 2, 1)
trans(X, 0) % 회전 변환을 하지 않은 이미지
title('original image')
subplot(1, 2, 2)
trans(X, 270) % 270도 회전 변환을 적용한 이미지
title('rotationed image')
function trans(X, theta)
X(:, end+1) = X(:, 1);
ang = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
trans = ang * X;
plot(trans(1, :), trans(2, :), '.-', 'markersize', 20, 'lineWidth', 2)
axis(10 * [-1 1 -1 1])
axis square
end

ginput을 이용한 회전변환 구현
clear all;figure;axis(10*[-1 1 -1 1])
[x,y] = ginput; p = [x y]';
plot(p(1,:),p(2,:),'.-','markersize',20,'linewidth',2)
hold on
theta=180;
ang=[cosd(theta) -sind(theta);sind(theta) cosd(theta)];
trans=ang*p;
plot(trans(1,:),trans(2,:),'.-','markersize',20,'linewidth',2)
hold off
ginput 함수는 그래픽 창에서 마우스를 클릭하여 입력을 받는다.
이미지 좌우/상하 반전
% 이미지 로드 및 크기 확인
A = imread('image.jpg');
% 창 위치 및 크기 조정
figure('Position', [200, 200, 800, 500]);
% original image 출력
subplot(1, 2, 1);
image(A)
title('original image')
% 상하/좌우 변환 입력
answer = input("Enter lrflip or tbflip : ", "s");
[rows, cols, ch] = size(A);
% 변환 행렬 설정
if strcmp(answer, 'tbflip')
ang = [1 0
0 -1];
elseif strcmp(answer, 'lrflip')
ang = [-1 0
0 1];
else
error('Wrong input. Please enter a valid option.');
end
transformed_A = zeros(rows, cols, ch, 'uint8');
% 중심 좌표
h = (1 + cols) / 2;
k = (1 + rows) / 2;
for x = 1:cols
for y = 1:rows
coord = [x - h; y - k];
trans = ang * coord;
trans = trans';
new_x = trans(1) + h; % 변환된 x 좌표
new_y = trans(2) + k; % 변환된 y 좌표
transformed_A(new_y, new_x, :) = A(y, x, :); % y축 -> rows, x축 -> cols
end
end
subplot(1, 2, 2);
image(transformed_A)
title('transformed image')

