High-boost filter¶
| Fact | Value |
|---|---|
| Also called | High-boost filtering |
| Status | Implemented and tested |
| Family | Linear spatial filters (also Enhancement, illumination and color) |
| Engine | Browser |
| Type | Linear, spatial, convolution |
| Output | Image |
| Operator shown as | dynamic-kernel (exact) |
| Support radius | floor(3 * sigma + 0.5) |
| Code | web/src/core/filters/linear/high-pass.ts, highBoostFilter |
| Operator code | web/src/core/filters/linear/high-pass.ts, boostKernel |
| Channels | RGB, Brightness only, Color only |
Overview¶
The high-boost filter takes A times the image and subtracts a Gaussian blur of it. It is a sharpening filter that also sets how much of the original brightness stays. With A = 1 it leaves only the detail, like the high-pass filter. With A = 2 it is the same as the unsharp mask with amount 1.
How it works¶
- Make a blurred copy of the image.
- Multiply the image by the boost A.
- Subtract the blurred copy.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): Input channel value
- \(I_{\text{out}}\): Output channel value
- \(A\): Boost factor, at least 1
- \(G_{\sigma}\): Normalized Gaussian kernel with radius floor(3 sigma + 0.5)
- \(\star\): Correlation
- \(\sigma\): Standard deviation of the Gaussian in pixels
The second form shows what happens: the image is kept with weight A - 1, and the detail that the blur removes is added on top. With A = 1 only the detail is left. With A = 2 the result is the unsharp mask with amount 1. A flat area of value v becomes (A - 1) v, so A above 2 also brightens the image.
The kernel is \(A\,\delta - G_\sigma\), and its weights add up to \(A - 1\). That number is the gain for flat areas. So A below 2 darkens the image, A = 2 keeps its brightness, and A above 2 brightens it. The detail on top is always the high-pass \(I - G_\sigma \star I\), at full strength.
The unsharp mask with amount \(a\) is \(I + a (I - G \star I) = (1 + a) I - a\, G \star I\). Divided by \(a\), this is the high-boost with \(A = (1 + a)/a\). So both filters have the same shape of response, and only the gain differs.
Kernel or operator¶
The kernel for \(\sigma = 0.5\) and \(A = 2\), from the filter code. The weights add up to 1.
Algorithm¶
- Blur the image with a Gaussian of the given sigma.
- Multiply the image by A and subtract the blur.
- Clip to 0 to 255 and round to 8 bits. Keep alpha unchanged.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Boost boost |
2 | 1 to 5 | The factor A that multiplies the image before the blur is subtracted. |
Sigma sigma |
2 | 0.3 to 50 px | Standard deviation of the Gaussian low-pass that is subtracted. |
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 |
RGB | RGB, Brightness only, Color only | Which part of the color image the filter changes. |
Implementation¶
boostPlane in web/src/core/filters/linear/high-pass.ts computes \(A I - G \star I\) with the Gaussian filter code. The high-pass filter calls the same function with \(A = 1\). Results past 0 or 255 are clipped.
Worked example¶
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| Value I | 40 | 40 | 40 | 70 | 150 | 200 | 215 | 215 | 215 |
| 2 I - G * I | 39.7 | 37.9 | 26.1 | 52 | 159.9 | 215.3 | 222.8 | 216.1 | 215.1 |
| Pixel | 40 | 38 | 26 | 52 | 160 | 215 | 223 | 216 | 215 |
A = 2 and sigma 1 on the same edge. Far from the edge the value stays the same, because the weights add up to A - 1 = 1. Next to the edge the values dip and rise, as with the unsharp mask.
Complexity¶
- Time: \(O(N\,(2r+1))\)
- Memory: \(O(N)\)
N is the number of pixels per channel and r the Gaussian radius. The blur is separable.
Artifacts and limitations¶
Limitations
- A between 1 and 2 darkens the image, because flat areas become (A - 1) times their value.
- It sharpens noise as strongly as edges.
Artifacts
- Halos along edges.
- Clipped highlights for large A.
Tests¶
The test compares the filter with A times the image minus scipy.ndimage.gaussian_filter, for two sigmas, three boosts and three border modes. A unit test checks that the kernel weights add up to A - 1.
web/src/core/filters/filters.test.tsweb/src/core/filters/linear/linear5a.test.tsweb/src/core/filters/run.test.ts
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 3.
- SciPy documentation, scipy.ndimage.gaussian_filter. https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html