or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-features.mdchromatic-adaptation.mdcolorimetry.mdcolour-appearance.mdcolour-difference.mdcolour-models.mdconstants.mdgeometry.mdindex.mdinput-output.mdmath-utilities.mdnotation.mdplotting.mdquality-assessment.mdtemperature.md

quality-assessment.mddocs/

0

# Quality Assessment

1

2

Comprehensive colour quality assessment functions for evaluating illumination source quality, colour fidelity, and spectral similarity. These functions implement industry-standard metrics including CRI, CQS, CFI, and advanced assessment methods for professional lighting evaluation and colour science applications.

3

4

## Capabilities

5

6

### Main Quality Assessment Functions

7

8

Primary entry points for colour quality calculations with automatic method selection and comprehensive result specifications.

9

10

```python { .api }

11

def colour_rendering_index(sd_test: SpectralDistribution, additional_data: bool = False) -> float | ColourRendering_Specification_CRI:

12

"""

13

Calculate Colour Rendering Index (CRI) Ra of given test spectral distribution.

14

15

Parameters:

16

- sd_test: test illuminant spectral distribution

17

- additional_data: whether to output detailed specification with individual sample data

18

19

Returns:

20

Float CRI Ra value (0-100) or detailed ColourRendering_Specification_CRI

21

22

Notes:

23

- Based on CIE 13.3-1995 standard using 8 test colour samples (TCS01-TCS08)

24

- Uses CIE 1931 2° Standard Observer and CIE 1960 UCS colour space

25

- Reference illuminant: blackbody radiator (CCT < 5000K) or CIE Illuminant D (CCT ≥ 5000K)

26

- Individual sample indexes available with additional_data=True

27

- Values: 100 = perfect colour rendering, lower values indicate poorer rendering

28

"""

29

30

def colour_quality_scale(sd_test: SpectralDistribution, additional_data: bool = False, method: str = "NIST CQS 9.0") -> float | ColourRendering_Specification_CQS:

31

"""

32

Calculate Colour Quality Scale (CQS) of given test spectral distribution.

33

34

Parameters:

35

- sd_test: test illuminant spectral distribution

36

- additional_data: whether to output detailed specification

37

- method: computation method:

38

* "NIST CQS 9.0": latest CQS method (default)

39

* "NIST CQS 7.4": legacy CQS method with preference metrics

40

41

Returns:

42

Float CQS Qa value (0-100) or detailed ColourRendering_Specification_CQS

43

44

Notes:

45

- Uses 15 virtual test samples (VS) covering wider gamut than CRI

46

- Employs CIE L*a*b* colour space with chromatic adaptation

47

- Includes colour fidelity (Qf), preference (Qp), and gamut (Qg) metrics

48

- More comprehensive than CRI, especially for LED and novel light sources

49

- Values: 100 = excellent quality, 0 = poor quality

50

"""

51

52

def colour_fidelity_index(sd_test: SpectralDistribution, additional_data: bool = False, method: str = "CIE 2017") -> float | ColourRendering_Specification_CIE2017 | ColourQuality_Specification_ANSIIESTM3018:

53

"""

54

Calculate Colour Fidelity Index (CFI) Rf of given test spectral distribution.

55

56

Parameters:

57

- sd_test: test illuminant spectral distribution

58

- additional_data: whether to output detailed specification

59

- method: computation method:

60

* "CIE 2017": CIE 2017 Colour Fidelity Index (default)

61

* "ANSI/IES TM-30-18": IES TM-30-18 method with gamut index

62

63

Returns:

64

Float CFI Rf value (0-100) or detailed specification object

65

66

Notes:

67

- Uses 99 test colour samples for comprehensive evaluation

68

- Based on CAM02-UCS uniform colour space for improved accuracy

69

- CIE 1964 10° Standard Observer for better correlation with visual assessment

70

- TM-30-18 method includes gamut index Rg and local metrics

71

- Superior to CRI for modern light sources and critical applications

72

"""

73

74

def spectral_similarity_index(sd_test: SpectralDistribution, sd_reference: SpectralDistribution, round_result: bool = True) -> NDArray:

75

"""

76

Calculate Academy Spectral Similarity Index (SSI) between test and reference spectra.

77

78

Parameters:

79

- sd_test: test spectral distribution

80

- sd_reference: reference spectral distribution

81

- round_result: whether to round result to integer (default True)

82

83

Returns:

84

SSI value (0-100), where 100 indicates perfect spectral match

85

86

Notes:

87

- Developed by Academy of Motion Picture Arts and Sciences

88

- Evaluates spectral similarity rather than colour rendering

89

- Uses 375-675nm range with 1nm resolution and specialized weighting

90

- Ideal for comparing LED sources to reference illuminants

91

- Does not require colour space transformations

92

"""

93

94

# Available methods for each quality metric

95

COLOUR_FIDELITY_INDEX_METHODS = {

96

"CIE 2017": colour_fidelity_index_CIE2017,

97

"ANSI/IES TM-30-18": colour_fidelity_index_ANSIIESTM3018

98

}

99

100

COLOUR_QUALITY_SCALE_METHODS = ("NIST CQS 7.4", "NIST CQS 9.0")

101

```

