In short, gradient is a measure for changes of the color intensity of an image. Of course, it does not have to be limited to 2-D images and it can be applied to any n-D functions. For the general definition, see wikipedia > Gradient.

For a 2-D function, the gradient can be computed using the given formula on the right. The formula simply asks for the rate of changes in the x direction (i) and the rate of changes in the y direction (j). In my project, I followed the algorithm given in MathWorks > Gradient. The general idea is to calculate the gradient horizontally and vertically:

1. internal pixels:
• `G[i][j] = (m[i+1][j] + m[i-1][j]) * 0.5`
2. pixels along the edges
• `G[i][j] = m[i+1][j] + m[i][j]` <<< on the left edge
• `G[i][j] = m[i-1][j] + m[i][j]` <<< on the right edge
1. internal pixels:
• `G[i][j] = (m[i][j+1] + m[i][j-1]) * 0.5`
2. pixels along the edges:
• `G[i][j] = m[i][j+1] + m[i][j]` <<< on the bottom edge
• `G[i][j] = m[i][j-1] + m[i][j]` <<< on the top edge

The output of my `Gradient` filter is:

• `gradientCalculator.calculateGradientCart(image);`
• `double[][] gx`: Horizontal gradient
• `double[][] gy`: Vertical gradient
• `gradientCalculator.calculateGradientPolar(image);`
• `double[][] gx`: angles of gradient vectors
• `double[][] gy`: Magnitude of gradient vectors

Original 4096-by-4096 SDO image     