@@ -15,13 +15,17 @@ julia> cs = ColorSchemes.PuOr_7.colors; # using ColorSchemes.jl for color palett
15
15
16
16
julia> dither(img, alg, cs);
17
17
```
18
+
19
+ !!! note "Color Image"
20
+ For color image, two color spaces are used when applying the algorithm: 1) the luminance
21
+ channel in the Lab space is used to find the closest color in `cs`, and 2) the `CT`
22
+ diffusion color space is used to propagate the error. `CT` is typically a linear
23
+ colorspace, and the default value is `XYZ`. Another common choice is `RGB`, but strictly
24
+ speaking, RGB is not a linear space.
18
25
"""
19
26
20
- _error_diffusion_kwargs = """
27
+ const _error_diffusion_kwargs = """
21
28
# Keyword arguments
22
- - `color_space`: Color space in which the error is diffused.
23
- Only used when dithering with a color palette. Defaults to `XYZ`.
24
- To replicate the output of other dithering libraries, set this to `RGB`.
25
29
- `clamp_error::Bool`: Clamp accumulated error on each pixel within limits of colorant
26
30
type `color_space` before looking up the closest color. Defaults to `true`.
27
31
"""
@@ -81,11 +85,11 @@ function diffuse_error!(img, err, I, filter)
81
85
end
82
86
83
87
function colordither (
84
- alg:: ErrorDiffusion{F, C} ,
88
+ alg:: ErrorDiffusion{C} ,
85
89
img:: GenericImage ,
86
90
cs:: AbstractVector{<:Pixel} ,
87
91
metric:: DifferenceMetric ,
88
- ) where {F, C}
92
+ ) where {C}
89
93
# this function does not yet support OffsetArray
90
94
require_one_based_indexing (img)
91
95
index = Matrix {UInt8} (undef, size (img)... ) # allocate matrix of color indices
@@ -116,7 +120,7 @@ function colordither(
116
120
end
117
121
118
122
"""
119
- SimpleErrorDiffusion()
123
+ SimpleErrorDiffusion(color_space=XYZ )
120
124
121
125
Error diffusion algorithm using the filter
122
126
```
@@ -135,7 +139,7 @@ SimpleErrorDiffusion(; kwargs...) = ErrorDiffusion(SIMPLE_ERROR_DIFFUSION, 1; kw
135
139
const SIMPLE_ERROR_DIFFUSION = [0 1 ; 1 0 ]// 2
136
140
137
141
"""
138
- FloydSteinberg()
142
+ FloydSteinberg(color_space=XYZ; kwargs... )
139
143
140
144
Error diffusion algorithm using the filter
141
145
```
@@ -154,7 +158,7 @@ FloydSteinberg(; kwargs...) = ErrorDiffusion(FLOYD_STEINBERG, 2; kwargs...)
154
158
const FLOYD_STEINBERG = [0 0 7 ; 3 5 1 ]// 16
155
159
156
160
"""
157
- JarvisJudice()
161
+ JarvisJudice(color_space=XYZ; kwargs... )
158
162
159
163
Error diffusion algorithm using the filter
160
164
```
@@ -175,7 +179,7 @@ JarvisJudice(; kwargs...) = ErrorDiffusion(JARVIS_JUDICE, 3; kwargs...)
175
179
const JARVIS_JUDICE = [0 0 0 7 5 ; 3 5 7 5 3 ; 1 3 5 3 1 ]// 48
176
180
177
181
"""
178
- Stucki()
182
+ Stucki(color_space=XYZ; kwargs... )
179
183
180
184
Error diffusion algorithm using the filter
181
185
```
@@ -195,7 +199,7 @@ Stucki(; kwargs...) = ErrorDiffusion(STUCKI, 3; kwargs...)
195
199
const STUCKI = [0 0 0 8 4 ; 2 4 8 4 2 ; 1 2 4 2 1 ]// 42
196
200
197
201
"""
198
- Burkes()
202
+ Burkes(color_space=XYZ; kwargs... )
199
203
200
204
Error diffusion algorithm using the filter
201
205
```
@@ -214,7 +218,7 @@ Burkes(; kwargs...) = ErrorDiffusion(BURKES, 3; kwargs...)
214
218
const BURKES = [0 0 0 8 4 ; 2 4 8 4 2 ]// 32
215
219
216
220
"""
217
- Sierra()
221
+ Sierra(color_space=XYZ; kwargs... )
218
222
219
223
Error diffusion algorithm using the filter
220
224
```
@@ -231,7 +235,7 @@ Sierra(; kwargs...) = ErrorDiffusion(SIERRA, 3; kwargs...)
231
235
const SIERRA = [0 0 0 5 3 ; 2 4 5 4 2 ; 0 2 3 2 0 ]// 32
232
236
233
237
"""
234
- TwoRowSierra()
238
+ TwoRowSierra(color_space=XYZ; kwargs... )
235
239
236
240
Error diffusion algorithm using the filter
237
241
```
@@ -246,7 +250,7 @@ TwoRowSierra(; kwargs...) = ErrorDiffusion(TWO_ROW_SIERRA, 3; kwargs...)
246
250
const TWO_ROW_SIERRA = [0 0 0 4 3 ; 1 2 3 2 1 ]// 16
247
251
248
252
"""
249
- SierraLite()
253
+ SierraLite(color_space=XYZ; kwargs... )
250
254
251
255
Error diffusion algorithm using the filter
252
256
```
@@ -261,7 +265,7 @@ SierraLite(; kwargs...) = ErrorDiffusion(SIERRA_LITE, 2; kwargs...)
261
265
const SIERRA_LITE = [0 0 2 ; 1 1 0 ]// 4
262
266
263
267
"""
264
- Atkinson()
268
+ Atkinson(color_space=XYZ; kwargs... )
265
269
266
270
Error diffusion algorithm using the filter
267
271
```
@@ -276,7 +280,7 @@ Atkinson(; kwargs...) = ErrorDiffusion(ATKINSON, 2; kwargs...)
276
280
const ATKINSON = [0 0 1 1 ; 1 1 1 0 ; 0 1 0 0 ]// 8
277
281
278
282
"""
279
- Fan93()
283
+ Fan93(color_space=XYZ; kwargs... )
280
284
281
285
Error diffusion algorithm using the filter
282
286
```
@@ -296,7 +300,7 @@ Fan93(; kwargs...) = ErrorDiffusion(FAN_93, 3; kwargs...)
296
300
const FAN_93 = [0 0 0 7 ; 1 3 5 0 ]// 16
297
301
298
302
"""
299
- ShiauFan()
303
+ ShiauFan(color_space=XYZ; kwargs... )
300
304
301
305
Error diffusion algorithm using the filter
302
306
```
@@ -314,7 +318,7 @@ ShiauFan(; kwargs...) = ErrorDiffusion(SHIAU_FAN, 3; kwargs...)
314
318
const SHIAU_FAN = [0 0 0 4 ; 1 1 2 0 ]// 8
315
319
316
320
"""
317
- ShiauFan2()
321
+ ShiauFan2(color_space=XYZ; kwargs... )
318
322
319
323
Error diffusion algorithm using the filter
320
324
```
@@ -335,7 +339,7 @@ ShiauFan2(; kwargs...) = ErrorDiffusion(SHIAU_FAN_2, 4; kwargs...)
335
339
const SHIAU_FAN_2 = [0 0 0 0 8 ; 1 1 2 4 0 ]// 16
336
340
337
341
"""
338
- FalseFloydSteinberg()
342
+ FalseFloydSteinberg(color_space=XYZ; kwargs... )
339
343
340
344
Error diffusion algorithm using the filter
341
345
```
0 commit comments