102

103

### CIE Colour Rendering Index (CRI) Functions

104

105

Traditional colour rendering evaluation based on CIE 13.3-1995 standard.

106

107

```python { .api }

108

def colour_rendering_index(sd_test: SpectralDistribution, additional_data: bool = False) -> float | ColourRendering_Specification_CRI:

109

"""

110

Calculate CRI Ra using 8 standard test colour samples.

111

112

Algorithm:

113

1. Determine CCT of test source using Robertson's method

114

2. Select reference illuminant (blackbody < 5000K, CIE D-series ≥ 5000K)

115

3. Calculate tristimulus values for test samples under both illuminants

116

4. Apply chromatic adaptation using CIE 1960 UCS

117

5. Compute individual rendering indexes Ri for each sample

118

6. Calculate general rendering index Ra as average of R1-R8

119

120

Test Colour Samples:

121

- TCS01: Light greyish red

122

- TCS02: Dark greyish yellow

123

- TCS03: Strong yellow green

124

- TCS04: Moderate yellowish green

125

- TCS05: Light bluish green

126

- TCS06: Light blue

127

- TCS07: Light violet

128

- TCS08: Light reddish purple

129

- TCS09-TCS14: Special samples (not included in Ra)

130

"""

131

132

def tcs_colorimetry_data(sd_t: SpectralDistribution, sd_r: SpectralDistribution, sds_tcs: dict, cmfs: MultiSpectralDistributions, chromatic_adaptation: bool = False) -> tuple:

133

"""

134

Calculate colorimetry data for test colour samples under test and reference illuminants.

135

136

Parameters:

137

- sd_t: test spectral distribution

138

- sd_r: reference spectral distribution

139

- sds_tcs: test colour sample spectral reflectance distributions

140

- cmfs: colour matching functions

141

- chromatic_adaptation: apply von Kries chromatic adaptation

142

143

Returns:

144

Tuple of DataColorimetry_TCS objects containing XYZ, uv, UVW data

145

"""

146

147

def colour_rendering_indexes(test_data: tuple, reference_data: tuple) -> dict:

148

"""

149

Calculate individual colour rendering indexes for each test sample.

150

151

Parameters:

152

- test_data: colorimetry data under test illuminant

153

- reference_data: colorimetry data under reference illuminant

154

155

Returns:

156

Dictionary mapping sample number to DataColourQualityScale_TCS

157

158

Formula: Ri = 100 - 4.6 * ΔE*uv

159

"""

160

```

161

162

### Colour Quality Scale (CQS) Functions

163

164

Advanced quality assessment using virtual test samples and improved colour space.

165

166

