-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduke.m
More file actions
39 lines (37 loc) · 1.08 KB
/
duke.m
File metadata and controls
39 lines (37 loc) · 1.08 KB
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
%Gray = 0.2989 * R + 0.5870 * G + 0.1140 * B
function map = Duke(N)
if ~exist('N','var')
N = size(get(gcf,'Colormap'),1);
end
colorList = [...
0 0 0;...
0 0 0.9;...
1 1 1];
map = genColorMap(colorList,N);
end
function map = genColorMap(colorList,N)
grayVals = rgb2gray(permute(colorList,[1 3 2]));
[sortGray, sortIdx] = sort(grayVals);
colorSort = colorList(sortIdx,:);
breakPoints = (sortGray-sortGray(1))/(sortGray(end)-sortGray(1));
brkpt0 = 0;
r0 = colorSort(1,1);
g0 = colorSort(1,2);
b0 = colorSort(1,3);
r = colorSort(end,1)*ones(N,1);
g = colorSort(end,2)*ones(N,1);
b = colorSort(end,3)*ones(N,1);
x = linspace(0,1,N)';
for i = 1:length(colorList)
brkpt = breakPoints(i);
idx = find(x>=brkpt0 & x<=brkpt);
r(idx) = r0+(colorSort(i,1)-r0)*(x(idx)-brkpt0)/(brkpt-brkpt0);
g(idx) = g0+(colorSort(i,2)-g0)*(x(idx)-brkpt0)/(brkpt-brkpt0);
b(idx) = b0+(colorSort(i,3)-b0)*(x(idx)-brkpt0)/(brkpt-brkpt0);
r0 = colorSort(i,1);
g0 = colorSort(i,2);
b0 = colorSort(i,3);
brkpt0 = brkpt;
end
map = [r g b];
end