CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-colormath

Color math and conversion library for comprehensive color space transformations and color difference calculations.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

constants-standards.mddocs/

Constants and Standards

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.

Capabilities

Color Constants

Fundamental mathematical constants used in CIE color calculations.

# CIE constants
CIE_E: float = 216.0/24389.0    # CIE epsilon constant
CIE_K: float = 24389.0/27.0     # CIE kappa constant

# Usage in Lab/XYZ conversions and other CIE calculations

Illuminant Data

Comprehensive illuminant XYZ values for different observer angles and standard illuminants.

ILLUMINANTS: dict = {
    '2': {  # 2-degree observer
        'd65': (0.95047, 1.00000, 1.08883),
        'd50': (0.96422, 1.00000, 0.82521),
        'a': (1.09850, 1.00000, 0.35585),
        'c': (0.98074, 1.00000, 1.18232),
        'e': (1.00000, 1.00000, 1.00000),
        # ... additional illuminants
    },
    '10': {  # 10-degree observer
        'd65': (0.94811, 1.00000, 1.07304),
        'd50': (0.96720, 1.00000, 0.81427),
        'a': (1.11144, 1.00000, 0.35200),
        'c': (0.97285, 1.00000, 1.16145),
        'e': (1.00000, 1.00000, 1.00000),
        # ... additional illuminants
    }
}

OBSERVERS: list = ['2', '10']  # Available observer angles

Chromatic Adaptation Matrices

Transformation matrices for chromatic adaptation between different illuminants.

ADAPTATION_MATRICES: dict = {
    'bradford': {
        'M': [[0.8951, 0.2664, -0.1614],
              [-0.7502, 1.7135, 0.0367],
              [0.0389, -0.0685, 1.0296]],
        'M_inv': [[0.9869929, -0.1470543, 0.1599627],
                  [0.4323053, 0.5183603, 0.0492912],
                  [-0.0085287, 0.0400428, 0.9684867]]
    },
    'von_kries': {
        'M': [[0.4002400, 0.7076000, -0.0808100],
              [-0.2280000, 1.1500000, 0.0612000],
              [0.0000000, 0.0000000, 0.9184000]],
        'M_inv': [[1.8599364, -1.1293816, 0.2198974],
                  [0.3611914, 0.6388125, -0.0000064],  
                  [0.0000000, 0.0000000, 1.0888251]]
    }
    # ... additional adaptation methods
}

Density Standards

ANSI Status T Standards

Transmission density standards for color reproduction.

# ANSI Status T Red
ANSI_STATUS_T_RED: dict = {
    # Spectral response data for Status T Red filter
    # Wavelength data from 340-830nm
}

# ANSI Status T Green  
ANSI_STATUS_T_GREEN: dict = {
    # Spectral response data for Status T Green filter
}

# ANSI Status T Blue
ANSI_STATUS_T_BLUE: dict = {
    # Spectral response data for Status T Blue filter
}

ANSI Status A Standards

Reflection density standards for printing applications.

# ANSI Status A Red
ANSI_STATUS_A_RED: dict = {
    # Spectral response data for Status A Red filter
}

# ANSI Status A Green
ANSI_STATUS_A_GREEN: dict = {
    # Spectral response data for Status A Green filter  
}

# ANSI Status A Blue
ANSI_STATUS_A_BLUE: dict = {
    # Spectral response data for Status A Blue filter
}

ANSI Status E Standards

Photographic density standards.

# ANSI Status E Red
ANSI_STATUS_E_RED: dict = {
    # Spectral response data for Status E Red filter
}

# ANSI Status E Green
ANSI_STATUS_E_GREEN: dict = {
    # Spectral response data for Status E Green filter
}

# ANSI Status E Blue  
ANSI_STATUS_E_BLUE: dict = {
    # Spectral response data for Status E Blue filter
}

ANSI Status M Standards

Motion picture density standards.

# ANSI Status M Red
ANSI_STATUS_M_RED: dict = {
    # Spectral response data for Status M Red filter
}

# ANSI Status M Green
ANSI_STATUS_M_GREEN: dict = {
    # Spectral response data for Status M Green filter
}