```python { .api }

167

def colour_quality_scale(sd_test: SpectralDistribution, additional_data: bool = False, method: str = "NIST CQS 9.0") -> float | ColourRendering_Specification_CQS:

168

"""

169

Calculate CQS using 15 virtual samples with comprehensive quality metrics.

170

171

Quality Metrics:

172

- Qa: Overall colour quality scale

173

- Qf: Colour fidelity scale (similar to CRI)

174

- Qp: Colour preference scale (rewards increased chroma)

175

- Qg: Gamut area scale (relative gamut size)

176

- Qd: Relative gamut area scale (deprecated in CQS 9.0)

177

178

Virtual Samples (VS):

179

- 15 synthetic reflectance spectra covering extended colour gamut

180

- More saturated colours than CRI test samples

181

- Better representation of real-world object colours

182

"""

183

184

def gamut_area(Lab: ArrayLike) -> float:

185

"""

186

Calculate gamut area covered by given L*a*b* coordinates using triangulation.

187

188

Parameters:

189

- Lab: L*a*b* colourspace matrices for samples

190

191

Returns:

192

Gamut area G using Heron's formula for triangular areas

193

"""

194

195

def vs_colorimetry_data(sd_test: SpectralDistribution, sd_reference: SpectralDistribution, sds_vs: dict, cmfs: MultiSpectralDistributions, chromatic_adaptation: bool = False) -> tuple:

196

"""

197

Calculate colorimetry data for virtual samples under test and reference illuminants.

198

199

Uses von Kries chromatic adaptation with CMCCAT2000 transform

200

when chromatic_adaptation=True for improved accuracy.

201

"""

202

203

def CCT_factor(reference_data: tuple, XYZ_r: ArrayLike) -> float:

204

"""

205

Calculate correlated colour temperature factor penalizing extremely low CCT lamps.

206

207

Returns factor ≤ 1.0 that reduces quality scores for sources with

208

very low CCT that compress the reference gamut.

209

"""

210

211

def scale_conversion(D_E_ab: float, CCT_f: float, scaling_f: float) -> float:

212

"""

213

Convert ΔE*ab value to CQS scale using logarithmic transformation.

214

215

Formula: Qa = 10 * log(1 + exp((100 - scaling_f * ΔE*ab) / 10)) * CCT_f

216

"""

217

218

def delta_E_RMS(CQS_data: dict, attribute: str) -> float:

219

"""

220

Calculate root-mean-square average for CQS data attributes.

221

222

Used to compute RMS values for ΔE*ab, ΔE'*ab, and ΔC*ab.

223

"""

224

225

def colour_quality_scales(test_data: tuple, reference_data: tuple, scaling_f: float, CCT_f: float) -> dict:

226

"""

227

Calculate individual quality scales for each virtual sample.

228

229

Computes chroma shift ΔC*ab, colour difference ΔE*ab,

230

and colour preference difference ΔE'*ab for each sample.

231

"""

232

233

# CQS reference gamut area constant

234

GAMUT_AREA_D65 = 8210 # Gamut area for CIE Illuminant D65

235

```

236

237

### CIE 2017 Colour Fidelity Index Functions

238

239

State-of-the-art colour fidelity assessment using 99 test samples and CAM02-UCS colour space.

240

241

