Magnitude and direction of image gradient geometrically

2.9k Views Asked by At

I want to understand how the calculation of the image gradient magnitude and direction make sense. The magnitude of the image gradient is given by $\sqrt{G_x^2+G_y^2}$ and the direction by $\tan \theta=\frac{G_y}{G_x}$, where $G_x,G_y$ are the partial derivatives. So it makes sense if $G_x$ and $G_y$ form a right angled triangle. But if we plot the image function in 3 dimensions, both $G_x$ and $G_y$ is a change in $z$–direction, so I cannot see how the vectors can be orthogonal.

1

There are 1 best solutions below

0
On

Here is how I would see it. Let $\mathcal{P}(x,y)$ be the pixel value function. Then its gradient is: $$ f(x,y) = \nabla \mathcal{P}(x,y) = (f_x(x,y), f_y(x,y)) $$ i.e. $f:\mathbb{R}^2 \rightarrow \mathbb{R}^2$, which is a vector at each point in the image.

Now, a vector has a magnitude $M(x,y)$ and a direction. The magnitude is: $$ M(x,y) = || f(x,y) ||_2 = \sqrt{f_x(x,y)^2 + f_y(x,y)^2} $$ But how do we represent the direction? One way is to use the vector itself as a normalized unit vector, i.e. $$ \widehat{d}(x,y) = \frac{f(x,y)}{M(x,y)} $$ But we are in 2D, so we can actually just represent the direction with one angle, $\theta$. Arbitrarily, we can choose the angle to be with respect to the positive $x$-axis. Then, we are considering a right triangle with the one non-hypotenuse side being $f_x(x,y)$ and the other being $f_y(x,y)$. Thus, the angle with the $x$-axis satisfies: $$ \tan(\theta(x,y)) = \frac{f_y(x,y)}{f_x(x,y)} \;\;\; \implies \;\;\; \theta(x,y) = \arctan\left( \frac{f_y(x,y)}{f_x(x,y)} \right) $$