-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinConversions.py
30 lines (26 loc) · 1.13 KB
/
linConversions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
def sRGB_to_lin(rgb):
# Converts array or list of sRGB values to linear RGB values
rgb = np.array(rgb)/255
linear = np.where(rgb<=0.04045, rgb/12.92, ((rgb+0.055)/1.055)**(2.4))
return((linear*255).astype(int))
def lin_to_XYZ(lin):
# Converts array of linear RGB values to XYZ values
lin = np.array(lin)/255
M = np.array([[0.4124, 0.3576, 0.1805],
[0.2126, 0.7152, 0.0722],
[0.0193, 0.1192, 0.9505]])
return(np.transpose(np.matmul(M, np.transpose(lin))))
def lin_to_sRGB(lin):
# Converts array or list of linear RGB values to sRGB values
lin = np.array(lin)/255
rgb = np.where(lin <= 0.0031308, 12.92*lin, (1.055*lin)**(1/2.4)-0.055)
return((rgb*255).astype(int))
def sRGB_to_XYZ(rgb):
# Converts array of sRGB values to XYZ values
rgb = rgb/255
linear = np.where(rgb<=0.04045, rgb/12.92, ((rgb+0.055)/1.055)**2.4)
M = np.array([[0.4124, 0.3576, 0.1805],
[0.2126, 0.7152, 0.0722],
[0.0193, 0.1192, 0.9505]])
return(np.transpose(np.matmul(M, np.transpose(linear))))