```python { .api }

242

def colour_fidelity_index_CIE2017(sd_test: SpectralDistribution, additional_data: bool = False) -> float | ColourRendering_Specification_CIE2017:

243

"""

244

Calculate CIE 2017 Colour Fidelity Index using 99 test colour samples.

245

246

Technical Requirements:

247

- Spectral range: 380-780nm (recommended)

248

- Maximum interval: 5nm

249

- Observer: CIE 1964 10° Standard Observer

250

- Colour space: CAM02-UCS for uniform colour differences

251

- Missing values filled with zeros per standard

252

253

Test Colour Samples:

254

- 99 samples covering comprehensive colour space

255

- Real reflectance spectra from natural and artificial materials

256

- Superior coverage compared to CRI's 8 or 14 samples

257

"""

258

259

def load_TCS_CIE2017(shape: SpectralShape) -> MultiSpectralDistributions:

260

"""

261

Load CIE 2017 test colour samples dataset for given spectral shape.

262

263

Parameters:

264

- shape: spectral shape of tested illuminant

265

266

Returns:

267

MultiSpectralDistributions containing 99 test samples

268

269

Notes:

270

- Supports 1nm and 5nm intervals

271

- Cached for performance on subsequent calls

272

- Labels: TCS0-TCS98 (CIE 2017)

273

"""

274

275

def CCT_reference_illuminant(sd: SpectralDistribution) -> NDArray:

276

"""

277

Determine reference illuminant CCT and Δuv using Ohno 2013 method.

278

279

Uses optimized temperature range 1000K-25000K for performance.

280

Returns CCT and distance from Planckian locus.

281

"""

282

283

def sd_reference_illuminant(CCT: float, shape: SpectralShape) -> SpectralDistribution:

284

"""

285

Generate reference illuminant for given CCT following CIE 2017 standard.

286

287

Reference Selection:

288

- CCT < 4000K: Planckian radiator only

289

- 4000K ≤ CCT ≤ 5000K: Weighted mixture of Planckian and CIE D-series

290

- CCT > 5000K: CIE D-series illuminant only

291

292

Mixture ensures smooth transition between reference types.

293

"""

294

295

def tcs_colorimetry_data(sd_irradiance: SpectralDistribution | list, sds_tcs: MultiSpectralDistributions, cmfs: MultiSpectralDistributions) -> tuple:

296

"""

297

Calculate test colour sample colorimetry under CIE 2017 viewing conditions.

298

299

Viewing Conditions:

300

- Adapting luminance LA: 100 cd/m²

301

- Background luminance Yb: 20% of white

302

- Surround: Average (CIECAM02)

303

- Discount illuminant: True

304

"""

305

306

def delta_E_to_R_f(delta_E: ArrayLike) -> NDArray:

307

"""

308

Convert CAM02-UCS colour difference to CIE 2017 fidelity index.

309

310

Formula: Rf = 10 * log(1 + exp((100 - 6.73 * ΔE) / 10))

311

312

Where ΔE is Euclidean distance in CAM02-UCS colour space.

313

"""

314

315

# CIE 2017 constants

316

SPECTRAL_SHAPE_CIE2017 = SpectralShape(380, 780, 1) # Standard spectral shape

317

ROOT_RESOURCES_CIE2017 = "datasets/" # TCS data directory

318

```

319

320

### ANSI/IES TM-30-18 Functions

321

322

Extended colour fidelity assessment with gamut index and local colour fidelity metrics.

323

324

```python { .api }

325

def colour_fidelity_index_ANSIIESTM3018(sd_test: SpectralDistribution, additional_data: bool = False) -> float | ColourQuality_Specification_ANSIIESTM3018:

326

"""

327

Calculate ANSI/IES TM-30-18 Colour Fidelity Index with comprehensive metrics.

328

329

Based on CIE 2017 CFI with additional TM-30-18 specific metrics:

330

- Rf: Colour fidelity index (same as CIE 2017)

331

- Rg: Gamut index (relative gamut area)

332

- Rfs: 16 local colour fidelity indexes per hue bin

333

- Rcs: 16 local chromaticity shifts (%)

334

- Rhs: 16 local hue shifts

335

336

Hue Binning:

337

- 16 equal hue bins of 22.5° each in CAM02-UCS a'b' plane

338

- Bin assignment based on reference sample hue angles

339

- Local metrics provide detailed spectral performance analysis

340

"""

341

342

def averages_area(averages: ArrayLike) -> float:

343

"""

344

Calculate area of polygon formed by hue bin averages using shoelace formula.

345

346

Used for computing gamut index Rg = 100 * (test_area / reference_area).

347

"""

348

349

# TM-30-18 hue bin configuration

350

# 16 bins × 22.5° = 360° coverage

351

# Bin centers: 11.25°, 33.75°, ..., 348.75°

352

```

353

354

### Academy Spectral Similarity Index Functions

355

356

Direct spectral comparison without colour space transformations.

357

358

