Created
June 8, 2015 12:28
-
-
Save jnkather/30f06c544a3dcb4e7388 to your computer and use it in GitHub Desktop.
Sort a Hex color vector by hue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% JN Kather 2015 | |
% sorts a vector of hex colors by hue | |
% dependencies: needs functions rgb2hex and hex2rgb | |
dataDir = 'input/data/'; | |
% read color vector | |
colorList = readtable(strcat(dataDir,'/custom_color_list3.txt'),... | |
'ReadVariableNames',false); | |
% preallocate | |
colors_HSV = zeros(numel(colorList),3); | |
% convert to HSV | |
for i=1:numel(colorList) | |
colors_HSV(i,:) = rgb2hsv(hex2rgb(char(colorList.Var1(i)))); | |
end | |
% sort by hue | |
colors_HSV = sort(colors_HSV,1); | |
% convert back to Hex RGB | |
for i=1:numel(colorList) | |
colorsListOut(i) = cellstr(rgb2hex(hsv2rgb(colors_HSV(i,:)))); | |
end | |
disp(colorsListOut'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment