1

Is there any significant meaning of the gradient of a matrix? What does it imply? For example in Matlab:

F = [ 2 4 5; 5 6 9; 0 1 3];
[Fx, Fy] = gradient(F);

Fx =

2.0000    1.5000    1.0000
1.0000    2.0000    3.0000
1.0000    1.5000    2.0000

Fy =

3.0000    2.0000    4.0000
-1.0000   -1.5000   -1.0000
-5.0000   -5.0000   -6.0000

How about the quiver(Fx, Fy) as shown below attached image? quiver(Fx, Fy)

  • No clue. It only makes sense to apply the gradient operation to a function, and a matrix is not a function, just a bucket of numbers. If you interpret the matrix as a linear function on vectors, its gradient is just the matrix again. So I don't know what Matlab is doing here. – user7530 Oct 11 '13 at 01:06
  • 1
    how about if the matrix is the intensity of a grayscale image? let say an image of size 256x256. – askingtoomuch Oct 11 '13 at 01:21
  • @boogiedoll : a matrix of numbers not have a gradient, as user7530 said, in a mathematical sense. You need to find what the command "gradient" does in Matlab. Did you try "help gradient" at the command prompt? If that doesn't work, try "edit gradient". – Stefan Smith Oct 11 '13 at 01:58
  • @sfefan yes. I have checked the definition provided by matlab. In my case, it says: "[FX,FY] = gradient(F), where F is a matrix, returns the x and y components of the two-dimensional numerical gradient. FX corresponds to ∂F/∂x, the differences in x (horizontal) direction. FY corresponds to ∂F/∂y, the differences in the y (vertical) direction. The spacing between points in each direction is assumed to be one." I just wonder whether there's any significant meaning behind it. May be you guys are right. – askingtoomuch Oct 11 '13 at 02:19
  • @user7530 "a matrix is not a function" -- in matlab, everything is a matrix, including functions. – user98130 Oct 12 '13 at 03:36

1 Answers1

3

The definition provided by Matlab is clear enough: the command computes numerical derivatives (i.e., finite differences) in the horizontal and vertical directions. This is what you use if $F$ represents the values of some function sampled along a rectangular grid, and you want an approximation to the derivatives of $F$. The plot shows the directions in which the function grows the fastest (steepest ascent).

In the specific example of $F$ being greyscale intensity, the derivatives will measure how much the intensity changes between adjacent points. Large values of derivative may indicate an edge in the image; thus, truncating $|Fx|+|Fy|$ at some large value may serve as a primitive edge-detection algorithm. Of course, the real edge-detection algorithms are more sophisticated and look at more than just the difference of adjacent values.

By the way, I want to emphasize the difference between matrix-in-mathematics and matrix-in-matlab. Matrix-in-mathematics is something that represents a linear transformation. Matrix-in-matlab is any rectangular array filled with numbers, e.g., the result of evaluation of a function along a grid. The latter does not naturally represent any linear transformation; we are unlikely to ask what the rank, range and kernel are for this thing. Gradient makes sense for some matrices-in-matlab, but not for those that are matrices-in-mathematics.

user98130
  • 2,707