```python { .api }

359

def spectral_similarity_index(sd_test: SpectralDistribution, sd_reference: SpectralDistribution, round_result: bool = True) -> NDArray:

360

"""

361

Calculate Academy Spectral Similarity Index for direct spectral comparison.

362

363

Algorithm:

364

1. Normalize spectra to 375-675nm at 1nm resolution

365

2. Integrate using weighted trapezoidal rule over 10nm bands

366

3. Calculate relative differences with reference offset

367

4. Apply wavelength-dependent weighting (higher weight 500-600nm)

368

5. Convolve with smoothing kernel [0.22, 0.56, 0.22]

369

6. Compute SSI = 100 - 32 * √(Σ(weighted_differences²))

370

371

Spectral Requirements:

372

- Range: 375-675nm (extrapolated with zeros outside)

373

- Resolution: 1nm (interpolated from input)

374

- Normalization: area under curve = 1.0

375

376

Weighting Function:

377

- 375-425nm: 4/15 to 22/45 (low weight, blue)

378

- 425-575nm: 32/45 to 1.0 (high weight, visible)

379

- 575-625nm: 1.0 (maximum weight, yellow-green)

380

- 625-675nm: 11/15 to 3/15 (decreasing weight, red)

381

382

Applications:

383

- LED source matching to reference illuminants

384

- Spectral metameric evaluation

385

- Light source development and quality control

386

"""

387

388

# SSI constants

389

SPECTRAL_SHAPE_SSI = SpectralShape(375, 675, 1) # Required spectral shape

390

```

391

392

## Specification Classes

393

394

Comprehensive data classes for structured quality assessment results.

395

396

```python { .api }

397

class ColourRendering_Specification_CRI:

398

"""

399

CRI computation results with detailed sample-by-sample data.

400

401

Attributes:

402

- name: test illuminant name

403

- Q_a: general colour rendering index Ra (0-100)

404

- Q_as: individual sample rendering indexes R1-R14

405

- colorimetry_data: test and reference colorimetry computations

406

407

Individual Sample Data (DataColourQualityScale_TCS):

408

- name: sample name (e.g., "TCS01")

409

- Q_a: individual rendering index Ri

410

"""

411

412

class ColourRendering_Specification_CQS:

413

"""

414

CQS computation results with comprehensive quality metrics.

415

416

Attributes:

417

- name: test illuminant name

418

- Q_a: overall colour quality scale (0-100)

419

- Q_f: colour fidelity scale (0-100)

420

- Q_p: colour preference scale (0-100, None in CQS 9.0)

421

- Q_g: gamut area scale (relative to D65)

422

- Q_d: relative gamut area scale (None in CQS 9.0)

423

- Q_as: individual sample quality data

424

- colorimetry_data: detailed colorimetric computations

425

426

Sample Data (DataColourQualityScale_VS):

427

- name: virtual sample name

428

- Q_a: sample quality scale

429

- D_C_ab: chroma difference ΔC*ab

430

- D_E_ab: colour difference ΔE*ab

431

- D_Ep_ab: preference-weighted colour difference

432

"""

433

434

class ColourRendering_Specification_CIE2017:

435

"""

436

CIE 2017 CFI results with advanced colorimetric data.

437

438

Attributes:

439

- name: test illuminant name

440

- sd_reference: reference illuminant spectrum

441

- R_f: colour fidelity index (0-100)

442

- R_s: individual sample fidelity indexes (99 values)

443

- CCT: correlated colour temperature (K)

444

- D_uv: distance from Planckian locus

445

- colorimetry_data: CAM02-UCS based computations

446

- delta_E_s: colour shifts in CAM02-UCS space

447

448

Colorimetry Data (DataColorimetry_TCS_CIE2017):

449

- name: sample names (99 TCS labels)

450

- XYZ: CIE XYZ tristimulus values

451

- CAM: CIECAM02 appearance specification

452

- JMh: lightness-chroma-hue coordinates

453

- Jpapbp: CAM02-UCS uniform colour coordinates

454

"""

455

456

class ColourQuality_Specification_ANSIIESTM3018:

457

"""

458

TM-30-18 extended colour quality specification with local metrics.

459

460

Extends CIE 2017 specification with:

461

- R_g: gamut index (relative gamut area)

462

- bins: hue bin assignments for 99 samples

463

- averages_test: test hue bin average coordinates

464

- averages_reference: reference hue bin averages

465

- average_norms: reference coordinate magnitudes

466

- R_fs: local fidelity indexes (16 hue bins)

467

- R_cs: local chromaticity shifts (16 values, %)

468

- R_hs: local hue shifts (16 values)

469

470

Local Metrics Applications:

471

- Identify specific hue regions with poor performance

472

- Evaluate gamut compression/expansion patterns

473

- Optimize LED spectra for targeted applications

474

"""

475

476

# Supporting data classes

477

class DataColorimetry_TCS:

478

"""CRI test colour sample colorimetry data."""

479

# name: sample name, XYZ: tristimulus, uv: chromaticity, UVW: uniform coordinates

480

481

class DataColourQualityScale_TCS:

482

"""CRI sample quality scale data."""

483

# name: sample name, Q_a: rendering index

484

485

class DataColorimetry_VS:

486

"""CQS virtual sample colorimetry data."""

487

# name: sample name, XYZ: tristimulus, Lab: L*a*b*, C: chroma

488

489

class DataColourQualityScale_VS:

490

"""CQS sample quality scale data."""

491

# name: sample name, Q_a: quality, D_C_ab: chroma shift, D_E_ab: colour shift, D_Ep_ab: preference shift

492

493

class DataColorimetry_TCS_CIE2017:

494

"""CIE 2017 test sample colorimetry data."""

495

# name: sample names, XYZ: tristimulus, CAM: appearance, JMh: appearance coordinates, Jpapbp: uniform coordinates

496

```

