0
# Constants and Standards
1
2
Colormath provides comprehensive collections of color science constants, illuminants, observers, density standards, and spectral data that serve as the foundation for accurate color calculations throughout the library.
3
4
## Capabilities
5
6
### Color Constants
7
8
Fundamental mathematical constants used in CIE color calculations.
9
10
```python { .api }
11
# CIE constants
12
CIE_E: float = 216.0/24389.0 # CIE epsilon constant
13
CIE_K: float = 24389.0/27.0 # CIE kappa constant
14
15
# Usage in Lab/XYZ conversions and other CIE calculations
16
```
17
18
### Illuminant Data
19
20
Comprehensive illuminant XYZ values for different observer angles and standard illuminants.
21
22
```python { .api }
23
ILLUMINANTS: dict = {
24
'2': { # 2-degree observer
25
'd65': (0.95047, 1.00000, 1.08883),
26
'd50': (0.96422, 1.00000, 0.82521),
27
'a': (1.09850, 1.00000, 0.35585),
28
'c': (0.98074, 1.00000, 1.18232),
29
'e': (1.00000, 1.00000, 1.00000),
30
# ... additional illuminants
31
},
32
'10': { # 10-degree observer
33
'd65': (0.94811, 1.00000, 1.07304),
34
'd50': (0.96720, 1.00000, 0.81427),
35
'a': (1.11144, 1.00000, 0.35200),
36
'c': (0.97285, 1.00000, 1.16145),
37
'e': (1.00000, 1.00000, 1.00000),
38
# ... additional illuminants
39
}
40
}
41
42
OBSERVERS: list = ['2', '10'] # Available observer angles
43
```
44
45
### Chromatic Adaptation Matrices
46
47
Transformation matrices for chromatic adaptation between different illuminants.
48
49
```python { .api }
50
ADAPTATION_MATRICES: dict = {
51
'bradford': {
52
'M': [[0.8951, 0.2664, -0.1614],
53
[-0.7502, 1.7135, 0.0367],
54
[0.0389, -0.0685, 1.0296]],
55
'M_inv': [[0.9869929, -0.1470543, 0.1599627],
56
[0.4323053, 0.5183603, 0.0492912],
57
[-0.0085287, 0.0400428, 0.9684867]]
58
},
59
'von_kries': {
60
'M': [[0.4002400, 0.7076000, -0.0808100],
61
[-0.2280000, 1.1500000, 0.0612000],
62
[0.0000000, 0.0000000, 0.9184000]],
63
'M_inv': [[1.8599364, -1.1293816, 0.2198974],
64
[0.3611914, 0.6388125, -0.0000064],
65
[0.0000000, 0.0000000, 1.0888251]]
66
}
67
# ... additional adaptation methods
68
}
69
```
70
71
## Density Standards
72
73
### ANSI Status T Standards
74
75
Transmission density standards for color reproduction.
76
77
```python { .api }
78
# ANSI Status T Red
79
ANSI_STATUS_T_RED: dict = {
80
# Spectral response data for Status T Red filter
81
# Wavelength data from 340-830nm
82
}
83
84
# ANSI Status T Green
85
ANSI_STATUS_T_GREEN: dict = {
86
# Spectral response data for Status T Green filter
87
}
88
89
# ANSI Status T Blue
90
ANSI_STATUS_T_BLUE: dict = {
91
# Spectral response data for Status T Blue filter
92
}
93
```
94
95
### ANSI Status A Standards
96
97
Reflection density standards for printing applications.
98
99
```python { .api }
100
# ANSI Status A Red
101
ANSI_STATUS_A_RED: dict = {
102
# Spectral response data for Status A Red filter
103
}
104
105
# ANSI Status A Green
106
ANSI_STATUS_A_GREEN: dict = {
107
# Spectral response data for Status A Green filter
108
}
109
110
# ANSI Status A Blue
111
ANSI_STATUS_A_BLUE: dict = {
112
# Spectral response data for Status A Blue filter
113
}
114
```
115
116
### ANSI Status E Standards
117
118
Photographic density standards.
119
120
```python { .api }
121
# ANSI Status E Red
122
ANSI_STATUS_E_RED: dict = {
123
# Spectral response data for Status E Red filter
124
}
125
126
# ANSI Status E Green
127
ANSI_STATUS_E_GREEN: dict = {
128
# Spectral response data for Status E Green filter
129
}
130
131
# ANSI Status E Blue
132
ANSI_STATUS_E_BLUE: dict = {
133
# Spectral response data for Status E Blue filter
134
}
135
```
136
137
### ANSI Status M Standards
138
139
Motion picture density standards.
140
141
```python { .api }
142
# ANSI Status M Red
143
ANSI_STATUS_M_RED: dict = {
144
# Spectral response data for Status M Red filter
145
}
146
147
# ANSI Status M Green
148
ANSI_STATUS_M_GREEN: dict = {
149
# Spectral response data for Status M Green filter
150
}
151
152
# ANSI Status M Blue
153
ANSI_STATUS_M_BLUE: dict = {
154
# Spectral response data for Status M Blue filter
155
}
156
```
157
158
### ISO Visual Standards
159
160
Visual density standards for human visual assessment.
161
162
```python { .api }
163
# ISO Visual density standard
164
ISO_VISUAL: dict = {
165
# Spectral response data matching human visual response
166
}
167
168
# Visual density threshold for automatic standard selection
169
VISUAL_DENSITY_THRESH: float = 0.08
170
```
171
172
## Spectral Reference Data
173
174
### Reference Illuminants
175
176
Complete spectral power distributions for standard illuminants.
177
178
```python { .api }
179
# Reference illuminant A (tungsten)
180
REFERENCE_ILLUM_A: dict = {
181
# Spectral power distribution data 340-830nm
182
}
183
184
# Reference illuminant B (direct sunlight)
185
REFERENCE_ILLUM_B: dict = {
186
# Spectral power distribution data 340-830nm
187
}
188
189
# Reference illuminant C (average daylight)
190
REFERENCE_ILLUM_C: dict = {
191
# Spectral power distribution data 340-830nm
192
}
193
194
# Reference illuminant E (equal energy)
195
REFERENCE_ILLUM_E: dict = {
196
# Equal energy spectral distribution
197
}
198
199
# Blackbody illuminant data
200
REFERENCE_ILLUM_BLACKBODY: dict = {
201
# Blackbody spectral data for various temperatures
202
}
203
204
# Reference illuminant lookup table
205
REF_ILLUM_TABLE: dict = {
206
'a': REFERENCE_ILLUM_A,
207
'b': REFERENCE_ILLUM_B,
208
'c': REFERENCE_ILLUM_C,
209
'e': REFERENCE_ILLUM_E
210
}
211
```
212
213
## Usage Examples
214
215
### Working with Illuminants
216
217
```python
218
from colormath.color_constants import ILLUMINANTS, OBSERVERS
219
from colormath.color_objects import XYZColor
220
221
# Get illuminant XYZ values
222
d65_xyz_2deg = ILLUMINANTS['2']['d65']
223
d65_xyz_10deg = ILLUMINANTS['10']['d65']
224
225
print(f"D65 2°: X={d65_xyz_2deg[0]:.5f}, Y={d65_xyz_2deg[1]:.5f}, Z={d65_xyz_2deg[2]:.5f}")
226
227
# Available observers
228
print(f"Available observers: {OBSERVERS}")
229
230
# Create XYZ color with specific illuminant
231
xyz_color = XYZColor(xyz_x=0.4, xyz_y=0.3, xyz_z=0.2, illuminant='d50', observer='10')
232
illum_xyz = xyz_color.get_illuminant_xyz()
233
```
234
235
### Using CIE Constants
236
237
```python
238
from colormath.color_constants import CIE_E, CIE_K
239
240
# Example of using CIE constants in Lab calculations
241
def xyz_to_lab_component(value, white_point):
242
"""Example showing CIE constant usage."""
243
ratio = value / white_point
244
245
if ratio > CIE_E:
246
return ratio ** (1/3)
247
else:
248
return (CIE_K * ratio + 16) / 116
249
250
# Use in calculations
251
xyz_y = 0.18
252
white_y = 1.0
253
lab_f_y = xyz_to_lab_component(xyz_y, white_y)
254
```
255
256
### Density Standards Selection
257
258
```python
259
from colormath.density_standards import *
260
from colormath.density import ansi_density
261
262
# Dictionary of available standards
263
density_standards = {
264
'Status T': {
265
'red': ANSI_STATUS_T_RED,
266
'green': ANSI_STATUS_T_GREEN,
267
'blue': ANSI_STATUS_T_BLUE
268
},
269
'Status A': {
270
'red': ANSI_STATUS_A_RED,
271
'green': ANSI_STATUS_A_GREEN,
272
'blue': ANSI_STATUS_A_BLUE
273
},
274
'ISO Visual': ISO_VISUAL
275
}
276
277
def select_density_standard(application, color_channel=None):
278
"""
279
Select appropriate density standard for application.
280
281
Parameters:
282
- application: 'printing', 'photography', 'visual'
283
- color_channel: 'red', 'green', 'blue' (if applicable)
284
285
Returns:
286
Appropriate density standard
287
"""
288
if application == 'printing':
289
if color_channel:
290
return density_standards['Status T'][color_channel]
291
else:
292
return density_standards['Status T']['red'] # Default
293
elif application == 'photography':
294
if color_channel:
295
return density_standards['Status A'][color_channel]
296
else:
297
return density_standards['Status A']['red'] # Default
298
elif application == 'visual':
299
return density_standards['ISO Visual']
300
else:
301
raise ValueError(f"Unknown application: {application}")
302
303
# Example usage
304
printing_red_standard = select_density_standard('printing', 'red')
305
visual_standard = select_density_standard('visual')
306
```
307
308
### Chromatic Adaptation Matrices
309
310
```python
311
from colormath.color_constants import ADAPTATION_MATRICES
312
from colormath.chromatic_adaptation import apply_chromatic_adaptation
313
314
# Available adaptation methods
315
adaptation_methods = list(ADAPTATION_MATRICES.keys())
316
print(f"Available adaptation methods: {adaptation_methods}")
317
318
# Get Bradford adaptation matrix
319
bradford_matrix = ADAPTATION_MATRICES['bradford']['M']
320
bradford_inverse = ADAPTATION_MATRICES['bradford']['M_inv']
321
322
# Apply chromatic adaptation
323
xyz_adapted = apply_chromatic_adaptation(
324
val_x=0.4, val_y=0.3, val_z=0.2,
325
orig_illum='d65',
326
targ_illum='d50',
327
adaptation='bradford'
328
)
329
```
330
331
### Complete Constants Inspection
332
333
```python
334
from colormath import color_constants, density_standards, spectral_constants
335
336
def inspect_colormath_constants():
337
"""Inspect all available constants in colormath."""
338
339
print("=== COLOR CONSTANTS ===")
340
print(f"CIE_E: {color_constants.CIE_E}")
341
print(f"CIE_K: {color_constants.CIE_K}")
342
print(f"Available observers: {color_constants.OBSERVERS}")
343
print(f"Available illuminants: {list(color_constants.ILLUMINANTS['2'].keys())}")
344
print(f"Adaptation methods: {list(color_constants.ADAPTATION_MATRICES.keys())}")
345
346
print("\n=== DENSITY STANDARDS ===")
347
status_t_standards = [name for name in dir(density_standards) if 'STATUS_T' in name]
348
status_a_standards = [name for name in dir(density_standards) if 'STATUS_A' in name]
349
print(f"Status T standards: {len(status_t_standards)}")
350
print(f"Status A standards: {len(status_a_standards)}")
351
print(f"Visual density threshold: {density_standards.VISUAL_DENSITY_THRESH}")
352
353
print("\n=== SPECTRAL CONSTANTS ===")
354
illuminants = [name for name in dir(spectral_constants) if 'REFERENCE_ILLUM' in name]
355
print(f"Reference illuminants: {len(illuminants)}")
356
357
return {
358
'color_constants': len([attr for attr in dir(color_constants) if not attr.startswith('_')]),
359
'density_standards': len([attr for attr in dir(density_standards) if not attr.startswith('_')]),
360
'spectral_constants': len([attr for attr in dir(spectral_constants) if not attr.startswith('_')])
361
}
362
363
# Inspect all constants
364
constants_summary = inspect_colormath_constants()
365
```
366
367
## Standard Illuminant Specifications
368
369
### Common Illuminants
370
371
| Illuminant | Description | Color Temperature | Applications |
372
|------------|-------------|-------------------|-------------|
373
| A | Tungsten incandescent | 2856K | Photography, general lighting |
374
| B | Direct sunlight | 4874K | Obsolete, historical reference |
375
| C | Average daylight | 6774K | Photography, obsolete |
376
| D50 | Daylight | 5003K | Graphic arts, printing |
377
| D55 | Daylight | 5503K | Photography |
378
| D65 | Daylight | 6504K | Video, computer displays |
379
| D75 | Daylight | 7504K | LCD backlighting |
380
| E | Equal energy | N/A | Theoretical reference |
381
382
### Observer Angles
383
384
| Observer | Description | Field of View | Applications |
385
|----------|-------------|---------------|-------------|
386
| 2° | CIE 1931 Standard Observer | 2° field | Small samples, historical |
387
| 10° | CIE 1964 Supplementary Observer | 10° field | Large samples, modern standard |
388
389
## Density Standards Applications
390
391
### Status T (Transmission)
392
- Color negative film processing
393
- Transmission densitometry
394
- Color reproduction evaluation
395
396
### Status A (Reflection)
397
- Print density measurement
398
- Paper and ink evaluation
399
- Quality control in printing
400
401
### Status E (Photographic)
402
- Black and white photography
403
- Photographic printing
404
- Film density evaluation
405
406
### Status M (Motion Picture)
407
- Cinema film processing
408
- Motion picture printing
409
- Theater projection standards
410
411
### ISO Visual
412
- Visual color assessment
413
- Human vision correlation
414
- Perceptual color evaluation