# Image Differentials

### An ImageJ plugin that computes the gradient, Laplacian, and Hessian of a grayscale image

##### Philippe Thévenaz, Biomedical Imaging Group, Swiss Federal Institute of Technology Lausanne

Figure 1. Diatom (left) and its gradient amplitude (right).

This distribution is dated Avril 7, 2014. It includes the complete set of source files, along with the precompiled classes.

## II. Related work

This Java class is based on the following paper:
M. Unser, "Splines: A Perfect Fit for Signal and Image Processing," IEEE Signal Processing Magazine, vol. 16, no. 6, pp. 22-38, November 1999.
It is written as a plugin for ImageJ. Please read the ImageJ documentation to learn how to install the plugin.

## III. Explanations

This plugin allows you to perform several differentiation operations on images, seen as continuous functions, even though they are stored as discrete pixels. The general principle is to construct the continuously defined function

ƒ(x, y) = k,l c[k,l] ⋅ φ(x-k, y-l).

Here, we shall concentrate on the specific case where the function

φ(x, y) = β3(x) ⋅ β3(y)

is a tensor-product (separable) cubic B-spline. Then, a typical example of spatial differentiation operation is

∂ƒ(x, y) ⁄ ∂y = k,l c[k,l] ⋅ β3(x-k) ⋅ ∂β3(y-l) ⁄ ∂y,

where we compute the exact vertical gradient of the continuously defined image.

## IV. Operations

Figure 2. Possible operations.

• Gradient Magnitude: the gradient is the first derivative of the image, and is performed along some preferred direction. The result returned by the Gradient Magnitude operation gives the largest gradient magnitude when every possible direction is taken into account. It is a non-negative number computed as

√( (∂ƒ(x, y) ⁄ ∂x)2 + (∂ƒ(x, y) ⁄ ∂y)2 ).

• Gradient Direction: the direction of the largest gradient is an angle returned in radians in the range [-π, π]. It is computed as

arc tan( (∂ƒ(x, y) ⁄ ∂y) ⁄ (∂ƒ(x, y) ⁄ ∂x) ),

along with considerations on the sign of ∂ƒ(x, y) ⁄ ∂y and of ∂ƒ(x, y) ⁄ ∂x.
• Laplacian: the second derivative can be computed along any orientation and is composed of three terms
1. 2ƒ(x, y) ⁄ ∂x2;
2. 2ƒ(x, y) ⁄ ∂y2;
3. 2ƒ(x, y) ⁄ ∂x∂y.
The Laplacian operation ignores the third term and returns the average value of the second derivative when taking every orientation into account. It is a signed number computed as

2ƒ(x, y) ⁄ ∂x2 + ∂2ƒ(x, y) ⁄ ∂y2.

• Largest Hessian: the computation of the second derivatives of an image yields three terms. While the Laplacian ignores one of them and considers every possible orientation at once, the Hessian takes all three terms into account and is orientation-dependent. The Largest Hessian operation determines the orientation along which the second derivative is maximal. It returns this maximum as a signed number.
• Smallest Hessian: the orientation for which the second derivative is minimal can also be determined. The Smallest Hessian operation returns the minimum of the second derivative as a signed number.
• Hessian Orientation: this operation returns the orientation for which the second derivative is maximal. It is an angle returned in radians in the range [-π ⁄ 2, π ⁄ 2] and corresponds to an orientation without direction. The orientation for the minimal second derivative can be obtained by adding (or subtracting) π ⁄ 2.

## V. Example

The following pair of images is typical of the kind of results you can obtain with the present program. The image on the left is the original image, while the image on the right shows its Laplacian.

Figure 3. Left: 256×256 Lena input image. Right: Resulting Laplacian.

## VI. Conditions of use

You'll be free to use this software for research purposes, but you must not transmit and distribute it without our consent. In addition, you undertake to include a citation or acknowledgment whenever you present or publish results that are based on it. EPFL makes no warranties of any kind on this software and shall in no event be liable for damages of any kind in connection with the use and exploitation of this technology.

## VII. Programmer's note

The class Differentials_ contains the five following methods:

 getCrossHessian ↔ (∂ƒ(x, y) ⁄ ∂x) ⋅ (∂ƒ(x, y) ⁄ ∂y) getHorizontalGradient ↔ ∂ƒ(x, y) ⁄ ∂x getHorizontalHessian ↔ ∂2ƒ(x, y) ⁄ ∂x2 getVerticalGradient ↔ ∂ƒ(x, y) ⁄ ∂y getVerticalHessian ↔ ∂2ƒ(x, y) ⁄ ∂y2

These methods have two parameters each and perform the in-place processing of an object of type ImageProcessor, given as first parameter. The only image type that is currently implemented is ImagePlus.GRAY32.

The second parameter is a variable of type double that controls the compromise between speed and accuracy. Its value should be a small positive or null number. The best precision is achieved by setting tolerance = 0.0, at the expense of some (moderate) loss in efficiency. We have observed experimentally that the value that corresponds to the C constant FLT_EPSILON exhibits an excellent trade-off. In Java, this value can be written as Float.intBitsToFloat((int)0x33FFFFFF).