1mNAME0m colorconvert - convert a color to other color spaces, white points and RGB working spaces 1mSYNOPSIS0m # convert a color from RGB255 to other color spaces colorconvert -from 41,171,226 colorconvert -from rgb255,41,171,226 RGB255 41 171 226 RGBhex 29ABE2 RGB 0.161 0.671 0.886 XYZ 0.292 0.351 0.772 xyY 0.206 0.248 0.351 Lab 65.815 -15.265 -37.260 LCHab 65.815 40.266 -112.279 Luv 65.815 -42.283 -57.421 LCHuv 65.815 71.309 -126.367 HSL 197.838 0.761 0.524 HSV 197.838 0.819 0.886 CMY 0.839 0.329 0.114 CMYK 0.725 0.216 0 0.114 YCbCr 148.295 156.939 98.634 YPbPr 0.604 0.129 -0.131 YUV 0.604 0.113 -0.161 YIQ 0.604 -0.197 0.007 LMS 0.230 0.410 0.782 # convert a color from RGB255 to specific color spaces # (color space names are not case sensitive) colorconvert -from 41,171,226 -to rgbhex,lab RGBhex 29ABE2 Lab 65.815 -15.265 -37.260 # convert from Lab to RGB255 colorconvert -from lab,66,-15,-37 -to rgb255 RGB255 46 171 226 # unformatted multi-line output colorconvert -from 41,171,226 -to rgbhex,lab -raw RGBhex 29ABE2 Lab 65.815 -15.265 -37.260 # more precision colorconvert -from 41,171,226 -to lab -raw -precision 8 Lab 65.81523444 -15.26508019 -37.25990826 # single-line output with coordinates comma-delimited colorconvert -from rgb255,41,171,226 -oneline -csv RGB255 41,171,226 RGBhex 29ABE2 RGB 0.161,0.671,0.886 ... XYZ 0.292,0.351,0.772 xyY 0.206,0.248,0.351 ... Lab 65.815,-15.265,-37.260 LCHab 65.815,40.266,-112.279 ... Luv 65.815,-42.283,-57.421 LCHuv 65.815,71.309,-126.367 ... HSL 197.838,0.761,0.524 HSV 197.838,0.819,0.886 ... CMY 0.839,0.329,0.114 CMYK 0.725,0.216,0,0.114 ... YCbCr 148.295,156.939,98.634 YPbPr 0.604,0.129,-0.131 ... YUV 0.604,0.113,-0.161 YIQ 0.604,-0.197,0.007 LMS 0.230,0.410,0.782 # set color white point (default D65) colorconvert -from 41,171,226 -white_point D55 Lab 65.815 -16.012 -47.465 colorconvert -from 41,171,226 -white_point 8500K Lab 65.815 -15.332 -25.455 # get coordinate for the white point itself (use 'white' for color and -white_point # or more briefly the name of the white point itself as the color colorconvert -from white -white_point D55 colorconvert -from D55 colorconvert -from white -white_point 5500K colorconvert -from 5500K # convert between RGB working spaces (this works only for rgb, RGB255 and RGBhex) colorconvert -from 41,171,226 -to rgb,rgb255,rgbhex -from_rgbspace sRGB -to_rgbspace Adobe RGB 0.398 0.665 0.875 RGB255 102 170 223 RGBhex 66AADF colorconvert -from 41,171,226 -to rgb,RGB255,rgbhex -from_rgbspace sRGB -to_rgbspace ProPhoto RGB 0.477 0.589 0.961 RGB255 122 150 245 RGBhex 7A96F5 # convert RGB255 colors from a file (one R,G,B triplet per line, comma-delimited) colorconvert -from file.txt -to rgb255,rgbhex,lab,lch -oneline -csv # convert RGBhex colors from a file (one color per line, color coordinates comma delimited) colorconvert -from rgbhex,file.txt -to rgb255,rgbhex,lab,lch -oneline -csv # list all color spaces, RGB working spaces and white points colorconvert -list # manual colorconvert -man # usage colorconvert -h # debugging output colorconvert ... -debug # version colorconvert -v 1mDESCRIPTION0m Converts colors between color spaces. For details about how this is done see https://metacpan.org/pod/Graphics::ColorObject 1mOutput format0m The default output format is a multi-line pretty-formatted report. > colorconvert -from rgb255,41,171,226 -to hsv,lab,xyz hsv 197.838 0.819 0.886 lab 65.815 -15.265 -37.260 xyz 0.292 0.351 0.772 Controlling precision of coordinates with -precision > colorconvert -from rgb255,41,171,226 -to hsv,lab,xyz -precision 5 hsv 197.83784 0.81858 0.88627 lab 65.81523 -15.26508 -37.25991 xyz 0.29201 0.35086 0.77181 Unformatted output with -raw > colorconvert -from rgb255,41,171,226 -to hsv,lab,xyz -precision 5 -raw hsv 197.83784 0.81858 0.88627 lab 65.81523 -15.26508 -37.25991 xyz 0.29201 0.35086 0.77181 Comma-separated coordinates with -csv > colorconvert -from rgb255,41,171,226 -to hsv,lab,xyz -precision 5 -raw -csv hsv 197.83784,0.81858,0.88627 lab 65.81523,-15.26508,-37.25991 xyz 0.29201,0.35086,0.77181 Single line output with -oneline > colorconvert -from rgb255,41,171,226 -to hsv,lab,xyz -precision 5 -csv -oneline hsv 197.83784,0.81858,0.88627 lab 65.81523,-15.26508,-37.25991 xyz 0.29201,0.35086,0.77181 When using "-oneline" all spaces are collapsed with the same effect as "-raw". Colors from file You can process multiple colors at a time by reading them from a file. The file of colors must have the format COLOR_COORD {COLOR_NAME} where "COLOR_COORD" is a comma-separated color coordinate and "COLOR_NAME" is an optional color name, which can be any string. For example, # spectral.15.txt 158,1,66 213,62,79 215,25,28 244,109,67 or with names # spectral.15.txt 158,1,66 spectral-15-div-1 213,62,79 spectral-15-div-2 215,25,28 spectral-15-div-3 244,109,67 spectral-15-div-4 To specify that you want colors from a file, use the file name where you would normally put a color in the "-from" flag field. For example, colorconvert -from spectral.15.txt would read colors from spectral.15.txt and using default RGB255 space. colorconvert -from rgb255,spectral.15.txt It's probably most convenient to ask for single-line output when reading from a file. If the color has a name in the file, this will be the first string in the output line. If you use "-csv" any color coordinates will be reported as comma-delimited. colorconvert -from rgb255,spectral.15.txt -to rgb255,rgbhex -online -csv spectral-15-div-1 RGB255 158,1,66 RGBhex 9E0142 spectral-15-div-2 RGB255 213,62,79 RGBhex D53E4F spectral-15-div-3 RGB255 215,25,28 RGBhex D7191C spectral-15-div-4 RGB255 244,109,67 RGBhex F46D43 spectral-15-div-5 RGB255 252,141,89 RGBhex FC8D59 The colors in a file are assumed to be in the same color space. By default this is RGB255 but can be changed by using "-from SPACE,FILE". colorconvert -from lab,colorlist.lab.txt -to rgb255,rgbhex -online -csv 1mDefaults0m Default RGB working space is sRGB. Default white point is D65. 1mDebugging0m If you get an error in parsing input, run the script with "-debug" colorconvert ... -debug to see what's up. colorconvert -from rgb255,spectral.15.txt -to rgb255,rgbhex -online -csv -debug debug -from flag has two fields debug -from flag has color space rgb255 debug reading colors from spectral.15.txt debug got color 158 1 66 name spectral-15-div-1 debug got color 213 62 79 name spectral-15-div-2 debug got color 215 25 28 name spectral-15-div-3 ... debug white point D65 debug from color space rgb255 debug from RGB space sRGB debug to RGB space sRGB Input RGB hex coordinates, color spaces, white points and RGB spaces are not case sensitive. All of these are the same colorconvert -from rgbhex,ffaacc colorconvert -from RGBhex,FFAACC colorconvert -from RgbHex,FfAaCc colorconvert -from lch... -from_rgb adobe -to_rgb cie -white_point d75 colorconvert -from Lch... -from_rgb Adobe -to_rgb Cie -white_point D75 colorconvert -from LCH... -from_rgb ADOBE -to_rgb CIE -white_point D75 However, color space labels in the output are capitalized to their conventional form (LCH, LCHab, Lab, etc). Use "-list" to see them. All output coordinates are clipped to the gamut of the space, in as far as this is possible. See https://metacpan.org/pod/Graphics::ColorObject for details about clipping. 1mHISTORY0m 10 Feb 2021 Recompiled with newer Strawberry Perl. Fixed bug in Graphics::ColorObject::set_white_point() that was calling get_XYZ_white() without a hash key. 5 Jan 2019 All string input is case insensitive. Added "-list" flag. You can now set color space in Kelvin (4000-25000). You can now obtain the color of the white space using "-from white". colorconvert -from white -to rgb255 You can now get output on one line and as CSV. 19 Jul 2012 Switches to -rgb255 if -rgb is used with values > 1. 19 May 2010 First version. 1mURL0m http://mkweb.bcgsc.ca/color 1mAUTHOR0m Martin Krzywinski 1mCONTACT0m Martin Krzywinski Genome Sciences Center BC Cancer Research Center 100-570 W 7th Ave Vancouver BC V5Z 4S6 mkweb.bcgsc.ca martink@bcgsc.ca