{"id":1381,"date":"2015-08-11T07:00:59","date_gmt":"2015-08-11T11:00:59","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=1381"},"modified":"2019-11-01T11:44:56","modified_gmt":"2019-11-01T15:44:56","slug":"out-of-gamut-colors","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2015\/08\/11\/out-of-gamut-colors\/","title":{"rendered":"Out-of-gamut colors"},"content":{"rendered":"<div class=\"content\"><p>The set of colors that can be represented using a particular color space is called the <i>gamut<\/i>. Some L*a*b* color values may be <i>out of gamut<\/i> when converted to RGB. You know that a converted RGB color is out of gamut when any of its component values is less than 0 or greater than 1.<\/p><pre class=\"codeinput\">lab = [80 -130 85];\r\nlab2rgb(lab)\r\n<\/pre><pre class=\"codeoutput\">\r\nans =\r\n\r\n   -0.6210    0.9537   -0.1926\r\n\r\n<\/pre><p>The negative values demonstrate that the L*a*b* color [80 -130 85] is not in the gamut of the sRGB color space, which is the default RGB color space used by <tt>lab2rgb<\/tt>. A different RGB color space, Adobe RGB (1998), has a larger gamut than sRGB. Use the 'ColorSpace' parameter to convert a L*a*b* color to the Adobe color space.<\/p><pre class=\"codeinput\">lab2rgb(lab,<span class=\"string\">'ColorSpace'<\/span>,<span class=\"string\">'adobe-rgb-1998'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nans =\r\n\r\n    0.1234    0.9522    0.1073\r\n\r\n<\/pre><p>Because all the output values are between 0.0 and 1.0 (inclusive), you can conclude that the L*a*b* color [80 -130 85] is inside the Adobe RGB (1998) gamut.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_ecfb023e7d264cb6afc693ddcbbfe46d() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='ecfb023e7d264cb6afc693ddcbbfe46d ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ecfb023e7d264cb6afc693ddcbbfe46d';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2015 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_ecfb023e7d264cb6afc693ddcbbfe46d()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2015a<br><\/p><\/div><!--\r\necfb023e7d264cb6afc693ddcbbfe46d ##### SOURCE BEGIN #####\r\n%% \r\n% The set of colors that can be represented using a particular color\r\n% space is called the _gamut_. Some L*a*b* color values may be _out\r\n% of gamut_ when converted to RGB. You know that a converted RGB\r\n% color is out of gamut when any of its component values is less\r\n% than 0 or greater than 1.\r\n\r\nlab = [80 -130 85];\r\nlab2rgb(lab)\r\n\r\n%%\r\n% The negative values demonstrate that the L*a*b* color [80 -130 85]\r\n% is not in the gamut of the sRGB color space, which is the default\r\n% RGB color space used by |lab2rgb|. A different RGB color space,\r\n% Adobe RGB (1998), has a larger gamut than sRGB. Use the\r\n% 'ColorSpace' parameter to convert a L*a*b* color to the\r\n% Adobe color space.\r\n\r\nlab2rgb(lab,'ColorSpace','adobe-rgb-1998')\r\n\r\n%%\r\n% Because all the output values are between 0.0 and 1.0 (inclusive),\r\n% you can conclude that the L*a*b* color [80 -130 85] is inside the\r\n% Adobe RGB (1998) gamut.\r\n##### SOURCE END ##### ecfb023e7d264cb6afc693ddcbbfe46d\r\n-->","protected":false},"excerpt":{"rendered":"<p>The set of colors that can be represented using a particular color space is called the gamut. Some L*a*b* color values may be out of gamut when converted to RGB. You know that a converted RGB color... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2015\/08\/11\/out-of-gamut-colors\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[1115],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1381"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=1381"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1381\/revisions"}],"predecessor-version":[{"id":1384,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1381\/revisions\/1384"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=1381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=1381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=1381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}