I have a question about image gradient magnitude, given an image $I$. The horizontal and vertical derivatives resulting from Sobel filters are defined as: $$K_x= \begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \\ \end{bmatrix}*I; K_y= \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \\ \end{bmatrix}*I $$

where $*$ denotes the convolution operator. The gradient magnitudes can be computed as


Now, I want to "invert" the result of $I_{\delta}$, so that maximum magnitude gradient values become zero. Then the "inverting" function $g$ is $$g(I_{\delta})=\max (I_{\delta}) - I_{\delta}\,.$$

My question is: is $I_{\delta}$ scalar or vector? What do you think? If it is possible, could you correct help me.

  • $\begingroup$ I have strongly edited your question. I hope it looks more precise now. I have changed the $|I|$ notation into $I_\delta$ because I found it confusing. Feel free to re-edit if necessary $\endgroup$ Commented Nov 15, 2015 at 10:32
  • $\begingroup$ @LaurentDuval: What is different betwen $I_{\delta}$ and $|I|$, If I put above function $g$ in an integrate as $\int_\Omega g(|I|) dx$ or $\int_\Omega g(I_{\delta}) dx$, which one is correct? $\endgroup$
    – Jame
    Commented Apr 16, 2016 at 14:09

2 Answers 2


Pretty much by definition, the magnitude of anything is a scalar value. Though, since you are working on an image, the result is a 2D array of scalar values.

Given Kx and Ky, it's also possible to work out the directions of the edges, as well as the magnitudes, but that's a whole different bit of maths.

  • $\begingroup$ Thank Simon B. The above magnitude just Sobel magnitude. I just show it in the question to make more clear. At each pixel $x$, we have a own magnitude value, it will be a scalar value. Hence, for whole image, it will be 2D array of scalar values. You are right. So, Which is correct for $g$ function? $g(|I|)=\max(|I|)-|I|$ or $g(|I(x)|)=\max(|I(x)|)-|I(x)|, x \in \Omega$ $\endgroup$
    – John
    Commented Nov 4, 2015 at 15:40
  • 2
    $\begingroup$ @user8264 I don't really know what the x is meant to represent here. To me the first version is correct, as well as being simpler to read. That said, it would be simpler still to set J = |*I*|, and then write g (J) = max(J) - J. $\endgroup$
    – Simon B
    Commented Nov 4, 2015 at 16:04
  • $\begingroup$ $x$ denotes a pixel in image domain. I write the second version because i want to said that maximum of 2D scalar value, not just maximum of a single value. The $g$ function tried to invert the value in the 2D scalar, so that maximum value becomes zeros. Hence, max (.) must take over whole the 2D scalar. Therefore, if i write max(J), the reader may be confused that max take over one value $\endgroup$
    – John
    Commented Nov 4, 2015 at 16:09

Your question is strongly related to the discussion in How to represent a given equation more clear, profressional and short form?, and a matter of speaking formally or loosely. First, an image convolved by a filter remains an image, which can be interpreted as a matrix or a vector.

Yet the resulting image might not be of the same size, depending on filter size and border management. So scalar additions and subtractions could be ill-defined. Luckily here, the two gradient Sobel filters have the same size, hence $K_x$ and $K_y$ as well. Powers and square-roots should be understood as scalar too in that case, hence pixel by pixel. So assuming only scalar operations, $I_\delta$ is an image.

The $\max$ is hardly a matrix, unless "very lossely" speaking. The subtraction, that might work in Matlab, is only understandable if you allow a scalar to be a constant matrix with the same size as the others matrices.

Your notation $x$ does not seem much clearer to me. So apart from notations suggested in How to represent a given equation more clear, profressional and short form?, you can defined an "inverted gradient image" $I_g$ as:

$$\forall (i,j)\in [1,\ldots,M]\times [1,\ldots,N],\; I_g(i,j) = \max_{ (i,j)\in [1,\ldots,M]\times [1,\ldots,N]} I_\delta (i,j) - I_\delta(i,j)\,. $$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.