497

498

## Constants and Datasets

499

500

Essential constants and datasets for quality assessment computations.

501

502

```python { .api }

503

# Test colour sample datasets

504

SDS_TCS = {

505

# CRI test colour samples (TCS01-TCS14)

506

"TCS01": SpectralDistribution, # Light greyish red

507

"TCS02": SpectralDistribution, # Dark greyish yellow

508

"TCS03": SpectralDistribution, # Strong yellow green

509

"TCS04": SpectralDistribution, # Moderate yellowish green

510

"TCS05": SpectralDistribution, # Light bluish green

511

"TCS06": SpectralDistribution, # Light blue

512

"TCS07": SpectralDistribution, # Light violet

513

"TCS08": SpectralDistribution, # Light reddish purple

514

"TCS09": SpectralDistribution, # Strong red

515

"TCS10": SpectralDistribution, # Strong yellow

516

"TCS11": SpectralDistribution, # Strong green

517

"TCS12": SpectralDistribution, # Strong blue

518

"TCS13": SpectralDistribution, # Light yellowish pink (Caucasian skin)

519

"TCS14": SpectralDistribution # Moderate olive green (leaf)

520

}

521

522

SDS_VS = {

523

"NIST CQS 7.4": {

524

# 15 virtual samples for CQS 7.4

525

},

526

"NIST CQS 9.0": {

527

# 15 virtual samples for CQS 9.0

528

}

529

}

530

531

# Sample index mappings

532

INDEXES_TO_NAMES_TCS = {

533

1: "TCS01", 2: "TCS02", 3: "TCS03", 4: "TCS04",

534

5: "TCS05", 6: "TCS06", 7: "TCS07", 8: "TCS08",

535

9: "TCS09", 10: "TCS10", 11: "TCS11", 12: "TCS12",

536

13: "TCS13", 14: "TCS14"

537

}

538

539

INDEXES_TO_NAMES_VS = {

540

# Virtual sample index to name mapping

541

}

542

543

# Reference gamut area

544

GAMUT_AREA_D65 = 8210 # CIE Illuminant D65 gamut area for CQS normalization

545

546

# Spectral shapes

547

SPECTRAL_SHAPE_CIE2017 = SpectralShape(380, 780, 1) # CIE 2017 standard shape

548

SPECTRAL_SHAPE_SSI = SpectralShape(375, 675, 1) # SSI computation shape

549

```

