{"id":355,"date":"2010-12-17T14:57:58","date_gmt":"2010-12-17T19:57:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/17\/what-color-is-green\/"},"modified":"2019-10-29T13:43:58","modified_gmt":"2019-10-29T17:43:58","slug":"what-color-is-green","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/17\/what-color-is-green\/","title":{"rendered":"What color is green?"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>\"Why do you have M&amp;Ms on your desk?\" my friend Nausheen wanted to know. Well, the truth is, for playing around with color\r\n      images, M&amp;Ms are simply irresistable.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">url = <span style=\"color: #A020F0\">'https:\/\/blogs.mathworks.com\/images\/steve\/2010\/mms.jpg'<\/span>;\r\nrgb = imread(url);\r\nimshow(rgb)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/green_mms_01.jpg\"> <p>I can think a few different things we could try with this image. First let's tackle the question, \"What color is green?\"<\/p>\r\n   <p>That is, can we quantify the color of the green M&amp;Ms? There are a couple of challenges. The first is that there is some variation\r\n      in lighting in this image from top to bottom. For example, suppose we pick two pixels from within the regions marked below:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">imshow(rgb)\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(212, 26, <span style=\"color: #A020F0\">'wo'<\/span>, <span style=\"color: #A020F0\">'MarkerSize'<\/span>, 12)\r\nplot(235, 378, <span style=\"color: #A020F0\">'wo'<\/span>, <span style=\"color: #A020F0\">'MarkerSize'<\/span>, 12)\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/green_mms_02.jpg\"> <p>Let's display an image containing two giant pixels, one chosen from the upper M&amp;M and the other chosen from the lower one.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">twopixels = [rgb(26,212,:), rgb(378,235,:)];\r\nimshow(twopixels, <span style=\"color: #A020F0\">'InitialMagnification'<\/span>, <span style=\"color: #A020F0\">'fit'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/green_mms_03.jpg\"> <p>You can see that's quite a difference in shade. But even within the same M&amp;M there's a lot of color variation.  Let's examine\r\n      two pixels on a single M&amp;M.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">imshow(rgb)\r\naxis([220 250 370 400])\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(228, 382, <span style=\"color: #A020F0\">'wo'<\/span>, <span style=\"color: #A020F0\">'MarkerSize'<\/span>, 12)\r\nplot(237, 389, <span style=\"color: #A020F0\">'wo'<\/span>, <span style=\"color: #A020F0\">'MarkerSize'<\/span>, 12)\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/green_mms_04.jpg\"> <pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">twopixels = [rgb(382,228,:), rgb(389,237,:)];\r\nimshow(twopixels, <span style=\"color: #A020F0\">'InitialMagnification'<\/span>, <span style=\"color: #A020F0\">'fit'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2010\/green_mms_05.jpg\"> <p>So where do we go from here? Well, next time I'll probably explore one or two other color spaces, and I also plan to show\r\n      you how to compute and display a two-dimensional histogram.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_a34ab54fe79144d68be6047732bf25dc() {\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='a34ab54fe79144d68be6047732bf25dc ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' a34ab54fe79144d68be6047732bf25dc';\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_a34ab54fe79144d68be6047732bf25dc()\"><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\na34ab54fe79144d68be6047732bf25dc ##### SOURCE BEGIN #####\r\n%%\r\n% \"Why do you have M&Ms on your desk?\" my friend Nausheen wanted to know.\r\n% Well, the truth is, for playing around with color images, M&Ms are\r\n% simply irresistable.\r\n\r\nurl = 'https:\/\/blogs.mathworks.com\/images\/steve\/2010\/mms.jpg';\r\nrgb = imread(url);\r\nimshow(rgb)\r\n\r\n%%\r\n% I can think a few different things we could try with this image. First\r\n% let's tackle the question, \"What color is green?\"\r\n%\r\n% That is, can we quantify the color of the green M&Ms? There are a couple\r\n% of challenges. The first is that there is some variation in lighting in\r\n% this image from top to bottom. For example, suppose we pick two pixels\r\n% from within the regions marked below:\r\n\r\nimshow(rgb)\r\nhold on\r\nplot(212, 26, 'wo', 'MarkerSize', 12)\r\nplot(235, 378, 'wo', 'MarkerSize', 12)\r\nhold off\r\n\r\n%%\r\n% Let's display an image containing two giant pixels, one chosen from the\r\n% upper M&M and the other chosen from the lower one.\r\n\r\ntwopixels = [rgb(26,212,:), rgb(378,235,:)];\r\nimshow(twopixels, 'InitialMagnification', 'fit')\r\n\r\n%%\r\n% You can see that's quite a difference in shade. But even within the same\r\n% M&M there's a lot of color variation.  Let's examine two pixels on a\r\n% single M&M.\r\n\r\nimshow(rgb)\r\naxis([220 250 370 400])\r\nhold on\r\nplot(228, 382, 'wo', 'MarkerSize', 12)\r\nplot(237, 389, 'wo', 'MarkerSize', 12)\r\nhold off\r\n\r\n%%\r\n\r\ntwopixels = [rgb(382,228,:), rgb(389,237,:)];\r\nimshow(twopixels, 'InitialMagnification', 'fit')\r\n\r\n%%\r\n% So where do we go from here? Well, next time I'll probably explore one or\r\n% two other color spaces, and I also plan to show you how to compute and\r\n% display a two-dimensional histogram.\r\n\r\n##### SOURCE END ##### a34ab54fe79144d68be6047732bf25dc\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \"Why do you have M&amp;Ms on your desk?\" my friend Nausheen wanted to know. Well, the truth is, for playing around with color\r\n      images, M&amp;Ms are simply irresistable.\r\n   url =... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2010\/12\/17\/what-color-is-green\/\">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":[50,90,76,36,68],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/355"}],"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=355"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/355\/revisions"}],"predecessor-version":[{"id":3709,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/355\/revisions\/3709"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}