-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorimetric_measures.py
79 lines (67 loc) · 2.93 KB
/
colorimetric_measures.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import colour
import numpy as np
from utils import spec2lab, XYZ2proLab
def computeDEfromSpectra(groundTruth, recovered, cmf,
wpSpec, typeDE="CIE2000"):
"""
Compute deltaE between the recovered and the
corresponding ground-truth image
Args:
:param groundTruth: ground truth reference image
numpy.ndarray (Height x Width x Spectral_Dimension)
:param recovered: image under evaluation.
numpy.ndarray (Height x Width x Spectral_Dimension)
:param cmf: color matching function.
numpy.ndarray (Spectral_Dimension x 3)
:param wpSpec: reference white (e.g. D65)
numpy.ndarray (Spectral_Dimension)
:param typeDE: deltaE version, can be a string
("CIE2000", "CIE1994", or"CIE1976"). Default: "CIE2000"
Returns:
deltaE between `recovered` and `groundTruth`
"""
assert groundTruth.shape == recovered.shape, \
"Size not match for groundtruth and recovered spectral images"
assert groundTruth.shape[2] == cmf.shape[0], \
"Spectral dimension and number of filter must match"
groundTruth = np.clip(groundTruth.astype("float64"), 0, 1)
recovered = np.clip(recovered.astype("float64"), 0, 1)
groundTruth = np.reshape(groundTruth, (-1, groundTruth.shape[2]))
recovered = np.reshape(recovered, (-1, recovered.shape[2]))
LABgt = spec2lab(groundTruth, cmf, wpSpec)
LABrc = spec2lab(recovered, cmf, wpSpec)
deltaE = np.mean(colour.delta_E(LABgt, LABrc, typeDE))
return deltaE
def computeProLabEucD(groundTruth, recovered, cmf):
"""
Compute Euclidean distance in ProLab color space
between the recovered and the corresponding ground-truth image
Args:
:param groundTruth: ground truth reference image.
numpy.ndarray (Height x Width x Spectral_Dimension)
:param recovered: image under evaluation.
numpy.ndarray (Height x Width x Spectral_Dimension)
:param cmf: color matching function.
numpy.ndarray (Spatial_Dimension x 3)
Returns:
Euclidean error in ProLab color space between `recovered`
and `groundTruth`
"""
assert groundTruth.shape == recovered.shape, \
"Size not match for groundtruth and recovered spectral images"
h, w, _ = groundTruth.shape
groundTruth = np.clip(groundTruth.astype("float64"), 0, 1)
recovered = np.clip(recovered.astype("float64"), 0, 1)
groundTruth = np.reshape(groundTruth, (-1, groundTruth.shape[2]))
recovered = np.reshape(recovered, (-1, recovered.shape[2]))
sumy = np.sum(cmf[:, 1])
XYZgt = groundTruth @ cmf
XYZgt /= sumy
XYZrec = recovered @ cmf
XYZrec /= sumy
proLabGT = XYZ2proLab(XYZgt)
proLabRC = XYZ2proLab(XYZrec)
l1, a1, b1 = np.split(proLabGT, 3, axis=1)
l2, a2, b2 = np.split(proLabRC, 3, axis=1)
dist = np.sqrt((l1 - l2)**2 + (a1 - a2)**2 + (b1 - b2)**2)
return np.mean(dist)