# ANSI Status M Blue
ANSI_STATUS_M_BLUE: dict = {
    # Spectral response data for Status M Blue filter
}

ISO Visual Standards

Visual density standards for human visual assessment.

# ISO Visual density standard
ISO_VISUAL: dict = {
    # Spectral response data matching human visual response
}

# Visual density threshold for automatic standard selection
VISUAL_DENSITY_THRESH: float = 0.08

Spectral Reference Data

Reference Illuminants

Complete spectral power distributions for standard illuminants.

# Reference illuminant A (tungsten)
REFERENCE_ILLUM_A: dict = {
    # Spectral power distribution data 340-830nm
}

# Reference illuminant B (direct sunlight)
REFERENCE_ILLUM_B: dict = {
    # Spectral power distribution data 340-830nm
}

# Reference illuminant C (average daylight)
REFERENCE_ILLUM_C: dict = {
    # Spectral power distribution data 340-830nm
}

# Reference illuminant E (equal energy)
REFERENCE_ILLUM_E: dict = {
    # Equal energy spectral distribution
}

# Blackbody illuminant data
REFERENCE_ILLUM_BLACKBODY: dict = {
    # Blackbody spectral data for various temperatures
}

# Reference illuminant lookup table
REF_ILLUM_TABLE: dict = {
    'a': REFERENCE_ILLUM_A,
    'b': REFERENCE_ILLUM_B,  
    'c': REFERENCE_ILLUM_C,
    'e': REFERENCE_ILLUM_E
}

Usage Examples

Working with Illuminants

from colormath.color_constants import ILLUMINANTS, OBSERVERS
from colormath.color_objects import XYZColor

# Get illuminant XYZ values
d65_xyz_2deg = ILLUMINANTS['2']['d65']
d65_xyz_10deg = ILLUMINANTS['10']['d65']

print(f"D65 2°: X={d65_xyz_2deg[0]:.5f}, Y={d65_xyz_2deg[1]:.5f}, Z={d65_xyz_2deg[2]:.5f}")

# Available observers
print(f"Available observers: {OBSERVERS}")

# Create XYZ color with specific illuminant
xyz_color = XYZColor(xyz_x=0.4, xyz_y=0.3, xyz_z=0.2, illuminant='d50', observer='10')
illum_xyz = xyz_color.get_illuminant_xyz()

Using CIE Constants

from colormath.color_constants import CIE_E, CIE_K

# Example of using CIE constants in Lab calculations
def xyz_to_lab_component(value, white_point):
    """Example showing CIE constant usage."""
    ratio = value / white_point
    
    if ratio > CIE_E:
        return ratio ** (1/3)
    else:
        return (CIE_K * ratio + 16) / 116

# Use in calculations
xyz_y = 0.18
white_y = 1.0
lab_f_y = xyz_to_lab_component(xyz_y, white_y)

Density Standards Selection

from colormath.density_standards import *
from colormath.density import ansi_density

# Dictionary of available standards
density_standards = {
    'Status T': {
        'red': ANSI_STATUS_T_RED,
        'green': ANSI_STATUS_T_GREEN,
        'blue': ANSI_STATUS_T_BLUE
    },
    'Status A': {
        'red': ANSI_STATUS_A_RED,
        'green': ANSI_STATUS_A_GREEN,
        'blue': ANSI_STATUS_A_BLUE
    },
    'ISO Visual': ISO_VISUAL
}

def select_density_standard(application, color_channel=None):
    """
    Select appropriate density standard for application.
    
    Parameters:
    - application: 'printing', 'photography', 'visual'
    - color_channel: 'red', 'green', 'blue' (if applicable)
    
    Returns:
    Appropriate density standard
    """
    if application == 'printing':
        if color_channel:
            return density_standards['Status T'][color_channel]
        else:
            return density_standards['Status T']['red']  # Default
    elif application == 'photography':
        if color_channel:
            return density_standards['Status A'][color_channel]
        else:
            return density_standards['Status A']['red']  # Default
    elif application == 'visual':
        return density_standards['ISO Visual']
    else:
        raise ValueError(f"Unknown application: {application}")

