0
# Color Difference Calculations
1
2
Color difference calculations provide perceptual measures of how different two colors appear to human vision. Colormath implements multiple industry-standard Delta E algorithms, each optimized for different applications and levels of accuracy.
3
4
## Capabilities
5
6
### CIE 1976 Delta E
7
8
The original CIE Delta E formula, simple but less perceptually uniform than newer methods.
9
10
```python { .api }
11
def delta_e_cie1976(color1, color2):
12
"""
13
Calculate CIE 1976 Delta E difference.
14
15
Parameters:
16
- color1: First color object (Lab, Luv, or other color space)
17
- color2: Second color object (same type as color1)
18
19
Returns:
20
float: Delta E difference value (typically 0-100+)
21
22
Notes:
23
- Simple Euclidean distance in Lab space
24
- Values < 1: Not perceptible by human eye
25
- Values 1-2: Perceptible through close observation
26
- Values 2-10: Perceptible at a glance
27
- Values > 10: Colors appear as different colors
28
"""
29
```
30
31
### CIE 1994 Delta E
32
33
Improved formula with weighting factors for different viewing conditions.
34
35
```python { .api }
36
def delta_e_cie1994(color1, color2, K_L=1, K_C=1, K_H=1, K_1=0.045, K_2=0.015):
37
"""
38
Calculate CIE 1994 Delta E difference.
39
40
Parameters:
41
- color1: First color object (Lab color recommended)
42
- color2: Second color object (same type as color1)
43
- K_L: Lightness weighting factor (default: 1)
44
- K_C: Chroma weighting factor (default: 1)
45
- K_H: Hue weighting factor (default: 1)
46
- K_1: First parametric factor (default: 0.045)
47
- K_2: Second parametric factor (default: 0.015)
48
49
Returns:
50
float: Delta E difference value
51
52
Notes:
53
- Better perceptual uniformity than CIE 1976
54
- Separate weighting for lightness, chroma, and hue
55
- Standard conditions: K_L=K_C=K_H=1
56
- Textiles: K_L=2, K_C=K_H=1
57
"""
58
```
59
60
### CIE 2000 Delta E
61
62
Most advanced and perceptually accurate Delta E formula currently available.
63
64
```python { .api }
65
def delta_e_cie2000(color1, color2, Kl=1, Kc=1, Kh=1):
66
"""
67
Calculate CIE 2000 Delta E difference.
68
69
Parameters:
70
- color1: First color object (Lab color recommended)
71
- color2: Second color object (same type as color1)
72
- Kl: Lightness weighting factor (default: 1)
73
- Kc: Chroma weighting factor (default: 1)
74
- Kh: Hue weighting factor (default: 1)
75
76
Returns:
77
float: Delta E difference value
78
79
Notes:
80
- Most perceptually uniform Delta E formula
81
- Addresses issues with CIE 1994 in blue region
82
- Industry standard for color quality control
83
- Recommended for most applications
84
- Values < 1: Not perceptible
85
- Values 1-2: Just perceptible
86
- Values 2-5: Perceptible
87
- Values > 5: Well perceptible
88
"""
89
```
90
91
### CMC Delta E
92
93
Color Measurement Committee formula with adjustable tolerances for different industries.
94
95
```python { .api }
96
def delta_e_cmc(color1, color2, pl=2, pc=1):
97
"""
98
Calculate CMC Delta E difference.
99
100
Parameters:
101
- color1: First color object (Lab color recommended)
102
- color2: Second color object (same type as color1)
103
- pl: Lightness tolerance factor (default: 2)
104
- pc: Chroma tolerance factor (default: 1)
105
106
Returns:
107
float: Delta E difference value
108
109
Notes:
110
- Designed for textile industry applications
111
- Standard acceptability: pl=2, pc=1 (CMC 2:1)
112
- Perceptibility threshold: pl=1, pc=1 (CMC 1:1)
113
- Good performance in neutral colors
114
"""
115
```
116
117
## Usage Examples
118
119
### Basic Color Difference
120
121
```python
122
from colormath.color_objects import LabColor
123
from colormath.color_diff import delta_e_cie2000
124
125
# Create two Lab colors
126
color1 = LabColor(lab_l=50.0, lab_a=20.0, lab_b=-30.0)
127
color2 = LabColor(lab_l=52.0, lab_a=18.0, lab_b=-28.0)
128
129
# Calculate Delta E 2000 (recommended)
130
diff = delta_e_cie2000(color1, color2)
131
print(f"Delta E 2000: {diff:.2f}")
132
```
133
134
### Comparing Different Delta E Methods
135
136
```python
137
from colormath.color_objects import LabColor
138
from colormath.color_diff import (
139
delta_e_cie1976, delta_e_cie1994,
140
delta_e_cie2000, delta_e_cmc
141
)
142
143
color1 = LabColor(lab_l=50, lab_a=0, lab_b=0)
144
color2 = LabColor(lab_l=52, lab_a=2, lab_b=-1)
145
146
# Compare all methods
147
diff_1976 = delta_e_cie1976(color1, color2)
148
diff_1994 = delta_e_cie1994(color1, color2)
149
diff_2000 = delta_e_cie2000(color1, color2)
150
diff_cmc = delta_e_cmc(color1, color2)
151
152
print(f"CIE 1976: {diff_1976:.2f}")
153
print(f"CIE 1994: {diff_1994:.2f}")
154
print(f"CIE 2000: {diff_2000:.2f}")
155
print(f"CMC: {diff_cmc:.2f}")
156
```
157
158
### Working with Different Color Spaces
159
160
```python
161
from colormath.color_objects import sRGBColor, LabColor
162
from colormath.color_conversions import convert_color
163
from colormath.color_diff import delta_e_cie2000
164
165
# Create RGB colors
166
rgb1 = sRGBColor(rgb_r=0.8, rgb_g=0.2, rgb_b=0.1)
167
rgb2 = sRGBColor(rgb_r=0.85, rgb_g=0.15, rgb_b=0.12)
168
169
# Convert to Lab for Delta E calculation
170
lab1 = convert_color(rgb1, LabColor)
171
lab2 = convert_color(rgb2, LabColor)
172
173
# Calculate difference
174
diff = delta_e_cie2000(lab1, lab2)
175
print(f"RGB color difference: {diff:.2f}")
176
```
177
178
### Industry-Specific Tolerances
179
180
```python
181
from colormath.color_objects import LabColor
182
from colormath.color_diff import delta_e_cie1994, delta_e_cmc
183
184
color_standard = LabColor(lab_l=50, lab_a=10, lab_b=-5)
185
color_sample = LabColor(lab_l=51, lab_a=12, lab_b=-3)
186
187
# Graphic arts (standard conditions)
188
diff_graphics = delta_e_cie1994(color_standard, color_sample)
189
190
# Textiles (K_L=2 for textile industry)
191
diff_textiles = delta_e_cie1994(color_standard, color_sample, K_L=2)
192
193
# CMC for acceptability (2:1 ratio)
194
diff_cmc_accept = delta_e_cmc(color_standard, color_sample, pl=2, pc=1)
195
196
# CMC for perceptibility (1:1 ratio)
197
diff_cmc_percept = delta_e_cmc(color_standard, color_sample, pl=1, pc=1)
198
199
print(f"Graphics: {diff_graphics:.2f}")
200
print(f"Textiles: {diff_textiles:.2f}")
201
print(f"CMC Accept: {diff_cmc_accept:.2f}")
202
print(f"CMC Percept: {diff_cmc_percept:.2f}")
203
```
204
205
### Batch Color Difference Analysis
206
207
```python
208
from colormath.color_objects import LabColor
209
from colormath.color_diff import delta_e_cie2000
210
211
# Reference color
212
reference = LabColor(lab_l=50, lab_a=0, lab_b=0)
213
214
# Sample colors to compare
215
samples = [
216
LabColor(lab_l=52, lab_a=2, lab_b=-1),
217
LabColor(lab_l=48, lab_a=-1, lab_b=3),
218
LabColor(lab_l=50, lab_a=5, lab_b=-2),
219
LabColor(lab_l=53, lab_a=-3, lab_b=4)
220
]
221
222
# Calculate differences
223
differences = [delta_e_cie2000(reference, sample) for sample in samples]
224
225
# Analyze results
226
for i, diff in enumerate(differences):
227
status = "PASS" if diff < 2.0 else "FAIL"
228
print(f"Sample {i+1}: ΔE = {diff:.2f} [{status}]")
229
```
230
231
### Quality Control Workflow
232
233
```python
234
from colormath.color_objects import LabColor
235
from colormath.color_diff import delta_e_cie2000
236
237
def assess_color_quality(standard_color, test_color, tolerance=2.0):
238
"""
239
Assess color quality against standard.
240
241
Parameters:
242
- standard_color: Reference color
243
- test_color: Color to test
244
- tolerance: Maximum acceptable Delta E
245
246
Returns:
247
dict: Quality assessment results
248
"""
249
diff = delta_e_cie2000(standard_color, test_color)
250
251
if diff <= tolerance * 0.5:
252
grade = "Excellent"
253
elif diff <= tolerance:
254
grade = "Acceptable"
255
else:
256
grade = "Reject"
257
258
return {
259
'delta_e': diff,
260
'grade': grade,
261
'pass': diff <= tolerance,
262
'tolerance': tolerance
263
}
264
265
# Example usage
266
standard = LabColor(lab_l=50, lab_a=10, lab_b=-10)
267
test_sample = LabColor(lab_l=51, lab_a=11, lab_b=-9)
268
269
result = assess_color_quality(standard, test_sample)
270
print(f"Grade: {result['grade']}")
271
print(f"Delta E: {result['delta_e']:.2f}")
272
print(f"Pass: {result['pass']}")
273
```
274
275
## Delta E Interpretation Guidelines
276
277
### General Perception Thresholds
278
279
| Delta E Range | Perception Level | Description |
280
|---------------|------------------|-------------|
281
| 0-1 | Not perceptible | Colors appear identical |
282
| 1-2 | Just perceptible | Very close observation needed |
283
| 2-5 | Perceptible | Colors appear similar but different |
284
| 5-10 | Well perceptible | Clear color difference |
285
| 10+ | Very different | Colors appear as different colors |
286
287
### Industry-Specific Tolerances
288
289
| Industry | Application | Typical Tolerance | Method |
290
|----------|-------------|-------------------|---------|
291
| Printing | Commercial printing | ΔE < 3-5 | CIE 2000 |
292
| Textiles | Color matching | ΔE < 1-2 | CMC 2:1 |
293
| Paints | Automotive coatings | ΔE < 1 | CIE 2000 |
294
| Displays | Monitor calibration | ΔE < 2 | CIE 2000 |
295
| Photography | Color reproduction | ΔE < 2-3 | CIE 2000 |
296
297
## Method Selection Guidelines
298
299
### When to Use Each Method
300
301
- **CIE 1976**: Simple applications, historical compatibility
302
- **CIE 1994**: Better than 1976, still widely used in industry
303
- **CIE 2000**: Most accurate, recommended for new applications
304
- **CMC**: Textile industry, neutral color evaluation
305
306
### Computational Performance
307
308
| Method | Speed | Accuracy | Use Case |
309
|--------|-------|----------|----------|
310
| CIE 1976 | Fastest | Low | Quick screening |
311
| CIE 1994 | Fast | Medium | General purpose |
312
| CIE 2000 | Slower | High | Quality control |
313
| CMC | Fast | Medium | Textiles |