위키백과 ― 우리 모두의 백과사전.

Jump to: navigation, 찾기

이중선형 필터링(Bilinear filtering)은 컴퓨터 그래픽스에서 실제 크기보다 크거나 작게 표시되는 텍스쳐보간하는데 쓰는 방식이다.

텍스쳐를 씌운 도형을 화면에 그릴 때, 대부분의 경우는 텍스쳐가 왜곡 없이 저장된 정보 그대로 화면에 표시되지는 않는다. 하지만, 텍스쳐를 확대 축소시키거나 보는 시점을 바꾸면 텍스쳐 상의 픽셀(텍셀)이 튀어 보이게 된다. 이선형 필터링은 텍스쳐상의 임의의 텍셀과 그와 4방향으로 인접한 텍셀들의 중점에 대하여 선형 보간법을 수행하여 텍스쳐가 어떤 경우에라도 부드럽게 보일 수 있도록 한다.

[편집] 공식

다음 방정식에서 uk와 vk는 텍스쳐의 좌표이며, yk는 점 k의 색을 나타낸다. 첨자가 없는 값은 픽셀의 점을 나타내며, 첨자 0, 1, 2, 3을 가지는 값은 각각 픽셀과 인접해 있는 상, 좌, 우, 하의 텍셀을 나타낸다. 다음 이원일차 방정식은 선형 보간법 공식이다.

텍스쳐가 정사각형 비트맵이라고 가정하면

v_1 = v_0 \,\!
v_2 = v_3 \,\!
u_1 = u_3 \,\!
u_2 = u_0 \,\!
v_3 - v_0 = u_3 - u_0 = w \,\!

이 식이 모두 참이 된다. 나아가서 다음 식을 정의하면

U = \frac{u - u_0}{w} \,\!
V = \frac{v - v_0}{w} \,\!

이렇게 해서 보간법 방정식을 단순화시킬수 있다:

y_a = y_0 + (y_1-y_0)U \,\!
y_b = y_2 + (y_3-y_2)U \,\!
y = y_a + (y_b-y_a)V \,\!

위의 식을 결합시키면 다음과 같다:

y = y_0 + (y_1 - y_0)U + (y_2 - y_0)V + (y_3 - y_2 - y_1 + y_0)UV \,\!

다르게 표현하면:

y = y_0(1 - U)(1 - V) + y_1 U (1 - V) + y_2 (1 - U) V + y_3 U V \,\!

이 된다.

하지만, 이미지가 회전, 전단 이동 또는 시점 변환되는것이 아니라 단지 확대 및 축소만 할 경우에는, 따로 방정식을 만들고 yb (크기를 키울 경우에는 때때로 ya)를 다음 행에서 사용할 수 있도록 보관한다면 비교적 속도 향상을 꾀할 수 있다.

'알고리즘 > 이미지 처리' 카테고리의 다른 글

B-Spline을 활용하는 이미지 와핑 관련...  (0) 2008.03.06
역행렬 구하기  (0) 2008.03.05
이중선형 필터링  (0) 2008.03.05
Perspective projection matrix  (0) 2008.03.05
다각형을 가져오기 위한 노력...  (0) 2008.03.04
ImageWarping Processing  (0) 2008.02.26

