用于上色或其他处理、分析需求。如:PS自定义渐变色。
clc;clear;
Color = jet(1000)*255;
Precision = 1e-3;
R = Color(:,1); G = Color(:,2); B = Color(:,3); % R、G、B
r = diff(diff(R)); g = diff(diff(G)); b = diff(diff(B));
Lr = r*0; Lg = Lr; Lb = Lr;
Lr(r>Precision) = 1; Lg(g>Precision) = 1; Lb(b>Precision) = 1;
Pr = find(Lr)+1; Pg = find(Lg)+1; Pb = find(Lb)+1;
P = sort(unique(cat(1,Pb,Pg,Pr)));
disp('位置( %) 16位颜色码')
disp(['00.00 ' Dec2Hex(R(1)) Dec2Hex(G(1)) Dec2Hex(B(1))])
for ii = 1:length(P)
p = P(ii);
Position = num2str(p/10,'%.2f');
disp([Position ' ' Dec2Hex(R(p)) Dec2Hex(G(p)) Dec2Hex(B(p))]);
end
disp(['100.00 ' Dec2Hex(R(1e3)) Dec2Hex(G(1e3)) Dec2Hex(B(1e3))])
function Hex = Dec2Hex(Dec)
Dec = round(Dec);
Hex = dec2hex(Dec);
if length(Hex) == 1
Hex = ['0' Hex];
end
end