Laws' texture energy filters¶
| Fact | Value |
|---|---|
| Also called | Laws masks, Texture energy |
| Status | Implemented and tested |
| Family | Texture, corners, blobs and features |
| Engine | Browser |
| Type | Nonlinear, spatial, filter bank energy |
| Output | Image |
| Operator shown as | fixed-kernel (exact) |
| Support radius | window + 1 |
| Code | web/src/core/filters/edges/laws.ts, lawsFilter |
| Operator code | web/src/core/filters/edges/laws.ts, LAWS_VECTORS |
| Channels | Brightness only, RGB |
Overview¶
Laws' texture energy filters describe local texture. Five short vectors measure level, edge, spot, wave and ripple. Their outer products give 25 masks of 5x5. Each mask responds to one kind of pattern, and the average size of its response over a window is the texture energy.
How it works¶
- Remove the local brightness by subtracting the local mean.
- Correlate with a 5x5 mask made from two Laws vectors.
- Average the absolute response over a window.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(v, h\): The vertical and horizontal vectors
- \(W\): The energy window
- \(\bar{I}\): The local mean
v and h are two of the five Laws vectors: level, edge, spot, wave (-1, 2, 0, -2, 1) and ripple (1, -4, 6, -4, 1). Their outer product is a 5x5 mask. I bar is the local mean over the energy window W, removed first. The texture energy E is the mean absolute response over W. Each mask picks out a different kind of texture, such as horizontal edges or spots.
The vectors approximate a local average (L5), a first derivative (E5), a second derivative (S5) and higher-order patterns (W5, R5). Every vector except L5 adds up to 0, so masks with at least one of them ignore flat areas. Laws used a 15x15 window for the mean removal and the energy. Pairs such as E5L5 and L5E5 are the same mask turned by 90 degrees, and averaging them gives a measure that does not depend on the direction.
Kernel or operator¶
The Inspector shows the 5x5 mask and its two vectors. The worked example below builds the E5L5 mask.
Algorithm¶
- Extend the image by the full support with the border mode.
- Subtract the local mean over the energy window, if chosen.
- Correlate with the vector along the rows, then the vector down the columns.
- Average the absolute response over the energy window, and cut the extension off.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Vertical vector vertical |
E5 edge | L5 level, E5 edge, S5 spot, W5 wave, R5 ripple | The vector down the columns of the mask. |
Horizontal vector horizontal |
L5 level | L5 level, E5 edge, S5 spot, W5 wave, R5 ripple | The vector along the rows of the mask. |
Energy window window |
15 | 3 to 31, odd px | The window for the energy average and for the mean removal. Laws used 15. |
Remove local mean removeMean |
on | On or off | Subtract the local mean before the mask, so the brightness does not count. |
Output mapping outputMapping |
Stretch to full range | Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 | How signed results, such as gradients, become 8-bit pixel values. |
Border mode border |
Reflect 101 (default) | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
lawsFilter in web/src/core/filters/edges/laws.ts extends the plane once by its full support, the window plus 2, with the border mode. Then it removes the local mean, runs the separable mask and averages the absolute response, and cuts the extension off. Extending once keeps strips and whole images equal, which matters because the odd masks such as E5 change sign at a mirror border. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the border mode, the channel scope, alpha and the output mapping. By default it works on luma and gives a gray result.
Worked example¶
The E5L5 mask is the outer product of E5 down the columns and L5 along the rows:
Its rows weight a smoothed difference from top to bottom, so it responds to horizontal edges and texture. Its weights add up to 0, so flat areas give 0. The filter takes the absolute response and averages it over the energy window.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. The mask is separable and the means use running sums.
Artifacts and limitations¶
Limitations
- The energy window blurs texture boundaries.
- Masks are not rotation invariant. Laws combined pairs such as E5L5 and L5E5 for that.
Artifacts
- Soft, wide transitions between textured regions.
Tests¶
The reference runs the same steps with SciPy on the extended plane. Before it is used, the script checks that the L5L5 energy of a flat image is 0 after mean removal. The test covers three mask, window and mean-removal settings for all five border modes.
References¶
- Laws, K. I. Rapid texture identification. Image Processing for Missile Guidance, Proceedings of SPIE 0238, 376 to 381, 1980. DOI 10.1117/12.959169.