# Example Image Derivative

Example of how to compute different image derivatives. The gradient (1st order derivative) is probably the important image derivative and is used as a first step when extracting many types of image features. The code below shows how gradient, Hessian (2nd order), and arbitrary image derivatives can be computed.

Example Code:

Concepts:

• Image Derivative
• Hessian

# Example Code

```/**
* Example showing how to compute different image derivatives using built in functions.
*
* @author Peter Abeles
*/
public class ExampleImageDerivative {
public static void main( String[] args ) {

// We will use floating point images here, but GrayU8 with GrayS16 for derivatives also works
GrayF32 grey = new GrayF32(input.getWidth(), input.getHeight());
ConvertBufferedImage.convertFrom(input, grey);

// First order derivative, also known as the gradient
GrayF32 derivX = new GrayF32(grey.width, grey.height);
GrayF32 derivY = new GrayF32(grey.width, grey.height);

// Second order derivative, also known as the Hessian
GrayF32 derivXX = new GrayF32(grey.width, grey.height);
GrayF32 derivXY = new GrayF32(grey.width, grey.height);
GrayF32 derivYY = new GrayF32(grey.width, grey.height);

GImageDerivativeOps.hessian(DerivativeType.SOBEL, derivX, derivY, derivXX, derivXY, derivYY, BorderType.EXTENDED);

// There's also a built in function for computing arbitrary derivatives
AnyImageDerivative<GrayF32, GrayF32> derivative =
GImageDerivativeOps.createAnyDerivatives(DerivativeType.SOBEL, GrayF32.class, GrayF32.class);

// the boolean sequence indicates if its an X or Y derivative
derivative.setInput(grey);
GrayF32 derivXYX = derivative.getDerivative(true, false, true);

// Visualize the results
ListDisplayPanel gui = new ListDisplayPanel();