회전 변환과 기하학적 변환의 조합

BERT·2023년 4월 24일
0

Computer Vision

목록 보기
26/56

회전 변환(rotation transform)

영상을 특정 각도만큼 회전시키는 변환
OpenCV는 반시계 방향을 기본으로 사용

{x=cosθx+sinθyy=sinθx+cosθy\begin{cases} x'=cos\theta\cdot x+sin\theta\cdot y \\ y'=-sin\theta\cdot x+cos\theta\cdot y \end{cases}

[xy]\begin{bmatrix} x' \\ y' \end{bmatrix}=[cosθsinθ0sinθcosθ0]\begin{bmatrix} cos\theta & sin\theta & 0 \\ -sin\theta & cos\theta & 0 \end{bmatrix}[xy1]\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

회전 변환과 역방향 매핑

회전 변환도 역방향 매핑으로 구현해야 빈 픽셀이 발생하지 않음

[xy]\begin{bmatrix} x \\ y \end{bmatrix}=[cosθsinθsinθcosθ]1\begin{bmatrix} cos\theta & sin\theta \\ -sin\theta & cos\theta \end{bmatrix}^{-1}[xy]\begin{bmatrix} x' \\ y' \\ \end{bmatrix}=[cosθsinθsinθcosθ]\begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{bmatrix}[xy]\begin{bmatrix} x' \\ y' \\ \end{bmatrix}

보간법 선택 가능

영상의 회전 변환 행렬 구하기

center : 회전 중심 좌표
angle : 회전 각도
scale : 회전 후 확대 비율
return : 2x3 double (CV_64F) 행렬
[αβ(1α)center.xβcenter.yβαβcenter.x+(1α)center.y]\begin{bmatrix} \alpha & \beta & (1-\alpha)\cdot center.x-\beta\cdot center.y \\ -\beta & \alpha & \beta\cdot center.x+(1-\alpha)\cdot center.y \\ \end{bmatrix}

{α=scalecos(angle)β=scalesin(angle)\begin{cases} \alpha=scale\cdot cos(angle) \\ \beta=scale\cdot sin(angle) \end{cases}

Mat getRotationMatrix2D(Point2f center, double angle, double scale);

src : 입력 영상
dst : 출력 영상
M : 2x3 어파인 변환 행렬
dsize : 결과 영상의 크기
flags : 보간법 선택
borderMode : 가장자리 픽셀 처리 방식
borderValue : BORDER_CONSTANT 모드 사용 시 사용할 픽셀 값

void warpAffine(InputArray src, 
				OutputArray dst, 
                InputArray M, 
                Size dsize,
                int flags = INTER_LINEAR,
                int borderMode = BORDER_CONSTANT,
                const Scalar& borderValue = Scalar());

rotate

이동, 크기, 회전 변환 조합

이동 변환 \rarr 크기 변환 \rarr 회전 변환
[xy]\begin{bmatrix} x' \\ y' \end{bmatrix}=[cosθsinθsinθcosθ]\begin{bmatrix} cos\theta & sin\theta \\ -sin\theta & cos\theta \end{bmatrix}[sx00sy]\begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix}([xy]+[ab])\bigg(\begin{bmatrix} x \\ y \\ \end{bmatrix}+\begin{bmatrix} a \\ b \\ \end{bmatrix}\bigg)

동차 좌표계

homogenous coordinates
차원의 좌표를 1차원 증가시켜 표현하는 방법
이동 변환 \rarr 크기 변환 \rarr 회전 변환

[xy1]\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}=[cosθsinθ0sinθcosθ0001]\begin{bmatrix} cos\theta & sin\theta & 0 \\ -sin\theta & cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix}[sx000sy0001]\begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{bmatrix}[10a01b001]\begin{bmatrix} 1 & 0 & a \\ 0 & 1 & b \\ 0 & 0 & 1 \end{bmatrix}[xy1]\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

=[a11a12a13a21a22a23001]\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ 0 & 0 & 1 \end{bmatrix}[xy1]\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

대칭 변환

영상의 대칭 변환(flip, reflection)
영상의 상하 대칭, 좌우 대칭, 원점 대칭
src : 입력 영상
dst : 출력 영상
flipCode : 대칭 방향 지정

void flip(InputArray src, OutputArray dst, int flipCode);

0개의 댓글