Lably
Skip to content

Structure tensor

Tensor related to gradients

  • 13 min read
  • 6 chapters

Related on Lably

Through Matrix (mathematics), Gradient and Function (mathematics)

The 2D structure tensor

Continuous version

For a function I of two variables p = (x, y), the structure tensor is the 2×2 matrix

Sw(p)=[∫w(r)(Ix(p−r))2dr∫w(r)Ix(p−r)Iy(p−r)dr∫w(r)Ix(p−r)Iy(p−r)dr∫w(r)(Iy(p−r))2dr] where Ix and Iy are the partial derivatives of I with respect to x and y; the integrals range over the plane R2; and w is some fixed "window function" (such as a Gaussian blur), a distribution on two variables. Note that the matrix Sw is itself a function of p = (x, y).

The formula above can be written also as Sw(p)=∫w(r)S0(p−r)dr, where S0 is the matrix-valued function defined by S0(p)=[(Ix(p))2Ix(p)Iy(p)Ix(p)Iy(p)(Iy(p))2]

If the gradient ∇I=(Ix,Iy)T of I is viewed as a 2×1 (single-column) matrix, where (⋅)T denotes transpose operation, turning a row vector to a column vector, the matrix S0 can be written as the matrix product (∇I)(∇I)T or tensor or outer product ∇I⊗∇I. Note however that the structure tensor Sw(p) cannot be factored in this way in general except if w is a Dirac delta function.

Discrete version

In image processing and other similar applications, the function I is usually given as a discrete array of samples I[p], where p is a pair of integer indices. The 2D structure tensor at a given pixel is usually taken to be the discrete sum

Sw[p]=[∑rw[r](Ix[p−r])2∑rw[r]Ix[p−r]Iy[p−r]∑rw[r]Ix[p−r]Iy[p−r]∑rw[r](Iy[p−r])2]

Here the summation index r ranges over a finite set of index pairs (the "window", typically {−m…+m}×{−m…+m} for some m), and w[r] is a fixed "window weight" that depends on r, such that the sum of all weights is 1. The values Ix[p],Iy[p] are the partial derivatives sampled at pixel p; which, for instance, may be estimated from by I by finite difference formulas.

The formula of the structure tensor can be written also as Sw[p]=∑rw[r]S0[p−r], where S0 is the matrix-valued array such that S0[p]=[(Ix[p])2Ix[p]Iy[p]Ix[p]Iy[p](Iy[p])2]

Interpretation

The importance of the 2D structure tensor Sw stems from the fact eigenvalues λ1,λ2 (which can be ordered so that λ1≥λ2≥0) and the corresponding eigenvectors e1,e2 summarize the distribution of the gradient ∇I=(Ix,Iy) of I within the window defined by w centered at p.

Namely, if λ1>λ2, then e1 (or −e1) is the direction that is maximally aligned with the gradient within the window.

In particular, if λ1>0,λ2=0 then the gradient is always a multiple of e1 (positive, negative or zero); this is the case if and only if I within the window varies along the direction e1 but is constant along e2. This condition of eigenvalues is also called linear symmetry condition because then the iso-curves of I consist in parallel lines, i.e there exists a one dimensional function g which can generate the two dimensional function I as I(x,y)=g(dTp) for some constant vector d=(dx,dy)T and the coordinates p=(x,y)T.

If λ1=λ2, on the other hand, the gradient in the window has no predominant direction; which happens, for instance, when the image has rotational symmetry within that window. This condition of eigenvalues is also called balanced body, or directional equilibrium condition because it holds when all gradient directions in the window are equally frequent/probable.

Furthermore, the condition λ1=λ2=0 happens if and only if the function I is constant (∇I=(0,0)) within W.

More generally, the value of λk, for k=1 or k=2, is the w-weighted average, in the neighborhood of p, of the square of the directional derivative of I along ek. The relative discrepancy between the two eigenvalues of Sw is an indicator of the degree of anisotropy of the gradient in the window, namely how strongly is it biased towards a particular direction (and its opposite). This attribute can be quantified by the coherence, defined as

cw=(λ1−λ2λ1+λ2)2

if λ2>0. This quantity is 1 when the gradient is totally aligned, and 0 when it has no preferred direction. The formula is undefined, even in the limit, when the image is constant in the window (λ1=λ2=0). Some authors define it as 0 in that case.

Note that the average of the gradient ∇I inside the window is not a good indicator of anisotropy. Aligned but oppositely oriented gradient vectors would cancel out in this average, whereas in the structure tensor they are properly added together. This is a reason for why (∇I)(∇I)T is used in the averaging of the structure tensor to optimize the direction instead of ∇I.

