-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorimetryDemo.m
156 lines (116 loc) · 4.04 KB
/
ColorimetryDemo.m
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
clc, clear, close all
% based on a stripped down version of:
%https://github.com/da5nsy/PTBColorimetryDemo/tree/5070c25dac1fef3342fa26546be440ebb2977133
d = DGdisplaydefaults;
% set(groot,'defaultfigureposition',[100 100 500 400]);
% set(groot,'defaultLineLineWidth',2);
% set(groot,'defaultAxesFontName', 'Courier');
% set(groot,'defaultAxesFontSize',12);
% set(groot,'defaultFigureRenderer', 'painters') %renders pdfs as vectors
% set(groot,'defaultfigurecolor','white')
%%
load spd_D65 % SPD: CIE D-series illuminant D65
load sur_macbeth % SRF: macbeth colour checker
load T_xyz1931 % CMF: 1931 2deg
%% Data
figure('Position',[100 100 500 700])
%figure
subplot(3,1,1)
plot(SToWls(S_D65),spd_D65)
xlim([380,730]),xticks([])
subplot(3,1,2)
plot(SToWls(S_macbeth),sur_macbeth)
xlim([380,730]),xticks([])
yticks(ylim)
subplot(3,1,3)
plot(SToWls(S_xyz1931),T_xyz1931)
xlim([380,730])
yticks(ylim)
xlabel('Wavelength (nm')
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\SPDetc.pdf')
%% Compute colour signals
colourSignal = sur_macbeth.*spd_D65;
%% CIE 1931 colorimetry
XYZ = T_xyz1931*colourSignal;
xy = [XYZ(1,:)./sum(XYZ);XYZ(2,:)./sum(XYZ)];
figure, hold on,
drawChromaticity('1931')
scatter(xy(1,:),xy(2,:),'k')
axis equal, axis([0 1 0 1])
xticks([0 1]), yticks([0 1])
xlabel('x'), ylabel('y')
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\ColorimetryDemo1.pdf')
%% u'v'
upvp = xyTouv(xy); %upvp is short for u prime v prime, because there is another colourspace called uv which is subtly different *sigh*
figure, hold on,
drawChromaticity('upvp')
axis equal
axis([0 1 0 1])
scatter(upvp(1,:),upvp(2,:),'k')
xticks([0 1]), yticks([0 1])
xlabel('u''') %to get an apostrophe you throw extra apostrophes at it until it behaves
ylabel('v''')
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\ColorimetryDemo3.pdf')
%% CIELUV
whiteXYZ = T_xyz1931*spd_D65;
Luv = XYZToLuv(XYZ,whiteXYZ);
figure,
scatter3(Luv(2,:),Luv(3,:),Luv(1,:),'k')
xlabel('u*')
ylabel('y*')
zlabel('L*')
xlim([-100 100])
ylim([-100 100])
zlim([0 100])
cleanTicks
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\ColorimetryDemo4.pdf')
%% MB
load T_cones_ss2.mat
load T_CIE_Y2.mat
%plot(SToWls(S_cones_ss2),T_cones_ss2)
T_c = SplineCmf(S_cones_ss2,T_cones_ss2,S_xyz1931); %resampling so that I can use the old sRGBs that I already calculated, and keep the appearance comparable accross diagrams
T_C = SplineCmf(S_CIE_Y2,T_CIE_Y2,S_xyz1931);
LMS = T_c*colourSignal;
ls = LMSToMacBoyn(LMS,T_c,T_C);
figure, hold on
drawChromaticity('MB2')
scatter(ls(1,:),ls(2,:),'k')
cleanTicks
xlabel('{\itl}_{MB}');
ylabel('{\its}_{MB}');
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\ColorimetryDemo5.pdf')
%% Illuminant dependence
% Granada daylight data
% Source:
% http://colorimaginglab.ugr.es/pages/Data#__doku_granada_daylight_spectral_database
% Cite:
% J. Hernández-Andrés, J. Romero& R.L. Lee, Jr., "Colorimetric and
% spectroradiometric characteristics of narrow-field-of-view
% clear skylight in Granada, Spain" (2001)
load('C:\Users\cege-user\Dropbox\UCL\Data\Reference Data\Granada Data\Granada_daylight_2600_161.mat');
T_SPD = final; clear final
T_SPD = T_SPD(17:97,1:20:end); %match sampling range and subsample across repeats
S_SPD = S_xyz1931;
for i=1:size(T_SPD,2)
T_rad(:,:,i) = sur_macbeth.*T_SPD(:,i);
XYZ(:,:,i) = T_xyz1931*T_rad(:,:,i);
end
XYZ = XYZ(:,:);
xy = [XYZ(1,:)./sum(XYZ);XYZ(2,:)./sum(XYZ)];
figure, hold on,
drawChromaticity('1931')
scatter(xy(1,:),xy(2,:),'k','MarkerEdgeAlpha',0.2)
axis equal, axis([0 1 0 1])
xticks([0 1]), yticks([0 1])
xlabel('x'), ylabel('y')
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\ColorimetryDemo6.pdf')
%% SPDs normalised to same luminance
lum = T_xyz1931(2,:)*T_SPD;
figure,
plot(SToWls(S_SPD),T_SPD./lum)
axis tight
xlabel('Wavelength (nm)')
ylabel('Relative power')
ylim([0 0.14])
yticks(ylim)
%save2pdf('C:\Users\cege-user\Dropbox\UCL\Ongoing Work\Thesis\figs\LitRev\ColorimetryDemo7.pdf')