# Structure tensor

In mathematics, the structure tensor, also referred to as the second-moment matrix, is a matrix derived from the gradient of a function. It summarizes the predominant directions of the gradient in a specified neighborhood of a point, and the degree to which those directions are coherent. The structure tensor is often used in image processing and computer vision.[1][2][3]

## The 2D structure tensor

### Continuous version

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

${\displaystyle S_{w}(p)={\begin{bmatrix}\int w(r)(I_{x}(p-r))^{2}\,dr&\int w(r)I_{x}(p-r)I_{y}(p-r)\,dr\\[10pt]\int w(r)I_{x}(p-r)I_{y}(p-r)\,dr&\int w(r)(I_{y}(p-r))^{2}\,dr\end{bmatrix}}}$

where ${\displaystyle I_{x}}$ and ${\displaystyle I_{y}}$ are the partial derivatives of ${\displaystyle I}$ with respect to x and y; the integrals range over the plane ${\displaystyle \mathbb {R} ^{2}}$; and w is some fixed "window function", a distribution on two variables. Note that the matrix ${\displaystyle S_{w}}$ is itself a function of p = (x, y).

The formula above can be written also as ${\displaystyle S_{w}(p)=\int w(r)S_{0}(p-r)\,dr}$, where ${\displaystyle S_{0}}$ is the matrix-valued function defined by

${\displaystyle S_{0}(p)={\begin{bmatrix}(I_{x}(p))^{2}&I_{x}(p)I_{y}(p)\\[10pt]I_{x}(p)I_{y}(p)&(I_{y}(p))^{2}\end{bmatrix}}}$

If the gradient ${\displaystyle \nabla I=(I_{x},I_{y})}$ of ${\displaystyle I}$ is viewed as a 1×2 (single-row) matrix, the matrix ${\displaystyle S_{0}}$ can be written as the matrix product ${\displaystyle (\nabla I)^{\text{T}}(\nabla I)}$, where ${\displaystyle (\nabla I)^{\text{T}}}$ denotes the 2×1 (single-column) transpose of the gradient. (Note however that the structure tensor ${\displaystyle S_{w}(p)}$ cannot be factored in this way.)

### Discrete version