# Example usage
printing_red_standard = select_density_standard('printing', 'red')
visual_standard = select_density_standard('visual')

Chromatic Adaptation Matrices

from colormath.color_constants import ADAPTATION_MATRICES
from colormath.chromatic_adaptation import apply_chromatic_adaptation

# Available adaptation methods
adaptation_methods = list(ADAPTATION_MATRICES.keys())
print(f"Available adaptation methods: {adaptation_methods}")

# Get Bradford adaptation matrix
bradford_matrix = ADAPTATION_MATRICES['bradford']['M']
bradford_inverse = ADAPTATION_MATRICES['bradford']['M_inv']

# Apply chromatic adaptation
xyz_adapted = apply_chromatic_adaptation(
    val_x=0.4, val_y=0.3, val_z=0.2,
    orig_illum='d65',
    targ_illum='d50', 
    adaptation='bradford'
)

Complete Constants Inspection

from colormath import color_constants, density_standards, spectral_constants

def inspect_colormath_constants():
    """Inspect all available constants in colormath."""
    
    print("=== COLOR CONSTANTS ===")
    print(f"CIE_E: {color_constants.CIE_E}")
    print(f"CIE_K: {color_constants.CIE_K}")
    print(f"Available observers: {color_constants.OBSERVERS}")
    print(f"Available illuminants: {list(color_constants.ILLUMINANTS['2'].keys())}")
    print(f"Adaptation methods: {list(color_constants.ADAPTATION_MATRICES.keys())}")
    
    print("\n=== DENSITY STANDARDS ===")
    status_t_standards = [name for name in dir(density_standards) if 'STATUS_T' in name]
    status_a_standards = [name for name in dir(density_standards) if 'STATUS_A' in name]
    print(f"Status T standards: {len(status_t_standards)}")
    print(f"Status A standards: {len(status_a_standards)}")
    print(f"Visual density threshold: {density_standards.VISUAL_DENSITY_THRESH}")
    
    print("\n=== SPECTRAL CONSTANTS ===")
    illuminants = [name for name in dir(spectral_constants) if 'REFERENCE_ILLUM' in name]
    print(f"Reference illuminants: {len(illuminants)}")
    
    return {
        'color_constants': len([attr for attr in dir(color_constants) if not attr.startswith('_')]),
        'density_standards': len([attr for attr in dir(density_standards) if not attr.startswith('_')]),
        'spectral_constants': len([attr for attr in dir(spectral_constants) if not attr.startswith('_')])
    }

# Inspect all constants
constants_summary = inspect_colormath_constants()

Standard Illuminant Specifications

Common Illuminants

IlluminantDescriptionColor TemperatureApplications
ATungsten incandescent2856KPhotography, general lighting
BDirect sunlight4874KObsolete, historical reference
CAverage daylight6774KPhotography, obsolete
D50Daylight5003KGraphic arts, printing
D55Daylight5503KPhotography
D65Daylight6504KVideo, computer displays
D75Daylight7504KLCD backlighting
EEqual energyN/ATheoretical reference

Observer Angles

ObserverDescriptionField of ViewApplications
CIE 1931 Standard Observer2° fieldSmall samples, historical
10°CIE 1964 Supplementary Observer10° fieldLarge samples, modern standard

Density Standards Applications

Status T (Transmission)

  • Color negative film processing
  • Transmission densitometry
  • Color reproduction evaluation

Status A (Reflection)

  • Print density measurement
  • Paper and ink evaluation
  • Quality control in printing

Status E (Photographic)

  • Black and white photography
  • Photographic printing
  • Film density evaluation

Status M (Motion Picture)

  • Cinema film processing
  • Motion picture printing
  • Theater projection standards

ISO Visual

  • Visual color assessment
  • Human vision correlation
  • Perceptual color evaluation

Install with Tessl CLI

npx tessl i tessl/pypi-colormath

docs

chromatic-adaptation.md

color-appearance-models.md

color-conversions.md

color-diff.md

color-objects.md

constants-standards.md

index.md

spectral-density.md

tile.json