{"id":357,"date":"2010-12-30T15:34:54","date_gmt":"2010-12-30T20:34:54","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/30\/a-and-b\/"},"modified":"2021-04-27T17:11:05","modified_gmt":"2021-04-27T21:11:05","slug":"a-and-b","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/30\/a-and-b\/","title":{"rendered":"a* and b*"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n<p><em><strong>Note added 27-Apr-2021:<\/strong> See the updated discussion of this topic in the <a href=\"https:\/\/blogs.mathworks.com\/steve\/2021\/04\/27\/plotting-a-and-b-colors\/\">27-Apr-2021 post, \"Plotting a* and b* colors.\"<\/a><\/em><\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/23\/two-dimensional-histograms\/\">Last week<\/a> I showed how to compute a two-dimensional histogram. Specifically, I computed the two-dimensional histogram of the a*-b*\r\n      values of this image:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/mms.jpg\"> <\/p>\r\n   <p>This was the result:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/two_dim_histogram_05.jpg\"> <\/p>\r\n   <p>Blog reader Vanessa naturally <a href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/23\/two-dimensional-histograms\/#comment-23808\">wanted to know<\/a> what this all means. (And blog reader Cmac gave a <a href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/23\/two-dimensional-histograms\/#comment-23818\">pretty good answer<\/a>.)\r\n   <\/p>\r\n   <p>Let me elaborate a bit. By L*a*b* I refer to the CIE 1976 L*, a*, b* color space. Here's a description of the three dimensions\r\n      (from the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Lab_color_space\">Wikipedia article<\/a>):\r\n   <\/p>\r\n   <p>\"The three coordinates of CIELAB represent the lightness of the color (L* = 0 yields black and L* = 100 indicates diffuse\r\n      white; specular white may be higher), its position between red\/magenta and green (a*, negative values indicate green while\r\n      positive values indicate magenta) and its position between yellow and blue (b*, negative values indicate blue and positive\r\n      values indicate yellow). The asterisk after L, a and b are part of the full name, since they represent L*, a* and b*, to distinguish\r\n      them from Hunter's L, a and b, [an earlier color space].\"\r\n   <\/p>\r\n   <p>Bright spots in the two-dimensional histogram indicate that a relatively large number of pixels in the original image have\r\n      the corresponding a* and b* values.\r\n   <\/p>\r\n   <p>Consider, for example, the lowest bright spot on the two-dimensional histogram. By using <tt>impixelinfo<\/tt> and my mouse I was able to see that the a* and b* values for this spot are about -12 and 85. What color is that? To convert\r\n      back to RGB values that we can display I have to pick some value for L*, whose natural range is 0 to 100. I'll pick 90, a\r\n      fairly bright value. Then I use <tt>applycform<\/tt> to convert from L*a*b* to sRGB.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">lab = [90 -12 85];\r\nrgb = applycform(lab, makecform(<span style=\"color: #A020F0\">'lab2srgb'<\/span>))<\/pre><pre style=\"font-style:oblique\">\r\nrgb =\r\n\r\n    0.9297    0.9066    0.0971\r\n\r\n<\/pre><p>How can we look at this color? There are a lot of different ways. One procedure is to display a 1-by-1 indexed image with\r\n      a one-color colormap.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">image(1)\r\ncolormap(rgb)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/ab_colors_01.jpg\"> <p>Looks like we found yellow! How about some of the other colors? The left-most bright spot is at about (-68,70). The right-most\r\n      spot is at about (60,70), and the top-most spot is at about (-4,-47).\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">lab = [90 -68 70; 90 60 70; 90 -4 -47];\r\nrgb = applycform(lab, makecform(<span style=\"color: #A020F0\">'lab2srgb'<\/span>))<\/pre><pre style=\"font-style:oblique\">\r\nrgb =\r\n\r\n    0.3737    1.0000    0.2844\r\n    1.0000    0.6832    0.3652\r\n    0.6637    0.9077    1.0000\r\n\r\n<\/pre><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">image([1 2 3])\r\ncolormap(rgb)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/ab_colors_02.jpg\"> <p>The two colors on the right don't look that much like any of our M&amp;Ms. Maybe I guessed wrong about L*.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">lab(:,1) = 50<\/pre><pre style=\"font-style:oblique\">\r\nlab =\r\n\r\n    50   -68    70\r\n    50    60    70\r\n    50    -4   -47\r\n\r\n<\/pre><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">rgb = applycform(lab, makecform(<span style=\"color: #A020F0\">'lab2srgb'<\/span>));\r\nimage([1 2 3])\r\ncolormap(rgb)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/ab_colors_03.jpg\"> <p>That's better. We found our green, red, and blue M&amp;M colors.<\/p>\r\n\r\n<p><em><strong>Note added 27-Apr-2021:<\/strong> The following explanation fails to note that many of the colors in the a*-b* plane are actually out of gamut. See the updated discussion of this topic in the <a href=\"https:\/\/blogs.mathworks.com\/steve\/2021\/04\/27\/plotting-a-and-b-colors\/\">27-Apr-2021 post, \"Plotting a* and b* colors.\"<\/a><\/em><\/p>\r\n\r\n   <p>Here's a crude way to visualize all the colors of the a*-b* plane. We make an \"image\" containing L*a*b* values and then convert\r\n      the whole thing to RGB.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[a,b] = meshgrid(-100:100);\r\nL = 90*ones(size(a));\r\nlab = cat(3, L, a, b);\r\nrgb = applycform(lab, makecform(<span style=\"color: #A020F0\">'lab2srgb'<\/span>));\r\nimshow(rgb, <span style=\"color: #A020F0\">'XData'<\/span>,[-100 100], <span style=\"color: #A020F0\">'YData'<\/span>, [-100 100])\r\nxlabel(<span style=\"color: #A020F0\">'a*'<\/span>)\r\nylabel(<span style=\"color: #A020F0\">'b*'<\/span>)\r\naxis <span style=\"color: #A020F0\">on<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/ab_colors_04.jpg\"> <p>I will continue for a while longer to use this image as an excuse for a pseudorandom walk through some image processing computational\r\n      and visualization techniques.  We've looked at color-space conversion, two-dimensional histograms, and ways to show individual\r\n      color patches.\r\n   <\/p>\r\n   <p>I think that next time I'll start to look at segmentation based on color.<\/p>\r\n   <p>In the meantime, Happy New Year everyone!<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_6ed472ea2fab4e1e8f90978d073c8a78() {\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='6ed472ea2fab4e1e8f90978d073c8a78 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 6ed472ea2fab4e1e8f90978d073c8a78';\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        author = 'Steve Eddins';\r\n        copyright = 'Copyright 2010 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 author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\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      \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_6ed472ea2fab4e1e8f90978d073c8a78()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.11<br><\/p>\r\n<\/div>\r\n<!--\r\n6ed472ea2fab4e1e8f90978d073c8a78 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/steve\/2010\/12\/23\/two-dimensional-histograms\/\r\n% Last week> I showed how to compute a two-dimensional histogram.\r\n% Specifically, I computed the two-dimensional histogram of the a*-b*\r\n% values of this image:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/mms.jpg>>\r\n%\r\n% This was the result:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2010\/two_dim_histogram_05.jpg>>\r\n%\r\n% Blog reader Vanessa naturally\r\n% <https:\/\/blogs.mathworks.com\/steve\/2010\/12\/23\/two-dimensional-histograms\/#comment-23808\r\n% wanted to know> what this all means. (And blog reader Cmac gave a\r\n% <https:\/\/blogs.mathworks.com\/steve\/2010\/12\/23\/two-dimensional-histograms\/#comment-23818\r\n% pretty good answer>.)\r\n%\r\n% Let me elaborate a bit. By L*a*b* I refer to the CIE 1976 L*, a*, b*\r\n% color space. Here's a description of the three dimensions (from the\r\n% <http:\/\/en.wikipedia.org\/wiki\/Lab_color_space Wikipedia article>):\r\n%\r\n% \"The three coordinates of CIELAB represent the lightness of the color (L*\r\n% = 0 yields black and L* = 100 indicates diffuse white; specular white may\r\n% be higher), its position between red\/magenta and green (a*, negative\r\n% values indicate green while positive values indicate magenta) and its\r\n% position between yellow and blue (b*, negative values indicate blue and\r\n% positive values indicate yellow). The asterisk after L, a and b are\r\n% part of the full name, since they represent L*, a* and b*, to distinguish\r\n% them from Hunter's L, a and b, [an earlier color space].\"\r\n%\r\n% Bright spots in the two-dimensional histogram indicate that a relatively\r\n% large number of pixels in the original image have the corresponding a*\r\n% and b* values.\r\n%\r\n% Consider, for example, the lowest bright spot on the two-dimensional\r\n% histogram. By using |impixelinfo| and my mouse I was able to see that the\r\n% a* and b* values for this spot are about -12 and 85. What color is that?\r\n% To convert back to RGB values that we can display I have to pick some\r\n% value for L*, whose natural range is 0 to 100. I'll pick 90, a fairly bright\r\n% value. Then I use |applycform| to convert from L*a*b* to sRGB.\r\n\r\nlab = [90 -12 85];\r\nrgb = applycform(lab, makecform('lab2srgb'))\r\n\r\n%%\r\n% How can we look at this color? There are a lot of different ways. One\r\n% procedure is to display a 1-by-1 indexed image with a one-color colormap.\r\n\r\nimage(1)\r\ncolormap(rgb)\r\n\r\n%%\r\n% Looks like we found yellow! How about some of the other colors? The left-most \r\n% bright spot is at about (-68,70). The right-most spot is at about\r\n% (60,70), and the top-most spot is at about (-4,-47).\r\n\r\nlab = [90 -68 70; 90 60 70; 90 -4 -47];\r\nrgb = applycform(lab, makecform('lab2srgb'))\r\n\r\n%%\r\nimage([1 2 3])\r\ncolormap(rgb)\r\n\r\n%%\r\n% The two colors on the right don't look that much like any of our M&Ms.\r\n% Maybe I guessed wrong about L*.\r\n\r\nlab(:,1) = 50\r\n\r\n%%\r\nrgb = applycform(lab, makecform('lab2srgb'));\r\nimage([1 2 3])\r\ncolormap(rgb)\r\n\r\n%%\r\n% That's better. We found our green, red, and blue M&M colors.\r\n%\r\n% Here's a crude way to visualize all the colors of the a*-b* plane. We make an\r\n% \"image\" containing L*a*b* values and then convert the whole thing to RGB.\r\n\r\n[a,b] = meshgrid(-100:100);\r\nL = 90*ones(size(a));\r\nlab = cat(3, L, a, b);\r\nrgb = applycform(lab, makecform('lab2srgb'));\r\nimshow(rgb, 'XData',[-100 100], 'YData', [-100 100])\r\nxlabel('a*')\r\nylabel('b*')\r\naxis on\r\n\r\n%%\r\n% I will continue for a while longer to use this image as an excuse for a\r\n% pseudorandom walk through some image processing computational and\r\n% visualization techniques.  We've looked at color-space conversion,\r\n% two-dimensional histograms, and ways to show individual color patches.\r\n%\r\n% I think that next time I'll start to look at segmentation based on color.\r\n%\r\n% In the meantime, Happy New Year everyone!\r\n##### SOURCE END ##### 6ed472ea2fab4e1e8f90978d073c8a78\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\nNote added 27-Apr-2021: See the updated discussion of this topic in the 27-Apr-2021 post, \"Plotting a* and b* colors.\"\r\n   Last week I showed how to compute a two-dimensional histogram.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/30\/a-and-b\/\">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":[114,50,46,58,48,112,30,288,190,94,96],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/357"}],"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=357"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":4448,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/357\/revisions\/4448"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}