Emboss¶
| Fact | Value |
|---|---|
| Also called | Relief, Emboss filter |
| Status | Implemented and tested |
| Family | Artistic and geometric effects |
| Engine | Browser |
| Type | Linear, spatial, directional difference with offset |
| Output | Image |
| Operator shown as | fixed-kernel (exact) |
| Support radius | 1 |
| Code | web/src/core/filters/artistic/kernels.ts, embossFilter |
| Operator code | web/src/core/filters/artistic/kernels.ts, EMBOSS_ROWS |
| Channels | RGB, Brightness only |
Overview¶
Emboss makes an image look like a relief pressed into metal or stone. Each pixel is compared with one diagonal neighbor, and mid gray is added, so flat areas turn gray and edges turn light or dark depending on which way they face.
How it works¶
- Subtract the pixel below and to the left from each pixel.
- Add 128, so that flat areas become mid gray.
- Clip the result to 0 to 255.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I(x, y)\): The input at column x and row y, with y growing downward
This is Pillow's EMBOSS filter. Pillow lists its kernel with -1 at the top left and 1 in the center, but applies the first row of a kernel to the row below the pixel. So the -1 falls on the pixel below and to the left, as a single bright pixel shows. y grows downward. Flat areas turn mid gray, 128. Where the image gets brighter toward the top right, the result is lighter, and where it gets darker, the result is darker.
The difference along one diagonal is a directional derivative. It is 0 where the image does not change in that direction, so edges that run along the diagonal leave no trace. Pillow's kernel is printed with -1 at the top left. A test with one bright pixel shows that Pillow applies the first kernel row to the row below, so PixelNexus stores the kernel the way Pillow really applies it.
Kernel or operator¶
The Inspector shows the 3 x 3 kernel, as a correlation, and the offset of 128.
Algorithm¶
- Subtract the pixel below and to the left from each pixel.
- Add 128 and clip to 0 to 255.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
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. |
Output mapping outputMapping |
Clip to 0 to 255 | 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. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
embossFilter in web/src/core/filters/artistic/kernels.ts correlates the image with EMBOSS_ROWS and adds 128.
Worked example¶
| Filter | x = 3 | x = 4 | x = 5 | x = 6 | x = 7 | x = 8 |
|---|---|---|---|---|---|---|
| Input | 50 | 50 | 50 | 200 | 200 | 200 |
| Emboss | 128 | 128 | 128 | 255 | 128 | 128 |
| Outline | 255 | 255 | 0 | 255 | 255 | 255 |
| Edge enhance | 50 | 50 | 0 | 255 | 200 | 200 |
| Edge enhance, more | 50 | 50 | 0 | 255 | 200 | 200 |
The middle row of a 12 by 3 image that steps from 50 to 200 between x = 5 and x = 6. Values are clipped to 0 to 255 and rounded. The emboss result depends on the pixel below and to the left, which is on the same side of a vertical step, so only the step itself shows.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels.
Artifacts and limitations¶
Limitations
- The light comes from one fixed direction. Edges along that direction do not show.
- Noise is embossed too.
Artifacts
- Gray, flat look in areas without edges.
Tests¶
The fixture cases compare every pixel with scipy.ndimage.correlate and the same kernel, for three border modes. Before the cases are written, the result is checked against Pillow's EMBOSS away from the edge, where Pillow rounds to whole levels.
References¶
- Pillow documentation, ImageFilter module, built-in filters. https://pillow.readthedocs.io/en/stable/reference/ImageFilter.html