550

551

## Usage Examples

552

553

Practical examples demonstrating quality assessment workflows for different applications.

554

555

### Basic Quality Assessment

556

557

```python

558

from colour import SDS_ILLUMINANTS, SpectralDistribution

559

from colour.quality import (

560

colour_rendering_index, colour_quality_scale,

561

colour_fidelity_index, spectral_similarity_index

562

)

563

564

# Load test illuminant

565

sd_test = SDS_ILLUMINANTS["FL2"] # Fluorescent F2

566

567

# Basic quality metrics

568

cri = colour_rendering_index(sd_test)

569

print(f"CRI Ra: {cri:.1f}") # CRI Ra: 64.2

570

571

cqs = colour_quality_scale(sd_test)

572

print(f"CQS Qa: {cqs:.1f}") # CQS Qa: 64.1

573

574

cfi = colour_fidelity_index(sd_test)

575

print(f"CFI Rf: {cfi:.1f}") # CFI Rf: 70.1

576

577

# Spectral similarity to daylight

578

sd_d65 = SDS_ILLUMINANTS["D65"]

579

ssi = spectral_similarity_index(sd_test, sd_d65)

580

print(f"SSI: {ssi:.0f}") # SSI: 75

581

```

582

583

### Detailed Assessment with Specifications

584

585

```python

586

# Get detailed CRI specification with individual sample data

587

cri_spec = colour_rendering_index(sd_test, additional_data=True)

588

print(f"General CRI: {cri_spec.Q_a:.1f}")

589

for i, (sample_num, sample_data) in enumerate(cri_spec.Q_as.items(), 1):

590

if i <= 8: # Show first 8 samples used in Ra

591

print(f" R{sample_num} ({sample_data.name}): {sample_data.Q_a:.1f}")

592

593

# Detailed CQS with all quality metrics

594

cqs_spec = colour_quality_scale(sd_test, additional_data=True, method="NIST CQS 9.0")

595

print(f"CQS Quality Metrics:")

596

print(f" Qa (Overall): {cqs_spec.Q_a:.1f}")

597

print(f" Qf (Fidelity): {cqs_spec.Q_f:.1f}")

598

print(f" Qg (Gamut): {cqs_spec.Q_g:.1f}")

599

# Qp and Qd are None in CQS 9.0

600

601

# TM-30-18 with local hue metrics

602

tm30_spec = colour_fidelity_index(sd_test, additional_data=True, method="ANSI/IES TM-30-18")

603

print(f"TM-30-18 Metrics:")

604

print(f" Rf (Fidelity): {tm30_spec.R_f:.1f}")

605

print(f" Rg (Gamut): {tm30_spec.R_g:.1f}")

606

print(f"Local Fidelity by Hue Bin:")

607

for i, rf_local in enumerate(tm30_spec.R_fs):

608

hue_center = 22.5 * i + 11.25

609

print(f" Bin {i+1} ({hue_center:.1f}°): Rf={rf_local:.1f}")

610

```

611

612

### LED Source Development

613

614

```python

615

# Evaluate custom LED spectrum

616

led_data = {

617

380: 0.001, 385: 0.002, 390: 0.003, 395: 0.005,

618

# ... LED spectral data ...

619

450: 0.850, 455: 0.900, 460: 0.950, # Blue peak

620

# ...

621

550: 0.120, 555: 0.150, 560: 0.180, # Green component

622

# ...

623

630: 0.280, 635: 0.300, 640: 0.320 # Red peak

624

}

625

sd_led = SpectralDistribution(led_data, name="Custom LED")

626

627

# Comprehensive quality assessment

628

print("LED Quality Assessment:")

629

print(f"CRI Ra: {colour_rendering_index(sd_led):.1f}")

630

print(f"CQS Qa: {colour_quality_scale(sd_led):.1f}")

631

print(f"CFI Rf: {colour_fidelity_index(sd_led):.1f}")

632

633

# Compare spectral match to target illuminant

634

target = SDS_ILLUMINANTS["D65"]

635

ssi_match = spectral_similarity_index(sd_led, target)

636

print(f"SSI to D65: {ssi_match:.0f}")

637

638

# TM-30-18 for detailed analysis

639

tm30 = colour_fidelity_index(sd_led, additional_data=True, method="ANSI/IES TM-30-18")

640

print(f"Gamut Index Rg: {tm30.R_g:.1f}")

641

642

# Identify weak hue regions

643

weak_hues = [(i, rf) for i, rf in enumerate(tm30.R_fs) if rf < 80]

644

if weak_hues:

645

print("Weak Performance Hue Regions:")

646

for bin_idx, rf_val in weak_hues:

647

hue_deg = 22.5 * bin_idx + 11.25

648

print(f" {hue_deg:.0f}° (Rf={rf_val:.1f})")

649

```

