apca-introduction

The missing introduction to APCA  https://p.ce9e.org/apca-introduction/
git clone https://git.ce9e.org/apca-introduction.git

commit
2860a9a9db41c1b87941bdbd6f9fad198a357b81
parent
3cf1a55eac51fcc03e0a47a6ca2af88168363562
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-07-16 09:57
add sRGBtoY_comparison

Diffstat

A plots/sRGBtoY_comparison.png 0
A plots/sRGBtoY_comparison.py 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 59 insertions, 0 deletions


diff --git a/plots/sRGBtoY_comparison.png b/plots/sRGBtoY_comparison.png

Binary files differ.

diff --git a/plots/sRGBtoY_comparison.py b/plots/sRGBtoY_comparison.py

@@ -0,0 +1,59 @@
   -1     1 from matplotlib import pyplot as plt
   -1     2 import numpy as np
   -1     3 
   -1     4 WCAG_FACTORS = [1, 0.2126, 0.7152, 0.0722]
   -1     5 APCA_FACTORS = [1, 0.2126729, 0.7151522, 0.0721750]
   -1     6 APCA_EXPONENTS = [0.56, 0.57, 0.62, 0.65]
   -1     7 
   -1     8 
   -1     9 def wcag(x, factor, ambient):
   -1    10 	y = x / 255
   -1    11 	y = np.where(y < 0.04045, y / 12.92, ((y + 0.055) / 1.055) ** 2.4)
   -1    12 	y *= factor
   -1    13 	return (y + ambient) / (1 + ambient)
   -1    14 
   -1    15 
   -1    16 def apca(x, factor, exp):
   -1    17 	y = x / 255
   -1    18 	y **= 2.4
   -1    19 	y *= factor
   -1    20 	y += np.where(y < 0.022, 0.022 - y, 0) ** 1.414
   -1    21 	y **= exp
   -1    22 	return np.exp(y) / np.exp(1)
   -1    23 
   -1    24 
   -1    25 if __name__ == '__main__':
   -1    26 	x = np.linspace(0, 255, 256)
   -1    27 	fig, axes = plt.subplots(4, 2, sharex=True, sharey='col', figsize=(6.4, 8))
   -1    28 
   -1    29 	for i in range(4):
   -1    30 		wcag6 = wcag(x, WCAG_FACTORS[i], 0.6)
   -1    31 
   -1    32 		for exp in APCA_EXPONENTS:
   -1    33 			y = apca(x, APCA_FACTORS[i], exp)
   -1    34 			axes[i][0].plot(x, y)
   -1    35 			axes[i][1].plot(x, wcag6 - y)
   -1    36 
   -1    37 		axes[i][0].plot(x, wcag(x, WCAG_FACTORS[i], 0.05))
   -1    38 		axes[i][0].plot(x, wcag6)
   -1    39 
   -1    40 	axes[0][0].set_ylabel('gray')
   -1    41 	axes[1][0].set_ylabel('red')
   -1    42 	axes[2][0].set_ylabel('green')
   -1    43 	axes[3][0].set_ylabel('blue')
   -1    44 
   -1    45 	axes[0][0].set_title('sRGBtoY')
   -1    46 	axes[0][1].set_title('difference to WCAG 0.6')
   -1    47 
   -1    48 	fig.legend([
   -1    49 		'APCA 0.56',
   -1    50 		'APCA 0.57',
   -1    51 		'APCA 0.62',
   -1    52 		'APCA 0.65',
   -1    53 		'WCAG 0.05',
   -1    54 		'WCAG 0.6',
   -1    55 	], ncol=3, loc='lower center')
   -1    56 
   -1    57 	plt.tight_layout()
   -1    58 	plt.subplots_adjust(bottom=0.1)
   -1    59 	plt.savefig('sRGBtoY_comparison.png')