Scale-space filtering¶
| Fact | Value |
|---|---|
| Also called | Gaussian scale space, Normalized derivatives, Automatic scale selection |
| Status | Implemented and tested |
| Family | Wavelet and multiscale filters |
| Engine | Browser |
| Type | Nonlinear, transform, normalized derivatives and scale selection |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | floor(4 * max(sigma, sigmaMax) + 0.5) |
| Code | web/src/core/filters/multiscale/scale-space.ts, scaleSpaceFilter |
| Operator code | web/src/core/filters/multiscale/scale-space.ts, normalizedMeasure |
| Channels | Brightness only, RGB |
Overview¶
Scale-space filtering looks at the image through Gaussian blurs of many sizes. At each size it measures edges or blobs with derivatives, normalized so that small and large blurs can be compared. At each pixel it keeps the strongest response and the size where it was found. The selected size follows the size of the structure, which is the idea behind scale-invariant detectors such as SIFT.
How it works¶
- Choose the measure: gradient magnitude, Laplacian or the determinant of the Hessian.
- Build a list of sigmas from the smallest to the largest, spaced evenly in log sigma.
- At each sigma, blur and differentiate the image with Gaussian derivative kernels.
- Multiply each measure by sigma to the power of its order times gamma.
- At each pixel, keep the value of largest size and the sigma where it was found.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): The input channel
- \(L\): The scale space, the image blurred by a Gaussian of variance t
- \(t, \sigma\): The scale t = sigma^2, in pixels squared
- \(L_x, L_{xx}, L_{xy}\): Derivatives of L along x and y. y points down.
- \(N\): The normalized measure
- \(\gamma\): The normalization power
- \(n\): The number of scales in the stack
L is the image blurred by a Gaussian g of variance t, the scale space of the image. Its derivatives come from derivative-of-Gaussian kernels cut at 4 sigma, as in scipy.ndimage.gaussian_filter. Derivatives get weaker as t grows, so plain responses at different scales cannot be compared. Lindeberg multiplies a derivative of order m by t^(m gamma / 2). With gamma 1, a structure made s times larger gives the same normalized responses at scale s^2 t as the original gives at t. So the scale where the normalized response is strongest grows with the size of the structure. Lindeberg detects features as local maxima over space and scale. This filter takes, at each pixel, the largest absolute value over the stack, so it gives a value at every pixel. Ties go to the smaller sigma. The scale output is the sigma of that scale.
The scale space of an image is the family of its Gaussian blurs L, with the variance t of the blur as the scale. Blurring makes derivatives weaker, so a fine scale usually wins a plain comparison. Lindeberg multiplies a derivative of order m by t^(m gamma / 2). With gamma 1, a structure made s times larger gives the same normalized responses at scale s^2 t as the original gives at t. So the scale with the strongest response grows with the structure. For a bright disk of radius r, the normalized Laplacian at the center is strongest at sigma = r / sqrt 2, as the worked example shows. Lindeberg detects features as local maxima over space and scale. This filter keeps the strongest scale at every pixel instead, so it gives a value everywhere.
Kernel or operator¶
The Inspector shows three stages: the list of sigmas in the stack, the formula of the normalized measure with the current gamma, and the selection rule.
Algorithm¶
- Build the list of sigmas from the smallest to the largest, spaced evenly in log sigma.
- For each sigma, correlate the image with the derivative-of-Gaussian kernels the measure needs.
- Combine the derivatives into the measure and multiply it by its normalization factor.
- At each pixel, keep the value of largest absolute value and the sigma where it was found.
- Output the kept value, or the kept sigma.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Measure measure |
Laplacian | Gradient magnitude, Laplacian, Determinant of the Hessian | The derivative measure taken at each scale. |
Smallest sigma sigma |
1 | 0.5 to 16 px | The sigma of the finest scale in the stack. The scale t is sigma squared. |
Largest sigma sigmaMax |
4 | 0.5 to 32 px | The sigma of the coarsest scale in the stack. Values below the smallest sigma count as the smallest sigma. |
Scales scales |
5 | 1 to 16 | How many scales the stack holds, spaced evenly in log sigma. 1 uses the smallest sigma only. |
Gamma gamma |
1 | 0 to 2 | The normalization power gamma. A derivative of order m is multiplied by t to the power m gamma / 2. |
Output output |
Strongest response | Strongest response, Selected scale | Whether to show the strongest normalized response, or the sigma where it is reached. |
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¶
scaleSpaceFilter in web/src/core/filters/multiscale/scale-space.ts builds the stack with scaleStack and measures each scale with normalizedMeasure. The derivative kernels are those of the steerable filter and the Laplacian of Gaussian, cut at 4 sigma, and each runs as two 1D passes. On a smaller preview copy, both sigmas shrink with the copy.
Worked example¶
| Disk radius r | 4 | 6 | 8 | 12 | 16 |
|---|---|---|---|---|---|
| r / sqrt 2 | 2.828 | 4.243 | 5.657 | 8.485 | 11.314 |
| Selected sigma | 2.828 | 4.287 | 5.657 | 8.574 | 11.314 |
The sigma that the normalized Laplacian with gamma 1 picks at the center of a bright disk on a 97 by 97 image. The stack has 41 scales from 1 to 16, so neighboring sigmas differ by a factor of about 1.07. At the center of a disk of height 1, the heat equation gives t times the Laplacian of L as -(r^2 / t) exp(-r^2 / (2 t)). Its size is largest at t = r^2 / 2, so at sigma = r / sqrt 2. The selected sigma matches it to within one step of the stack.
Complexity¶
- Time: \(O(N n r)\)
- Memory: \(O(N)\)
N is the number of pixels, n the number of scales and r the radius of the largest kernel, 4 times the largest sigma. Each kernel is separable.
Artifacts and limitations¶
Limitations
- The stack covers only the range from the smallest to the largest sigma. Structures outside it pick an end of the range.
- The selected scale is one of the stack values, so it is only as fine as the stack.
- Slower than one Gaussian derivative, since each scale needs its own filtering.
Artifacts
- Bands of constant value in the selected scale map, since it holds only the stack values.
- Near the image border, large kernels see mostly the border extension, so the selected scale there can differ.
Tests¶
The reference computes the derivatives with scipy.ndimage.gaussian_filter and its order argument. It covers all three measures, both outputs and all five border modes. More tests check the spacing of the stack. They also check that a Gaussian blob of sigma 4 picks sigma 4, and that disks pick r / sqrt 2 to within one step.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/multiscale/multiscale.test.ts
References¶
- Lindeberg, T. Feature detection with automatic scale selection. International Journal of Computer Vision 30(2), 79 to 116, 1998. DOI 10.1023/A:1008045108935.