650

651

### Method Comparison Study

652

653

```python

654

# Compare all methods for multiple sources

655

sources = ["A", "D65", "FL2", "FL11"] # Incandescent, daylight, fluorescent

656

methods_cfi = ["CIE 2017", "ANSI/IES TM-30-18"]

657

methods_cqs = ["NIST CQS 7.4", "NIST CQS 9.0"]

658

659

print("Quality Assessment Comparison:")

660

print("Source | CRI Ra | CQS 7.4| CQS 9.0| CFI 17 | TM30-18| SSI->D65")

661

print("-" * 70)

662

663

for source in sources:

664

sd = SDS_ILLUMINANTS[source]

665

666

# Calculate all metrics

667

cri = colour_rendering_index(sd)

668

cqs_74 = colour_quality_scale(sd, method="NIST CQS 7.4")

669

cqs_90 = colour_quality_scale(sd, method="NIST CQS 9.0")

670

cfi_17 = colour_fidelity_index(sd, method="CIE 2017")

671

cfi_tm30 = colour_fidelity_index(sd, method="ANSI/IES TM-30-18")

672

ssi = spectral_similarity_index(sd, SDS_ILLUMINANTS["D65"])

673

674

print(f"{source:9} | {cri:6.1f} | {cqs_74:6.1f} | {cqs_90:6.1f} | "

675

f"{cfi_17:6.1f} | {cfi_tm30:7.1f} | {ssi:7.0f}")

676

```

677

678

## Technical Notes

679

680

### Computational Considerations

681

682

- **CRI**: Fastest computation, suitable for real-time applications

683

- **CQS**: Moderate complexity, good for general LED evaluation

684

- **CFI**: Most computationally intensive due to 99 samples and CAM02-UCS

685

- **SSI**: Fast spectral-only computation, no colour space transforms

686

687

### Method Selection Guidelines

688

689

- **CRI**: Legacy applications, regulatory compliance, basic evaluation

690

- **CQS**: LED development, broader gamut assessment than CRI

691

- **CIE 2017 CFI**: Research applications, most accurate colour fidelity

692

- **TM-30-18**: Comprehensive lighting design, local performance analysis

693

- **SSI**: Spectral matching, metameric source development

694

695

### Spectral Requirements

696

697

- **Range**: 380-780nm recommended (CRI/CQS/CFI), 375-675nm (SSI)

698

- **Resolution**: ≤5nm intervals for CFI, 1nm preferred for SSI

699

- **Extrapolation**: Zero-padding for missing spectral regions

700

- **Normalization**: Methods handle relative spectral data appropriately

701

702

### Accuracy and Limitations

703

704

- All methods assume 2° or 10° standard observer viewing conditions

705

- CRI limited by 8 test samples and CIE 1960 UCS colour space

706

- CQS virtual samples better represent real object colours than CRI

707

- CFI most correlates with visual assessments due to CAM02-UCS uniformity

708

- SSI evaluates spectral similarity, not colour rendering quality

709

710

The quality assessment module provides comprehensive tools for professional lighting evaluation, supporting both traditional CRI assessment and advanced methods for modern light sources including LEDs, OLEDs, and laser-based systems.