Read color value from custom chart

2 ビュー (過去 30 日間)
Beycan Ibrahimoglu
Beycan Ibrahimoglu 2022 年 3 月 22 日
編集済み: DGM 2022 年 3 月 22 日
Hello,
I have custom color chart, as in the picture.
I have rgb color codes for each color.
I would like to read numerical value of new color from this scale.
Thanks in advance for helps.
Best Regards,
Ben

回答 (1 件)

DGM
DGM 2022 年 3 月 22 日
編集済み: DGM 2022 年 3 月 22 日
I'm sure there are better ways, but this is what I rolled with off the top of my head.
% the information from the swatch chart
CT = [1 1 1;
0.9451 0.7922 0.8392;
0.851 0.5333 0.6588;
0.8392 0.4588 0.6078;
0.7608 0.3451 0.5451;
0.5686 0.2392 0.4314];
key = [0 25 50 100 250 500]';
imshow(permute(CT,[3 1 2])) % show the chart colors
% pretend these are our sample colors to look up
samples = [0.8451 0.4960 0.6333;
0.8039 0.4078 0.5765;
0.6471 0.2824 0.4824;
0.6745 0.5098 0.6627];
imshow(permute(samples,[3 1 2])) % show the sample colors
% ignore samples which are not within the same hue range
samphue = rgb2hsv(samples);
samphue = samphue(:,1);
goodcolors = (samphue >= 0.89 & samphue <= 0.96) | samphue == 0;
samples = samples(goodcolors,:);
% find color distances
CTlab = permute(rgb2lab(CT),[1 3 2]);
samplab = permute(rgb2lab(samples),[3 1 2]);
DE = sqrt(sum((CTlab-samplab).^2,3)); % one column per sample
% find sample value by linear interpolation between nearest colors
sampvalue = zeros(size(samples,1),1);
for k = 1:size(samples,1)
[~,idx] = mink(DE(:,k),2);
idx = sort(idx);
sampvalue(k) = key(idx(1)) + range(key(idx))*DE(idx(1),k)/sum(DE(idx,k));
end
sampvalue
sampvalue = 3×1
75.2198 165.6172 396.7581
Note that some cursory attempt is made to reject colors which aren't on the same trajectory. Also, it's assumed that any sample colors extracted from photographic sources came from photographs taken under conditions (illumination and camera settings) comparable to those which the chart represents.

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by