You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Analyzes image histogram (2nd/98th percentile) and remaps the actual
used luminance range to the display's capabilities, maximizing contrast.
Full-range images behave like strength=1.0; narrow-range images get
more contrast than fixed linear compression.
BREAKING CHANGE: tone_compression default changed from 1.0 to "auto".
Copy file name to clipboardExpand all lines: packages/python/README.md
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,19 +118,22 @@ Note: The `serpentine` parameter only affects error diffusion algorithms (Floyd-
118
118
119
119
E-paper displays can't reproduce the full luminance range of digital images. Pure white on a display is much darker than (255, 255, 255), and pure black is lighter than (0, 0, 0). Without tone compression, dithering tries to represent unreachable brightness levels, causing large accumulated errors and noisy output.
120
120
121
-
Tone compression remaps image luminance from [0, 1] to the display's actual [black, white] range before dithering, producing smoother results. Based on [`fast_compress_dynamic_range()`](https://github.com/aitjcize/esp32-photoframe) from esp32-photoframe by aitjcize. It is enabled by default (`tone_compression=1.0`) and only applies when using measured `ColorPalette` instances:
121
+
Tone compression remaps image luminance to the display's actual range before dithering. Based on [`fast_compress_dynamic_range()`](https://github.com/aitjcize/esp32-photoframe) from esp32-photoframe by aitjcize. It is enabled by default (`tone_compression="auto"`) and only applies when using measured `ColorPalette` instances:
122
+
123
+
-**`"auto"`** (default): Analyzes the image histogram and remaps its actual luminance range to the display range. Maximizes contrast by stretching only the used range.
124
+
-**`0.0-1.0`**: Fixed linear compression strength. `1.0` maps the full [0,1] range to the display range. `0.0` disables compression.
122
125
123
126
```python
124
127
from epaper_dithering import dither_image, SPECTRA_7_3_6COLOR, DitherMode
125
128
126
-
# Default: full tone compression (recommended)
129
+
# Default: auto tone compression (recommended)
127
130
result = dither_image(img, SPECTRA_7_3_6COLOR, DitherMode.FLOYD_STEINBERG)
128
131
132
+
# Fixed linear compression
133
+
result = dither_image(img, SPECTRA_7_3_6COLOR, DitherMode.FLOYD_STEINBERG, tone_compression=1.0)
134
+
129
135
# Disable tone compression
130
136
result = dither_image(img, SPECTRA_7_3_6COLOR, DitherMode.FLOYD_STEINBERG, tone_compression=0.0)
131
-
132
-
# Partial compression (blend between original and compressed)
133
-
result = dither_image(img, SPECTRA_7_3_6COLOR, DitherMode.FLOYD_STEINBERG, tone_compression=0.5)
134
137
```
135
138
136
139
Note: `tone_compression` has no effect when using theoretical `ColorScheme` palettes (e.g., `ColorScheme.BWR`), since their black/white values already span the full range.
0 commit comments