In image processing and other similar applications, the function ${\displaystyle I}$ is usually given as a discrete array of samples ${\displaystyle 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

${\displaystyle S_{w}[p]={\begin{bmatrix}\sum _{r}w[r](I_{x}[p-r])^{2}&\sum _{r}w[r]I_{x}[p-r]I_{y}[p-r]\\[10pt]\sum _{r}w[r]I_{x}[p-r]I_{y}[p-r]&\sum _{r}w[r](I_{y}[p-r])^{2}\end{bmatrix}}}$

Here the summation index r ranges over a finite set of index pairs (the "window", typically ${\displaystyle \{-m..+m\}\times \{-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 ${\displaystyle I_{x}[p],I_{y}[p]}$ are the partial derivatives sampled at pixel p; which, for instance, may be estimated from by ${\displaystyle I}$ by finite difference formulas.

The formula of the structure tensor can be written also as ${\displaystyle S_{w}[p]=\sum _{r}w[r]S_{0}[p-r]}$, where ${\displaystyle S_{0}}$ is the matrix-valued array such that

${\displaystyle S_{0}[p]={\begin{bmatrix}(I_{x}[p])^{2}&I_{x}[p]I_{y}[p]\\[10pt]I_{x}[p]I_{y}[p]&(I_{y}[p])^{2}\end{bmatrix}}}$

### Interpretation

The importance of the 2D structure tensor ${\displaystyle S_{w}}$ stems from the fact eigenvalues ${\displaystyle \lambda _{1},\lambda _{2}}$ (which can be ordered so that ${\displaystyle \lambda _{1}\geq \lambda _{2}\geq 0}$) and the corresponding eigenvectors ${\displaystyle e_{1},e_{2}}$ summarize the distribution of the gradient ${\displaystyle \nabla I=(I_{x},I_{y})}$ of ${\displaystyle I}$ within the window defined by ${\displaystyle w}$ centered at ${\displaystyle p}$.[1][2][3]

Namely, if ${\displaystyle \lambda _{1}>\lambda _{2}}$, then ${\displaystyle e_{1}}$ (or ${\displaystyle -e_{1}}$) is the direction that is maximally aligned with the gradient within the window. In particular, if ${\displaystyle \lambda _{1}>0,\lambda _{2}=0}$ then the gradient is always a multiple of ${\displaystyle e_{1}}$ (positive, negative or zero); this is the case if and only if ${\displaystyle I}$ within the window varies along the direction ${\displaystyle e_{1}}$ but is constant along ${\displaystyle e_{2}}$.

If ${\displaystyle \lambda _{1}=\lambda _{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. In particular, ${\displaystyle \lambda _{1}=\lambda _{2}=0}$ if and only if the function ${\displaystyle I}$ is constant (${\displaystyle \nabla I=(0,0)}$) within ${\displaystyle W}$.

More generally, the value of ${\displaystyle \lambda _{k}}$, for k=1 or k=2, is the ${\displaystyle w}$-weighted average, in the neighborhood of p, of the square of the directional derivative of ${\displaystyle I}$ along ${\displaystyle e_{k}}$. The relative discrepancy between the two eigenvalues of ${\displaystyle S_{w}}$ 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).[4][5] This attribute can be quantified by the coherence, defined as

${\displaystyle c_{w}=\left({\frac {\lambda _{1}-\lambda _{2}}{\lambda _{1}+\lambda _{2}}}\right)^{2}}$

if ${\displaystyle \lambda _{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 (${\displaystyle \lambda _{1}=\lambda _{2}=0}$). Some authors define it as 0 in that case.

Note that the average of the gradient ${\displaystyle \nabla 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.[6]

By expanding the effective radius of the window function ${\displaystyle 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.[5][7] 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.

## The 3D structure tensor

### Definition

The structure tensor can be defined also for a function ${\displaystyle I}$ of three variables p=(x,y,z) in an entirely analogous way. Namely, in the continuous version we have ${\displaystyle S_{w}(p)=\int w(r)S_{0}(p-r)\,dr}$, where

${\displaystyle S_{0}(p)={\begin{bmatrix}(I_{x}(p))^{2}&I_{x}(p)I_{y}(p)&I_{x}(p)I_{z}(p)\\[10pt]I_{x}(p)I_{y}(p)&(I_{y}(p))^{2}&I_{y}(p)I_{z}(p)\\[10pt]I_{x}(p)I_{z}(p)&I_{y}(p)I_{z}(p)&(I_{z}(p))^{2}\end{bmatrix}}}$

where ${\displaystyle I_{x},I_{y},I_{z}}$ are the three partial derivatives of ${\displaystyle I}$, and the integral ranges over ${\displaystyle \mathbb {R} ^{3}}$.

In the discrete version,${\displaystyle S_{w}[p]=\sum _{r}w[r]S_{0}[p-r]}$, where

${\displaystyle S_{0}[p]={\begin{bmatrix}(I_{x}[p])^{2}&I_{x}[p]I_{y}[p]&I_{x}[p]I_{z}[p]\\[10pt]I_{x}[p]I_{y}[p]&(I_{y}[p])^{2}&I_{y}[p]I_{z}[p]\\[10pt]I_{x}[p]I_{z}[p]&I_{y}[p]I_{z}[p]&(I_{z}[p])^{2}\end{bmatrix}}}$

and the sum ranges over a finite set of 3D indices, usually ${\displaystyle \{-m..+m\}\times \{-m..+m\}\times \{-m..+m\}}$ for some m.

### Interpretation

As in the two-dimensional case, the eigenvalues ${\displaystyle \lambda _{1},\lambda _{2},\lambda _{3}}$ of ${\displaystyle S_{w}[p]}$, and the corresponding eigenvectors ${\displaystyle e_{1},e_{2},e_{3}}$, summarize the distribution of gradient directions within the neighborhood of p defined by the window ${\displaystyle w}$. This information can be visualized as an ellipsoid whose semi-axes are equal to the eigenvalues and directed along their corresponding eigenvectors.[8]

Ellipsoidal representation of the 3D structure tensor.

In particular, if the ellipsoid is stretched along one axis only, like a cigar (that is, if ${\displaystyle \lambda _{1}}$ is much larger than both ${\displaystyle \lambda _{2}}$ and ${\displaystyle \lambda _{3}}$), it means that the gradient in the window is predominantly aligned with the direction ${\displaystyle e_{1}}$, so that the isosurfaces of ${\displaystyle I}$ tend to be flat and perpendicular to that vector. This situation occurs, for instance, when p lies on a thin plate-like feature, or on the smooth boundary between two regions with contrasting values.

 The structure tensor ellipsoid of a surface-like neighborhood ("surfel"), where ${\displaystyle \lambda _{1}>\!>\lambda _{2}\approx \lambda _{3}}$. A 3D window straddling a smooth boundary surface between two uniform regions of a 3D image. The corresponding structure tensor ellipsoid.

If the ellipsoid is flattened in one direction only, like a pancake (that is, if ${\displaystyle \lambda _{3}}$ is much smaller than both ${\displaystyle \lambda _{1}}$ and ${\displaystyle \lambda _{2}}$), it means that the gradient directions are spread out but perpendicular to ${\displaystyle e_{3}}$; so that the isosurfaces tend to be like tubes parallel to that vector. This situation occurs, for instance, when p lies on a thin line-like feature, or on a sharp corner of the boundary between two regions with contrasting values.

 The structure tensor of a line-like neighborhood ("curvel"), where ${\displaystyle \lambda _{1}\approx \lambda _{2}>\!>\lambda _{3}}$. A 3D window straddling a line-like feature of a 3D image. The corresponding structure tensor ellipsoid.

Finally, if the ellipsoid is roughly spherical (that is, if ${\displaystyle \lambda _{1}\approx \lambda _{2}\approx \lambda _{3}}$), it means that the gradient directions in the window are more or less evenly distributed, with no marked preference; so that the function ${\displaystyle I}$ is mostly isotropic in that neighborhood. This happens, for instance, when the function has spherical symmetry in the neighborhood of p. In particular, if the ellipsoid degenerates to a point (that is, if the three eigenvalues are zero), it means that ${\displaystyle I}$ is constant (has zero gradient) within the window.

 The structure tensor in an isotropic neighborhood, where ${\displaystyle \lambda _{1}\approx \lambda _{2}\approx \lambda _{3}}$. A 3D window containing a spherical feature of a 3D image. The corresponding structure tensor ellipsoid.

## The multi-scale structure tensor

The structure tensor is an important tool in scale space analysis. The multi-scale structure tensor (or multi-scale second moment matrix) of a function ${\displaystyle I}$ is in contrast to other one-parameter scale-space features an image descriptor that is defined over two scale parameters. One scale parameter, referred to as local scale ${\displaystyle t}$, is needed for determining the amount of pre-smoothing when computing the image gradient ${\displaystyle (\nabla I)(x;t)}$. Another scale parameter, referred to as integration scale ${\displaystyle s}$, is needed for specifying the spatial extent of the window function ${\displaystyle w(\xi ;s)}$ that determines the weights for the region in space over which the components of the outer product of the gradient by itself ${\displaystyle (\nabla I)(\nabla I)^{\text{T}}}$ are accumulated.

More precisely, suppose that ${\displaystyle I}$ is a real-valued signal defined over ${\displaystyle \mathbb {R} ^{k}}$. For any local scale ${\displaystyle t>0}$, let a multi-scale representation ${\displaystyle I(x;t)}$ of this signal be given by ${\displaystyle I(x;t)=h(x;t)*I(x)}$ where ${\displaystyle h(x;t)}$ represents a pre-smoothing kernel. Furthermore, let ${\displaystyle (\nabla I)(x;t)}$ denote the gradient of the scale space representation. Then, the multi-scale structure tensor/second-moment matrix is defined by [7][9][10]

${\displaystyle \mu (x;t,s)=\int _{\xi \in \mathbb {R} ^{k}}(\nabla I)(x-\xi ;t)\,(\nabla I)^{\text{T}}(x-\xi ;t)\,w(\xi ;s)\,d\xi }$

Conceptually, one may ask if it would be sufficient to use any self-similar families of smoothing functions ${\displaystyle h(x;t)}$ and ${\displaystyle w(\xi ;s)}$. If one naively would apply, for example, a box filter, however, then non-desirable artifacts could easily occur. If one wants the multi-scale structure tensor to be well-behaved over both increasing local scales ${\displaystyle t}$ and increasing integration scales ${\displaystyle s}$, then it can be shown that both the smoothing function and the window function have to be Gaussian.[7] The conditions that specify this uniqueness are similar to the scale-space axioms that are used for deriving the uniqueness of the Gaussian kernel for a regular Gaussian scale space of image intensities.

There are different ways of handling the two-parameter scale variations in this family of image descriptors. If we keep the local scale parameter ${\displaystyle t}$ fixed and apply increasingly broadened versions of the window function by increasing the integration scale parameter ${\displaystyle s}$ only, then we obtain a true formal scale space representation of the directional data computed at the given local scale ${\displaystyle t}$.[7] If we couple the local scale and integration scale by a relative integration scale ${\displaystyle r\geq 1}$, such that ${\displaystyle s=rt}$ then for any fixed value of ${\displaystyle r}$, we obtain a reduced self-similar one-parameter variation, which is frequently used to simplify computational algorithms, for example in corner detection, interest point detection, texture analysis and image matching. By varying the relative integration scale ${\displaystyle r\geq 1}$ in such a self-similar scale variation, we obtain another alternative way of parameterizing the multi-scale nature of directional data obtained by increasing the integration scale.

A conceptually similar construction can be performed for discrete signals, with the convolution integral replaced by a convolution sum and with the continuous Gaussian kernel ${\displaystyle g(x;t)}$ replaced by the discrete Gaussian kernel ${\displaystyle T(n;t)}$:

${\displaystyle \mu (x;t,s)=\sum _{n\in \mathbb {Z} ^{k}}(\nabla I)(x-n;t)\,(\nabla I)^{\text{T}}(x-n;t)\,w(n;s)}$

When quantizing the scale parameters ${\displaystyle t}$ and ${\displaystyle s}$ in an actual implementation, a finite geometric progression ${\displaystyle \alpha ^{i}}$ is usually used, with i ranging from 0 to some maximum scale index m. Thus, the discrete scale levels will bear certain similarities to image pyramid, although spatial subsampling may not necessarily be used in order to preserve more accurate data for subsequent processing stages.

## Applications

The eigenvalues of the structure tensor play a significant role in many image processing algorithms, for problems like corner detection, interest point detection, and feature tracking.[8][11][12][13][14][15][16] The structure tensor also plays a central role in the Lucas-Kanade optical flow algorithm, and in its extensions to estimate affine shape adaptation;[9] where the magnitude of ${\displaystyle \lambda _{2}}$ is an indicator of the reliability of the computed result. The tensor has also been used for scale space analysis,[7] estimation of local surface orientation from monocular or binocular cues,[10] non-linear fingerprint enhancement,[17] diffusion-based image processing,[18][19][20][21] and several other image processing problems.

### Processing spatio-temporal video data with the structure tensor

The three-dimensional structure tensor has been used to analyze three-dimensional video data (viewed as a function of x, y, and time t).[4] If one in this context aims at image descriptors that are invariant under Galilean transformations, to make it possible to compare image measurements that have been obtained under variations of a priori unknown image velocities ${\displaystyle v=(v_{x},v_{y})^{\text{T}}}$

${\displaystyle {\begin{bmatrix}x'\\y'\\t'\end{bmatrix}}=G{\begin{bmatrix}x\\y\\t\end{bmatrix}}={\begin{bmatrix}x-v_{x}\,t\\y-v_{y}\,t\\t\end{bmatrix}}}$,

it is, however, from a computational viewpoint more preferable to parameterize the components in the structure tensor/second-moment matrix ${\displaystyle S}$ using the notion of Galilean diagonalization[22]

${\displaystyle S'=R_{\text{space}}^{-{\text{T}}}\,G^{-{\text{T}}}\,S\,G^{-1}\,R_{\text{space}}^{-1}={\begin{bmatrix}\nu _{1}&\,&\,\\\,&\nu _{2}&\,\\\,&\,&\nu _{3}\end{bmatrix}}}$

where ${\displaystyle G}$ denotes a Galilean transformation of spacetime and ${\displaystyle R_{\text{space}}}$ a two-dimensional rotation over the spatial domain, compared to the abovementioned use of eigenvalues of a 3-D structure tensor, which corresponds to an eigenvalue decomposition and a (non-physical) three-dimensional rotation of spacetime

${\displaystyle S''=R_{\text{spacetime}}^{-{\text{T}}}\,S\,R_{\text{spacetime}}^{-1}={\begin{bmatrix}\lambda _{1}&&\\&\lambda _{2}&\\&&\lambda _{3}\end{bmatrix}}}$.

To obtain true Galilean invariance, however, also the shape of the spatio-temporal window function needs to be adapted,[22][23] corresponding to the transfer of affine shape adaptation[9] from spatial to spatio-temporal image data. In combination with local spatio-temporal histogram descriptors,[24] these concepts together allow for Galilean invariant recognition of spatio-temporal events.[25]

## References

1. ^ a b J. Bigun and G. Granlund (1986), Optimal Orientation Detection of Linear Symmetry. Tech. Report LiTH-ISY-I-0828, Computer Vision Laboratory, Linkoping University, Sweden 1986; Thesis Report, Linkoping studies in science and technology No. 85, 1986.
2. ^ a b J. Bigun & G. Granlund (1987). "Optimal Orientation Detection of Linear Symmetry". First int. Conf. on Computer Vision, ICCV, (London). Piscataway: IEEE Computer Society Press, Piscataway. pp. 433–438.
3. ^ a b H. Knutsson (1989). "Representing local structure using tensors". Proceedings 6th Scandinavian Conf. on Image Analysis. Oulu: Oulu University. pp. 244–251.
4. ^ a b B. Jahne (1993). Spatio-Temporal Image Processing: Theory and Scientific Applications. 751. Berlin: Springer-Verlag.
5. ^ a b G. Medioni, M. Lee & C. Tang (March 2000). A Computational Framework for Feature Extraction and Segmentation. Elsevier Science.
6. ^ T. Brox, J. Weickert, B. Burgeth and P. Mrazek (2004). "Nonlinear Structure Tensors" (113): 1–32.
7. T. Lindeberg (1994), Scale-Space Theory in Computer Vision. Kluwer Academic Publishers, (see sections 14.4.1 and 14.2.3 on pages 359–360 and 355–356 for detailed statements about how the multi-scale second-moment matrix/structure tensor defines a true and uniquely determined multi-scale representation of directional data).
8. ^ a b M. Nicolescu & G. Medioni (2003). "Motion Segmentation with Accurate Boundaries – A Tensor Voting Approach". Proc. IEEE Computer Vision and Pattern Recognition. 1. pp. 382–389.
9. ^ a b c T. Lindeberg & J. Garding (1997). "Shape-adapted smoothing in estimation of 3-D depth cues from affine distortions of local 2-D structure". Image and Vision Computing. 15 (6): 415–434. doi:10.1016/S0262-8856(97)01144-X.
10. ^ a b J. Garding and T. Lindeberg (1996). "Direct computation of shape cues using scale-adapted spatial derivative operators, International Journal of Computer Vision, volume 17, issue 2, pages 163–191.
11. ^ W. Förstner (1986). "A Feature Based Correspondence Algorithm for Image Processing". 26: 150–166.
12. ^ C. Harris & M. Stephens (1988). "A Combined Corner and Edge Detector". Proc. of the 4th ALVEY Vision Conference. pp. 147–151.
13. ^ K. Rohr (1997). "On 3D Differential Operators for Detecting Point Landmarks". 15 (3): 219–233.
14. ^ I. Laptev & T. Lindeberg (2003). "Space–time interest points" (PDF). International Conference on Computer Vision ICCV'03. I. pp. 432–439. doi:10.1109/ICCV.2003.1238378.
15. ^ B. Triggs (2004). "Detecting Keypoints with Stable Position, Orientation, and Scale under Illumination Changes". Proc. European Conference on Computer Vision. 4. pp. 100–113.
16. ^ C. Kenney, M. Zuliani & B. Manjunath, (2005). "An Axiomatic Approach to Corner Detection". Proc. IEEE Computer Vision and Pattern Recognition. pp. 191–197.
17. ^ A. Almansa and T. Lindeberg (2000), Enhancement of fingerprint images using shape-adaptated scale-space operators. IEEE Transactions on Image Processing, volume 9, number 12, pages 2027–2042.
18. ^ J. Weickert (1998), Anisotropic diffusion in image processing, Teuber Verlag, Stuttgart.
19. ^ D. Tschumperle and Deriche (September 2002). "Diffusion PDE's on Vector-Valued Images": 16–25.
20. ^ S. Arseneau & J. Cooperstock (September 2006). "An Asymmetrical Diffusion Framework for Junction Analysis". British Machine Vision Conference. 2. pp. 689–698.
21. ^ S. Arseneau & J. Cooperstock (November 2006). "An Improved Representation of Junctions through Asymmetric Tensor Diffusion". International Symposium on Visual Computing.
22. ^ a b T. Lindeberg; A. Akbarzadeh & I. Laptev (August 2004). "Galilean-corrected spatio-temporal interest operators" (PDF). International Conference on Pattern Recognition ICPR'04. I. pp. 57–62. doi:10.1109/ICPR.2004.1334004.
23. ^ I. Laptev & T. Lindeberg (August 2004). "Velocity adaptation of space–time interest points". International Conference on Pattern Recognition ICPR'04. I. pp. 52–56. doi:10.1109/ICPR.2004.971.
24. ^ I. Laptev & T. Lindeberg (May 2004). "Local descriptors for spatio-temporal recognition". ECCV'04 Workshop on Spatial Coherence for Visual Motion Analysis (Prague, Czech Republic) Springer Lecture Notes in Computer Science. 3667. pp. 91–103. doi:10.1007/11676959.
25. ^ I. Laptev; B. Caputo; C. Schuldt & T. Lindeberg (2007). "Local velocity-adapted motion events for spatio-temporal recognition". Computer Vision and Image Understanding. 108. pp. 207–229. doi:10.1016/j.cviu.2006.11.023.