부동소수점 데이터는 꼴로 표현된다. (음수일 경우와 0일 경우는 무시했다.)
여기서 두 가지 경우로 나누어보자.

첫번째 n=2k 인 경우
가 된다.

두번째 n=2k+1 인 경우
가 된다.
http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=%5Csqrt%7B2%7D는 상수이므로, 컴파일 타임에 결정되므로 크게 상관하지 않아도 좋다.
여기서 중요한것은 실질적으로 우리가 계산해야할 값은 http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=%5Csqrt%7B%5Calpha%7D라는 것이다.
k는 n을 2로 나눈값이므로 시프트 연산만으로 구현할 수 있기 때문이다.

http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=%5Csqrt%7B%5Calpha%7D를 어떻게 구할까?
이를 예견한것인지는 몰라도 뛰어난 수학자들이 몇 세기전에 좋은 해결방법을 만들어 놓았다.
그 이름은 바로 테일러 급수.

http://www.sitmo.com/gg/latex/latex2png.2.php?z=150&eq=%5Csqrt%7B1%20%2B%20x%7D%20%3D%201%20%2B%20%5Ctextstyle%20%5Cfrac%7B1%7D%7B2%7Dx%20-%20%5Cfrac%7B1%7D%7B8%7Dx%5E2%20%2B%20%5Cfrac%7B1%7D%7B16%7D%20x%5E3%20-%20%5Cfrac%7B5%7D%7B128%7D%20x%5E4%20%2B%20%5Cdots%5C!
단 ( |x| < 1 이어야한다.)
자세한 것은 위키백과 테일러 급수 참조

http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=%5Calpha%3D1%2Bx라고 하면 http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=0%5Cle%20x%3C1가 된다.
따라서 위 테일러 전개식의 수렴조건도 만족한다. 적당한 부분까지 테일러 전개식에 대입하여 http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=%5Csqrt%7B%5Calpha%7D를 구해내면된다.
게다가 부동소수점 데이터의 특성상 곧바로 x값을 구할수 있다.

더보기


그리고 위 식을
http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=1%2B%5Cfrac%7B1%7D%7B2%7Dx(1-%5Cfrac%7B1%7D%7B4%7Dx(1-%5Cfrac%7B1%7D%7B2%7Dx(1-%5Cfrac%7B5%7D%7B8%7Dx(%5Cldots))))
이렇게 묶어내면 연산횟수를 줄일 수 있다.

이 정도면 꽤 최적화된 제곱근 계산하는 함수를 구현할수 있을것이다
by 쿠리다쿠리 2010. 3. 23. 19:12

From Wikipedia:
이미지 Gradient를 계산하기 위한 방법은 Sobel, Canny등과 같은 다양한 Edge Filter를 이용하는 방법도 있을 수 있으나,
가장 간단한 방법은 다음과 같이 주변 Pixel간의 차이값을 이용하는 방법이다.

L_x(x, y)=-1/2\cdot L(x-1, y) + 0 \cdot L(x, y) + 1/2 \cdot L(x+1, y).\,
L_y(x, y)=-1/2\cdot L(x, y-1) + 0 \cdot L(x, y) + 1/2 \cdot L(x, y+1).\,

위의 수식을 입력 이미지에 대한 Filter mask(Matrix)형태로 표시하면 다음과 같다.


L_x = \begin{bmatrix} 
-1/2 & 0 & 1/2 
\end{bmatrix} * L
\quad \mbox{and} \quad 
L_y = \begin{bmatrix} 
+1/2 \\
0 \\
-1/2
\end{bmatrix} * L

가중치값 1/2은 경우에 따라 달라질 수 있으며 HOG 연산에는
Lx(x,y) = -L(x-1, y)+0*L(x,y)+L(x+1, y)
Ly(x,y) = -L(x, y-1)+0*L(x,y)+L(x, y_1)을 적용한다
이를 Filter mask(Matrix)형태로 표시하면 [-1, 0, 1]과 같다.


by 쿠리다쿠리 2010. 3. 23. 16:20

From Wikipedia atan2(x)
삼각법에서 atan2는 아크탄젠트함수에 대한 2 argument를 가지는 변형함수로 positive x축에서 좌표 (x, y)까지의 각도를 라디안(radian)으로 반환한다.
 atan2함수는 컴퓨터 프로그래밍 언어에서 처음 도입되었으나 현재는 과학, 엔지니어링 분야에서 일반적으로 사용되고 있다.
atan2(x, y)함수는 다음과 같은 조건으로 atan함수로 표현될 수 있다.

\operatorname{atan2}(y, x) = \begin{cases}
\arctan(\frac y x) & \qquad x > 0 \\
\pi + \arctan(\frac y x) & \qquad y \ge 0 , x < 0 \\
-\pi + \arctan(\frac y x) & \qquad y < 0 , x < 0 \\
\frac{\pi}{2} & \qquad y > 0 , x = 0 \\
-\frac{\pi}{2} & \qquad y < 0 , x = 0 \\
\text{undefined} & \qquad y = 0, x = 0
\end{cases}

Notes:

  • This produces results in the range (-π,π], which can be mapped to [0,2π) by adding 2π to negative values.
  • Traditionally, atan2(0,0) is undefined.
    • The C function, and most other computer implementations, are designed to reduce the effort of transforming cartesian to polar coordinates and so always define atan2(0,0). On implementations without signed zero, or when given positive zero arguments, it is normally defined as 0. It will always return a value in the range [-π,π] rather than raising an error or returning a NaN (Not a Number).
    • Systems supporting symbolic mathematics normally return an undefined value for atan2(0,0) or otherwise signal that an abnormal condition has arisen.
  • For systems, for example IEEE floating point, implementing signed zero, infinities, or Not a Number it is usual to implement reasonable extensions which may extend the range of values produced to include -π and -0. These also may return NaN or raise an exception when given a NaN argument.
by 쿠리다쿠리 2010. 3. 23. 16:05