By expanding the effective radius of the window function w (that is, increasing its variance), one can make the structure tensor more robust in the face of noise, at the cost of diminished spatial resolution. The formal basis for this property is described in more detail below, where it is shown that a multi-scale formulation of the structure tensor, referred to as the multi-scale structure tensor, constitutes a true multi-scale representation of directional data under variations of the spatial extent of the window function.

Complex version

The interpretation and implementation of the 2D structure tensor becomes particularly accessible using complex numbers. The structure tensor consists in 3 real numbers

Sw(p)=[μ20μ11μ11μ02]

where μ20=∫(w(r)(Ix(p−r))2dr , μ02=∫(w(r)(Iy(p−r))2dr and μ11=∫w(r)Ix(p−r)Iy(p−r)dr in which integrals can be replaced by summations for discrete representation. Using Parseval's identity it is clear that the three real numbers are the second order moments of the power spectrum of I. The following second order complex moment of the power spectrum of I can then be written as

κ20=μ20−μ02+i2μ11=∫w(r)(Ix(p−r)+iIy(p−r))2dr=(λ1−λ2)exp⁡(i2ϕ)

where i=−1 and ϕ is the direction angle of the most significant eigenvector of the structure tensor ϕ=∠e1 whereas λ1 and λ2 are the most and the least significant eigenvalues. From, this it follows that κ20 contains both a certainty |κ20|=λ1−λ2 and the optimal direction in double angle representation since it is a complex number consisting of two real numbers. It follows also that if the gradient is represented as a complex number, and is remapped by squaring (i.e. the argument angles of the complex gradient is doubled), then averaging acts as an optimizer in the mapped domain, since it directly delivers both the optimal direction (in double angle representation) and the associated certainty. The complex number represents thus how much linear structure (linear symmetry) there is in image I, and the complex number is obtained directly by averaging the gradient in its (complex) double angle representation without computing the eigenvalues and the eigenvectors explicitly.

Likewise the following second order complex moment of the power spectrum of I, which happens to be always real because I is real,

κ11=μ20+μ02=∫w(r)|Ix(p−r)+iIy(p−r)|2dr=λ1+λ2

can be obtained, with λ1 and λ2 being the eigenvalues as before. Notice that this time the magnitude of the complex gradient is squared (which is always real).

However, decomposing the structure tensor in its eigenvectors yields its tensor components as

Sw(p)=λ1e1e1T+λ2e2e2T=(λ1−λ2)e1e1T+λ2(e1e1T+e2e2T)=(λ1−λ2)e1e1T+λ2E

where E is the identity matrix in 2D because the two eigenvectors are always orthogonal (and sum to unity). The first term in the last expression of the decomposition, (λ1−λ2)e1e1T, represents the linear symmetry component of the structure tensor containing all directional information (as a rank-1 matrix), whereas the second term represents the balanced body component of the tensor, which lacks any directional information (containing an identity matrix E). To know how much directional information there is in I is then the same as checking how large λ1−λ2 is compared to λ2.

Evidently, κ20 is the complex equivalent of the first term in the tensor decomposition, whereas 12(|κ20|−κ11)=λ2is the equivalent of the second term. Thus the two scalars, comprising three real numbers,

κ20=(λ1−λ2)exp⁡(i2ϕ)=w∗(h∗I)2κ11=λ1+λ2=w∗|h∗I|2 where h(x,y)=(x+iy)exp⁡(−(x2+y2)/(2σ2)) is the (complex) gradient filter, and ∗ is convolution, constitute a complex representation of the 2D Structure Tensor. As discussed here and elsewhere w defines the local image which is usually a Gaussian (with a certain variance defining the outer scale), and σ is the (inner scale) parameter determining the effective frequency range in which the orientation 2ϕ is to be estimated.

The elegance of the complex representation stems from that the two components of the structure tensor can be obtained as averages and independently. In turn, this means that κ20 and κ11 can be used in a scale space representation to describe the evidence for presence of unique orientation and the evidence for the alternative hypothesis, the presence of multiple balanced orientations, without computing the eigenvectors and eigenvalues. A functional, such as squaring the complex numbers have to this date not been shown to exist for structure tensors with dimensions higher than two. In Bigun 91, it has been put forward with due argument that this is because complex numbers are commutative algebras whereas quaternions, the possible candidate to construct such a functional by, constitute a non-commutative algebra.

The complex representation of the structure tensor is frequently used in fingerprint analysis to obtain direction maps containing certainties which in turn are used to enhance them, to find the locations of the global (cores and deltas) and local (minutia) singularities, as well as automatically evaluate the quality of the fingerprints.

Sign in to keep reading

5 more chapters are free with a Lably account.

More in Robotics