We are looking for a $4\times4$ transformation matrix for homogeneous coordinates which will map the viewing frustum, a truncated pyramid as described earlier, onto the standard cube in homogeneous coordinates $-1\le x'/w'\le +1, -1\le y'/w'\le +1, -1\le z'/w'\le +1$:

  • First, we consider the case of symmetrical perspective projection with $\theta_y = 90^\circ$ and r=1 (square window). The central projection (with center in the origin) of the viewing frustum on the plane z=-1 is then the square [-1,+1]2.

    This central projection is described by the following transformation matrix:

     \begin{displaymath}\mathbf{P} =
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 &...
...\end{pmatrix}
=
\begin{pmatrix}x \\ y \\ z \\ -z \end{pmatrix}\end{displaymath} (11)

    Indeed: the resulting point has affine coordinates $(\frac{x}{-z}, \frac{y}{-z}, -1)$, which is precisely the intersection of the line from the origin to the point (x,y,z) with the z=-1 plane.

    This transformation suffices when we are not interested in z'. This is the case when no visible face determination is needed.

  • The projection matrix P in (15) leaves the z-coordinate unchanged. After division by w'=-z we always obtain z''=-1. Due to the perspective division it is no longer possible to determine z'' as a linear function of z, as was the case in the third step of §5.1. However, it is still possible to construct the projection matrix such that $z'' = \frac {z'}{w'}$ is a monotonically increasing (non-linear) function of the depth -z of the point, in the range [-1,+1]. Fortunately, this is all we need for visible surface determination.

    z' is determined by the coefficients in the third row of P. We will now determine those coefficients so as to obtain the desired effect. The new matrix is designated by Q. There is no need for z' to depend on x or y. Therefore, the first two coefficients can have value 0. We will call the last two coefficients a and b. An arbitrary point (x,y,z,1), in eye coordinates, is then transformed into:

    \begin{displaymath}\begin{pmatrix}x' \\ y' \\ z' \\ w' \end{pmatrix} =
\mathbf{Q...
...d\Longrightarrow\quad
\frac{z'}{w'} = \frac{a\cdot z + b}{-z}.
\end{displaymath} (12)

    We want to map $z_{\text {front}}$ onto -1 and $z_{\text{back}}$ onto +1:
    $\displaystyle \frac{a\cdot z_{\text{front}}+ b}{-z_{\text{front}}}$ = -1  
    $\displaystyle \frac{a\cdot z_{\text{back}}+ b}{-z_{\text{back}}}$ = +1 (13)

    These two relations lead to a set of two equations with two unknowns a and b. Their solution is:
     
    a = $\displaystyle \frac{z_{\text{front}}+z_{\text{back}}}{z_{\text{front}}-z_{\text{back}}}$  
    b = $\displaystyle \frac{-2\cdot z_{\text{front}}\cdot z_{\text{back}}}{z_{\text{front}}-z_{\text{back}}}.$ (14)

    Figure 5 shows how $\frac{z'}{w'}$ varies as a monotonically increasing, but non-linear function of z.


      
    Figure: The graphs below show how the normalized device z-coordinate $z'' = \frac {z'}{w'}$ (vertical axis) varies as a non-linear, monotonically increasing function of -z, the distance from a point to the eye XY-plane (horizontal axis) when using the matrix Q. In the three cases shown, $z_{\text {back}}=-100$. The value of $z_{\text {front}}$ is -10, -1 and -0.1 in the left, middle and right graph respectively. Notice that the closer $z_{\text {front}}$ comes to the eyepoint z=0, the less uniformly the Z-buffer is filled: a larger range of eye z-values will be mapped onto a smaller range of Z-buffer values (values close to $\frac {z'}{w'} = +1$). When the Z-buffer has only a limited resolution (e.g. 16 bits), hidden face elimination with the Z-buffer algorithm will not work well for points in the far distance: points with large depth differences could then be represented by the same discrete Z-buffer value. This is why in practice, one should take care to position the front clipping plane $z=z_{\text {front}}$ as far as possible from the eye point.

  • The matrix Q suffices for symmetrical perspective projection with $\theta_y = 90^\circ$ and r=1. The general case should first be reduced to this special case. This step corresponds to the second step in §5.1

    • A symmetrical perspective projection with $\theta_y \ne 90^\circ$ and/or $r \ne 1$ is reduced to the previous case by simply scaling x and yby $\mathbf{M_s}(\vec{S})$ (2). The scaling factors are $\vec{S} = (\frac{2}{W}, \frac{2}{H}, 1)$ with W and H given in (11) (check this yourself!). The complete projection matrix for symmetrical perspective is then:
       \begin{displaymath}\mathbf{Q}\cdot\mathbf{M_s}(\vec{S}) =
\begin{pmatrix}
\frac...
...xt{front}}-z_{\text{back}}} \\
0 & 0 & -1 & 0
\end{pmatrix}.
\end{displaymath} (15)

    • For asymmetrical perspective projection the frustum is first transformed such that its axis coincides with the negative Z-axis. This requires a translation perpendicular to the Z-axis, over a distance proportional to -z (see figure 6). The top of the frustum lies in the origin and should remain there. The center $(\frac{x_{\text{right}}+x_{\text{left}}}{2}, \frac{y_{\text{top}}+y_{\text{bottom}}}{2}, z_{\text{front}})$of the front plane of the frustum should be mapped onto $(0,0,z_{\text{front}})$. This is called a shearing-transformation. The required transformation matrix is (check for yourself!):
      \begin{displaymath}\mathbf{S} =
\begin{pmatrix}
1 & 0 & \frac{x_{\text{right}}+...
...om}}}{-2z_{\text{front}}} \cdot z \\
z \\
1
\end{pmatrix}.
\end{displaymath} (16)

      The projection on the z=-1 plane is now symmetrical about the Z-axis, but its dimensions are not yet correct. The shearing transformation is therefore followed by a scaling transformation $\mathbf{M_s}(\vec{S})$(2) with
      \begin{displaymath}\vec{S} = \left(\frac{-2z_{\text{front}}}{x_{\text{right}}-x_...
...z_{\text{front}}}{y_{\text{top}}-y_{\text{bottom}}}, 1\right).
\end{displaymath} (17)

      $\mathbf{M_s}(\vec{S})$ reduces the dimensions $\frac{x_{\text{right}}-x_{\text{left}}}{-z_{\text{front}}}$ and $\frac{y_{\text{top}}-y_{\text{bottom}}}{-z_{\text{front}}}$ of the projection in the z=-1 plane to 2 units in the x and the y direction. The complete asymmetrical perspective projection matrix is:
       \begin{displaymath}\mathbf{Q}\cdot\mathbf{M_s}(\vec{S})\cdot\mathbf{S} =
\begin{...
...xt{front}}-z_{\text{back}}} \\
0 & 0 & -1 & 0
\end{pmatrix}.
\end{displaymath} (18)

      You should verify that this transformation, followed by a division by w', yields the same x'' and y'' as in §5.1. The z'' however is different, but still adequate for hidden face elimination.


  
Figure 6: An asymmetrical perspective projection reduces to a symmetrical perspective projection by a shearing transformation: a translation perpendicular to the Z-axis over a distance proportional to -z. This transformation maps the frustum axis on the negative Z-axis.

출처 : http://www.cs.kuleuven.ac.be/cwis/research/graphics/INFOTEC/viewing-in-3d/node8.html

혹시모르는 페이지 저장.. 

'알고리즘 > 이미지 처리' 카테고리의 다른 글

역행렬 구하기  (0) 2008.03.05
이중선형 필터링  (0) 2008.03.05
Perspective projection matrix  (0) 2008.03.05
다각형을 가져오기 위한 노력...  (0) 2008.03.04
ImageWarping Processing  (0) 2008.02.26
PNG 분석자료들  (0) 2008.02.24

+ Recent posts