[CV] Computer Vision(2-2): Image Processing - Geometric Transformation
๐Computer Vision ์ ๋ฆฌ
Geometric Transformation
Geometric ๊ฐ๋ ์ ๋ฆฌ
์ฃผ์: ์ด ์ฌ๋ผ์ด๋์ ๋์์๋ ์ ๋ค์ ์ขํ๋ค์ (x-์ขํ,y-์ขํ)๋ก ํ๊ธฐ๋์ด์์
์ฆ, computer vison์์๋ (y,x)๋ก ๋ฐ๊ฟ์ผํจ
- Scalar: real number (only magnitude), (e.g., distance)
- Vector: direction + magnitude
- Point: a location in space
- ๋ฒกํฐ์ ํฉ, ๊ณฑ ๋ฑ๋ฑ
- ๋ฒกํฐ + ๋ฒกํฐ = ๋ฒกํฐ / ๋ฒกํฐ * ์ค์นผ๋ผ = ๋ฒกํฐ
Parametric Form & Affine Sum
Dot Product(๋ด์ )
$\vec{a}\cdot\vec{b} = 0$ โ ๋ ๋ฒกํฐ ์์ง
Cross Product(์ธ์ )
๋ฐฉํฅ: $\vec{a}, \vec{b}$์ ๋ชจ๋ ์์ง, ์ค๋ฅธ์ ๋ฒ์น ๋ฐ๋ฆ
๊ฒฐ๊ณผ ๋ฒกํฐ ํฌ๊ธฐ(axb): ํํ์ฌ๋ณํ ๋์ด
2D Geometric Transformation
2์ฐจ์ ํฌ์ธํธ๋ $(x,y)$ or $x=\begin{bmatrix}x \\ y\end{bmatrix}$๋ก ํํ๊ฐ๋ฅ
- linear transformation: ์ด๋ค ํ๋ ฌ์ ์ด์ฉํด ๋ฒกํฐ๋ฅผ ๋ณํํ๋ ๊ฒ
์ ์์ ์ ์ผ๋ก ๊ฐ๋ mapping์ ํํํ๊ธฐ ์ํด ์ ํ ๋ณํ์ ์ฌ์ฉ
2์ฐจ์์ ๊ฒฝ์ฐ 2x2์ ์ด์ฉํด ๋ณํ
์ ํ ๋ณํ ์กฐ๊ฑด:$L(a+b) = L(a) + L(b)$
$L(sa) = sL(a)$
2D Scaling
- Scaling: changes length (and direction)
๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ๋ณ๊ฒฝํ๊ณ ์ ํ๋ ๊ฐ์ ์ฐ๋ฉด ๋จ
$s_x = s_y$: ๊ท ์ผ ์ค์ผ์ผ๋ง (uniform scaling) โ ๋ชจ์์ ๊ทธ๋๋ก ํฌ๊ธฐ๋ง ๋ณํจ
$s_x \neq s_y$: ๋น๊ท ์ผ ์ค์ผ์ผ๋ง (non-uniform) โ ํํ๊ฐ ์ฐ๊ทธ๋ฌ์ง ์ ์์
2D Rotation
- Rotation: ๋ฒกํฐ๋ฅผ ๊ฐ๋ $\theta$๋งํผ ๋ฐ์๊ณ ๋ฐฉํฅ์ผ๋ก ํ์ ์ํค๋ ๋ณํ
โ ๋ฒกํฐ $a=(x_a, y_a)$๋ ๋ค์ ๋ ๊ฐ์ง ๋ฐฉ์์ผ๋ก ํํ ๊ฐ๋ฅ:
- ์ง๊ต ์ขํ๊ณ(cartesian coordinates): $(x_a, y_a)$
- ๊ทน์ขํ๊ณ(polar coordinates): $(r\cos\alpha, r\sin\alpha)$
- $r$์ ๋ฒกํฐ์ ๊ธธ์ด: $r = \sqrt{(x_a^2 + y_a^2)}$
- $\alpha$๋ x์ถ๊ณผ ๋ฒกํฐ๊ฐ ์ด๋ฃจ๋ ๊ฐ๋
๋ฒกํฐ a๋ฅผ ๊ฐ๋ $\theta$๋งํผ ๋ฐ์๊ณ ๋ฐฉํฅ์ผ๋ก ํ์ ์ํจ ๋ฒกํฐ b๋ ๋ค์๊ณผ ๊ฐ๋ค:
- $x_b = r\cos(ฮฑ + \theta) = r\cos ฮฑ\cos\theta - r\sin ฮฑ\sin\theta$
- $y_b = r\sin(ฮฑ + \theta) = r\sin ฮฑ\cos\theta + r\cos ฮฑ\sin\theta$
- ์ด๋ $r\cos\alpha = x_a$์ $r\sin\alpha = y_a$์ด๋ฏ๋ก
- $x_b = x_a\cos\theta - y_a\sin\theta$
- $y_b = y_a\cos\theta + x_a\sin\theta$
(xb, yb)๋ฅผ
matrix
๋ก ๋ํ๋ด๋ฉด ์ฌ์ง๊ณผ ๊ฐ์ 2D rotation๋ 2x2๋ก ๊ณ์ฐ์ด ๋๊ธฐ ๋๋ฌธ์ linear transformation ์ด๋ค.
โ Rotation Properties
- Orthogonal matrix(์ง๊ต ํ๋ ฌ): Two columns (rows) are orthogonal(์๋ก ๋ด์ ์ ํ์ ๋ 0์ด ๋ ๋)
- (cos๐,sin๐)โโ(sin๐,cos๐)=0
- inverse matrix(์ญํ๋ ฌ)
2D Shear
- Shear: ๋ฌผ์ฒด๋ฅผ ํ ๋ฐฉํฅ์ผ๋ก โ๋ฐ์ด๋ด๋โ ๋ณํ, ํํ์ฌ๋ณํ ๋ชจํ์ผ๋ก ๋ณํ๋๋ค.
X, Y ๋ฐฉํฅ shear๋ ๋ค์๊ณผ ๊ฐ๋ค:
shear_x(s)
= $ \begin{bmatrix} 1 & s \\ 0 & 1 \end{bmatrix}$shear_y(s)
= $ \begin{bmatrix} 1 & 0 \\ s & 1 \end{bmatrix}$shear_x(s) ๋ณํ์ด ์ (x,y)์ ์ ์ฉ๋๋ฉด $xโ = x+sy, yโ=y$ ์ฆ y์ขํ๋ ๋ณํ์ง ์๊ณ , x์ขํ๋ y์ขํ์ ๋น๋กํ์ฌ ์ด๋
x๋ฐฉํฅ์ผ๋ก shearingํ ๋์ ์์
y๋ฐฉํฅ์ผ๋ก shearingํ ๋์ ์์
2D Reflection
- Reflection: ์ขํ ์ถ์ ๊ธฐ์ค์ผ๋ก ๋ฌผ์ฒด๋ฅผ โ๋ค์ง๋โ ๋ณํ
X, Y ๋ฐฉํฅ Reflection๋ ๋ค์๊ณผ ๊ฐ๋ค:
reflect_x
= $ \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}$reflect_y
= $ \begin{bmatrix} -1 & 0 \\ 0 & 1 \end{bmatrix}$reflect_x ๋ณํ์ด ์ (x,y)์ ์ ์ฉ๋๋ฉด $xโ = x, yโ=-y$
์ฆ, y์ขํ๋ง ๋ถํธ๊ฐ ๋ฐ๋๋ค
2D Translation
- Translation: ๋ฌผ์ฒด์ ๋ชจ๋ ์ ์ ๋์ผํ ๊ฑฐ๋ฆฌ์ ๋ฐฉํฅ์ผ๋ก ์ด๋์ํค๋ ๋ณํ
์ด๋ ๋ณํ ์์:
- $xโ = x + x_t$
- $yโ = y + y_t$
$(x_t,y_t)$๋ ์ด๋ ๋ฒกํฐ
์ผ๋ฐ์ ์ธ 2x2ํ๋ ฌ๋ก๋ Translation์ ๋ํ๋ผ ์ ์๋ค!
๊ทธ๋ผ ์ด๋ป๊ฒ ๊ณ์ฐํด์ผํ๋? โ ๊ทธ๋์ ๋์จ ์ด๋ก ์ด Homogeneous Coordinate
Homogeneous Coordinate
Homogeneous Coordinate(๋์ฐจ ์ขํ๊ณ): ๋์ฐจ ์ขํ๊ณ๋ ๊ธฐ์กด์ ์ขํ๊ณ๋ฅผ ํ์ ํ์ฌ, ์ ,์ ,๋ฉด ๋ฑ์ ์ผ๊ด๋ ๋ฐฉ์์ผ๋ก ํํํ๊ณ ๋ณํํ ์ ์๊ฒ ํ๋ค.
- 2์ฐจ์์์ ์ $x = (x,y)$๋ ๋์ฐจ ์ขํ๊ณ์์ ๋ค์๊ณผ ๊ฐ๋ค.
$\tilde{x}$๋ ๋์ฐจ ์ขํ๊ณ์์์ ์
$\bar{x} = (x,y,1)$์ ์ฆ๊ฐ ๋ฒกํฐ(augmented vector)
$\tilde{w} \neq {0}$์ธ ๋ชจ๋ $(\tilde{x},\tilde{y},\tilde{w})$๋ 2D ์ $\tilde{x}/\tilde{w}, \tilde{y}/\tilde{w}$๋ฅผ ๋ํ๋ธ๋ค
์ฆ, ๋์ฐจ ์ขํ๊ณ์์๋ (2,3,1), (4,6,2), (6,9,3) ๋ชจ๋ 2D ๊ณต๊ฐ์์ ๊ฐ์ ์ (2,3)์ ๋ํ๋ธ๋ค!
- ๋ง์ฝ $\tilde{x}$ = (x,y,0)(=$\tilde{w}$=0)์ด๋ฉด ์ด point๋ ideal point ๋๋ point at infinity๋ผ๊ณ ๋ถ๋ฆฐ๋ค
2D Lines
Homogeneous Corrdinate์์ 2D line: $\tilde{l} = (a,b,c)$
- ์ง์ ์ ๋ฐฉ์ ์: $\bar{x}\cdot\tilde{l} = ax + by + c = 0$
- $\tilde{l}$์ ์ ๊ทํ:
- $l = (\hat{n}x, \hat{n}y, d) = (\hat{n}, d), \parallel\hat{n}\parallel = 1$
$\hat{n}$: ์ง์ ์ ์์ง์ธ ๋จ์ normal vector
$\hat{n} = (\hat{n}x, \hat{n}y) = (\cos\theta, \sin\theta)$
d: ์์ ์์ ์ง์ ๊น์ง ๊ฑฐ๋ฆฌ
$(\theta, d)$: ๊ทน์ขํ๊ณ
- $l = (\hat{n}x, \hat{n}y, d) = (\hat{n}, d), \parallel\hat{n}\parallel = 1$
- $l$ = (0,0,1): ๋ฌดํ๋์ ์๋ ์ง์ ์ผ๋ก, ๋ชจ๋ ๋ฌดํ๋ ์ ๋ค์ ํฌํจํจ
Homogeneous Matrix
- ๋์ฐจ ์ขํ๊ณ์์์ 2D ๋ณํ์ ๋ค์๊ณผ ๊ฐ์ด ๋ณํ๋ค
์์๋๋ก
Rotation
,scale
,translation
๋ณํ
- ์ฌ๋ฌ ๋ณํ์ ์กฐํฉํ๋ ค๋ฉด ๊ฐ ๋ณํ ํ๋ ฌ์ ๊ณฑํ๊ธฐ๋ง ํ๋ฉด ๋๋ค!
ํ๋ ฌ์ ๊ณฑํ ๋๋ ์ ์ฉํ ํ๋ ฌ์ ๋ฐ๋ ์์๋ก ๊ณฑํด์ผํ๋ค!
- ๋ณตํฉ ๋ณํ ์์:
์์์์๋ ์์ ์ผ๋ก ์ด๋ โ Rotation ๋ณํ โ ๋ค์ ์๋์ ์์น๋ก ์ด๋์ด๋ฏ๋ก
1
T_final = T_translation(์๋ ์์น๋ก ์ด๋) ร T_rotation x T_translation(์์ ์ด๋)
๋ค์ CV๊ด์ ์ผ๋ก ๋์์์ (y,x) ์ขํ๊ณ์์์ Homogeneous Matrix๋ ๋ค์๊ณผ ๊ฐ๋ค
2D Transformation์ ์ข ๋ฅ์ ํน์ฑ:
DoF๋ ์์ ๋(์ฐ๋ฆฌ๊ฐ ๋ณํํ๋ ์)
Similarity์์ DoF: 4(์ค์ผ์ผ 1๊ฐ, ํ์ 1๊ฐ, ์ด๋ 2๊ฐ)
์ ์นํ๋ ฌ T์ธ ์ด์ ๋ ์ฌ์ง์ (x,y)์ด๊ธฐ ๋๋ฌธ
๊ทธ๋ผ ์ด๋ฏธ์ง์ Geometric Transformation์ ์ด๋ป๊ฒ ์ ์ฉ์ด ๋๋๊ฐ?
Geometric Transformation ์ ์ฉ
- Foward warping:
- ์์ค ์ด๋ฏธ์ง์ ๊ฐ ํฝ์ ์ ๋ณํํ์ฌ ๋์ ์ด๋ฏธ์ง์ ์์น๋ก ๋งคํ
- ๋ฌธ์ ์ :
- ์จ๋ฆฌ์ด์ฑ(aliasing) ์ํฐํฉํธ๊ฐ ๋ฐ์ํ ์ ์๋ค.
- ์์ค ์ด๋ฏธ์ง์ ํฝ์ ์ด ์ ํํ ๋์ ์ด๋ฏธ์ง์ ํฝ์ ๊ฒฉ์์ ๋ง์ง ์์ ์ ์์ด ๋น ๊ณต๊ฐ(ํ)์ด ์๊ธธ ์ ์๋ค.
- Inverse warping:
- ๋์ ์ด๋ฏธ์ง์ ๊ฐ ํฝ์ ์์น์ ๋ํด, ์์ค ์ด๋ฏธ์ง์์ ๊ฐ์ ๊ฐ์ ธ์จ๋ค
- ํ์ง๋ง ์ฌ๊ธฐ์๋ ๋ค๋ฅธ ๋ ๊ฐ์ ๋์ ํฝ์ ์ด ๊ฐ์ ์์ค ํฝ์ ์ ์ฐธ์กฐํ๋ฏ๋ก ์จ๋ฆฌ์ด์ฑ ๋ฐ์
์จ๋ฆฌ์ด์ฑ์ ํด๊ฒฐํ๊ธฐ ์ํด Interpolation์ผ๋ก ๋ณด์ํ๋ค
Interpolation
Interpolation: ์๋ ค์ง ๋ฐ์ดํฐ ํฌ์ธํธ ์ฌ์ด์ ์ค๊ฐ ๊ฐ์ ์ถ์ ํ๋ ๋ฐฉ๋ฒ
1D Linear Interpolation๊ณผ 2D Bilinear Interpolation
- 1D Linear Interpolation: ๋ ๊ฐ์ ์๋ ค์ง ๋ฐ์ดํฐ ํฌ์ธํธ ์ฌ์ด์ ๊ฐ์ ์ง์ ์ผ๋ก ๊ทผ์ฌํ์ฌ ์ถ์
2D Bilinear Interpolation: ์๋ ค์ง ๋ค ๊ฐ์ ๊ฒฉ์์ (grid points) ์ฌ์ด์ ๊ฐ์ ์ถ์
- lecture 5์ Edge Thinning์ ์ํ X