{"id":3346,"date":"2019-07-08T07:00:04","date_gmt":"2019-07-08T11:00:04","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=3346"},"modified":"2019-11-01T22:44:51","modified_gmt":"2019-11-02T02:44:51","slug":"color-correction-with-a-parula-quilt","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2019\/07\/08\/color-correction-with-a-parula-quilt\/","title":{"rendered":"Color correction with a parula quilt"},"content":{"rendered":"<div class=\"content\"><p>My wife, Geri Eddins, has been making a lot of quilts lately. A few months ago, I printed out these 10 colors, showed them to her, and asked, \"Can you make a wall hanging quilt with this color scheme? And make it look kind of mathematical?\" (Whatever that means!)<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/parula-colors-10.png\" alt=\"\"> <\/p><p>These are ten of the colors from the default MATLAB colormap, called parula. I've posted about this colormap <a href=\"https:\/\/blogs.mathworks.com\/steve\/category\/colormap\/?s_tid=Blog_steve_Category\">several times<\/a>.<\/p><p>So, we looked at some pattern books and found something that seemed promising. She took the color samples and bought some matching fabrics, and then she did her sewing magic. Pretty soon, she had finished two wall hangings! I hung one up at home and one at my MathWorks office. Here is the final result:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/parula-quilt-corrected.jpg\" alt=\"\"> <\/p><p>I took this picture in my office, using my phone's camera, and lit with sunlight filtered through office windows. But the picture above isn't the first thing I saw after taking the picture. Instead, this is what I got:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/parula-quilt-original.jpg\" alt=\"\"> <\/p><p>That's quite a difference! The yellows are almost completely gone. I can only guess that the way I framed the picture really fooled the phone camera's automatic white balancing algorithm.<\/p><p>After puzzling over what to do with that picture, I remembered about a new-ish (R2017b) color balancing function in the Image Processing Toolbox called <tt>chromadapt<\/tt>.<\/p><p>The simplest way to use this function is with the call:<\/p><pre class=\"language-matlab\">out = chromadapt(in,illuminant)\r\n<\/pre><p>where <tt>illuminant<\/tt> is chosen as a pixel color from the input that <b>should<\/b> be gray or white, but isn't. Notice that, in this wall hanging, Geri has conveniently provided a white region: the background of the rectangular label at the bottom.<\/p><p>I used <tt>impixelinfo<\/tt> to grab a pixel color ([143 170 241]\/255) from this region. Then I processed the original image as follows:<\/p><pre class=\"language-matlab\">corrected = chromadapt(original,[143 170 241]\/255);\r\n<\/pre><p>The resulting image is the first one displayed above, the one with the clearly visible yellow hues.<\/p><p>Enjoy.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_fa04fe4070f0411183ef8d0ffb1818b5() {\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='fa04fe4070f0411183ef8d0ffb1818b5 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' fa04fe4070f0411183ef8d0ffb1818b5';\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 2019 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_fa04fe4070f0411183ef8d0ffb1818b5()\"><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; R2019a<br><\/p><\/div><!--\r\nfa04fe4070f0411183ef8d0ffb1818b5 ##### SOURCE BEGIN #####\r\n%% Color correction with a parula quilt\r\n% My wife, Geri Eddins, has been making a lot of quilts lately. A few\r\n% months ago, I printed out these 10 colors, showed them to her, and\r\n% ask, \"Can you make a wall hanging quilt with this color scheme? And\r\n% make it look kind of mathematical?\" (Whatever that means!)\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/parula-colors-10.png>>\r\n%\r\n% These are ten of the colors from the default MATLAB colormap, called\r\n% parula. I've posted about this colormap\r\n% <https:\/\/blogs.mathworks.com\/steve\/category\/colormap\/?s_tid=Blog_steve_Category\r\n% several times>.\r\n%\r\n% So, we looked at some pattern books and found something that seemed\r\n% promising. She took the color samples and bought some matching\r\n% fabrics, and then she did her sewing magic. Pretty soon, she had\r\n% finished two wall hangings! I hung one up at home and one at my\r\n% MathWorks office. Here is the final result:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/parula-quilt-corrected.jpg>>\r\n%\r\n% I took this picture in my office, using my phone's camera, and lit\r\n% with sunlight filtered through office windows. But the picture above\r\n% isn't the first thing I saw after taking the picture. Instead, this is\r\n% what I got:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/parula-quilt-original.jpg>>\r\n%\r\n% That's quite a difference! The yellows are almost completely gone. I\r\n% can only guess that the way I framed the picture really fooled the\r\n% phone camera's automatic white balancing algorithm.\r\n%\r\n% After puzzling over what to do with that picture, I remembered about a\r\n% new-ish (R2017b) color balancing function in the Image Processing\r\n% Toolbox called |chromadapt|.\r\n%\r\n% The simplest way to use this function is with the call:\r\n%\r\n%   out = chromadapt(in,illuminant)\r\n%\r\n% where |illuminant| is chosen as a pixel color from the input that\r\n% *should* be gray or white, but isn't. Notice that, in this wall\r\n% hanging, Geri has conveniently provided a white region: the background\r\n% of the rectangular label at the bottom.\r\n%\r\n% I used |impixelinfo| to grab a pixel color ([143 170 241]\/255) from\r\n% this region. Then I processed the original image as follows:\r\n%\r\n%   corrected = chromadapt(original,[143 170 241]\/255);\r\n%\r\n% The resulting image is the first one displayed above, the one with the\r\n% clearly visible yellow hues.\r\n%\r\n% Enjoy.\r\n##### SOURCE END ##### fa04fe4070f0411183ef8d0ffb1818b5\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/steve\/files\/parula-quilt-corrected.jpg\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>My wife, Geri Eddins, has been making a lot of quilts lately. A few months ago, I printed out these 10 colors, showed them to her, and asked, \"Can you make a wall hanging quilt with this color... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2019\/07\/08\/color-correction-with-a-parula-quilt\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":3342,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[1253],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3346"}],"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=3346"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3346\/revisions"}],"predecessor-version":[{"id":3350,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3346\/revisions\/3350"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media\/3342"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=3346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=3346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=3346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}