{"id":6281,"date":"2015-11-27T09:00:25","date_gmt":"2015-11-27T14:00:25","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=6281"},"modified":"2015-11-25T16:55:59","modified_gmt":"2015-11-25T21:55:59","slug":"nfl-colors","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2015\/11\/27\/nfl-colors\/","title":{"rendered":"NFL Colors"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/16280-nflcolor\">nflcolor<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3324\">Alan Bindemann<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n\r\n   <p>Let's take this plain old boring football and turn it into one with some team colors:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">football = imread(<span style=\"color: #A020F0\">'football.jpg'<\/span>);\r\nimshow(football);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/mainnfl_01.png\"> <p>Segment the football using color thresholder in the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2015b\/images\/index.html\">Image Processing Toolbox<\/a> to identify it and then generate a masking function:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">colorThresholder(football)<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/colorthresholdr.png\"> <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">footballmask = createFootballMask(football);<\/pre><p>And remove the noise using the image region analyzer to remove small areas.  You could use <tt>bwareaopen<\/tt> for this, but the app allows for filtering based on many more properties with different boolean logic.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">imageRegionAnalyzer(M)<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/regionanalyzer.png\"> <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">footballmask = imfill(filterSmallRegions(footballmask),<span style=\"color: #A020F0\">'holes'<\/span>);<\/pre><p>Now let's color it based on my favorite team using Alan's <tt>nflcolor<\/tt>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% Patriots colors from nflcolor<\/span>\r\npatriots = [nflcolor(<span style=\"color: #A020F0\">'patriots'<\/span>); nflcolor(<span style=\"color: #A020F0\">'patriots'<\/span>,<span style=\"color: #A020F0\">'name'<\/span>)];\r\n\r\n<span style=\"color: #228B22\">% Indices into colormap offset for zero<\/span>\r\nind = rgb2ind(football,patriots)+1;\r\nind(~footballmask) = 0;\r\n\r\n<span style=\"color: #228B22\">% Show it!<\/span>\r\nimshow(ind,[0 0 0; patriots])<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/mainnfl_02.png\"> <p>Alan's function is a nice utility for grabbing any team's primary and name colors.  It's well-written and it taught me how\r\n      to use MATLAB to take a HEX color code and convert it into an RGB color.\r\n   <\/p>\r\n   <p>In the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/16280-nflcolor#comments\">comments<\/a>, John mentioned that the Giants being shadowed by the Jets when querying <i>'New York'<\/i> is a bug.  As a fix, I would probably argue that it should just error for New York fans.  Of course that would limit it's\r\n      ability for people like me to show fun plots, like this one!\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% Information as of Wednesday, November 25th 2015.  I don't have to worry,<\/span>\r\n<span style=\"color: #228B22\">% the Jets and Giants aren't playing on Thanksgiving so their records can't<\/span>\r\n<span style=\"color: #228B22\">% get worse before this goes live on Friday, November 27th.<\/span>\r\nrec = [5 5; 5 5; 10 0];\r\nteam = {<span style=\"color: #A020F0\">'Jets'<\/span>, <span style=\"color: #A020F0\">'Giants'<\/span>, <span style=\"color: #A020F0\">'Patriots'<\/span>};\r\n\r\n<span style=\"color: #0000FF\">for<\/span> ii = 1:3\r\n    colormap([nflcolor(team{ii},<span style=\"color: #A020F0\">'name'<\/span>); nflcolor(team{ii})])\r\n    pie(rec(ii,:), {sprintf(<span style=\"color: #A020F0\">'%s\\nWon'<\/span>,team{ii}),sprintf(<span style=\"color: #A020F0\">'%s\\nLost'<\/span>, team{ii})})\r\n    snapnow\r\n<span style=\"color: #0000FF\">end<\/span><\/pre><pre style=\"font-style:oblique\">Warning: Ignoring non-positive data in pie chart. \r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/mainnfl_03.png\"> <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/mainnfl_04.png\"> <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/mainnfl_05.png\"> <p>Interesting warning, apparently pie charts don't like winners.<\/p>\r\n   <h3>Comments<a name=\"7\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=6281#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/16280-nflcolor#comments\">comment<\/a> for Alan.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_bd1aa995bdf24a499eb4d3d1d2df4357() {\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='bd1aa995bdf24a499eb4d3d1d2df4357 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' bd1aa995bdf24a499eb4d3d1d2df4357';\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 = 'Sean de Wolski';\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 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_bd1aa995bdf24a499eb4d3d1d2df4357()\"><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; R2015b<br><\/p>\r\n<\/div>\r\n<!--\r\nbd1aa995bdf24a499eb4d3d1d2df4357 ##### SOURCE BEGIN #####\r\n%% NFL Colors\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/16280-nflcolor nflcolor> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3324 Alan Bindemann>.\r\n% \r\n\r\n%%\r\n% Let's take this plain old boring football and turn it into one with some\r\n% team colors:\r\n\r\nfootball = imread('football.jpg');\r\nimshow(football);\r\n\r\n%%\r\n% Segment the football using color thresholder in the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2015b\/images\/index.html Image\r\n% Processing Toolbox> to identify it and then generate a masking\r\n% function:\r\n%\r\n%   colorThresholder(football)\r\n%\r\n% <<colorthresholdr.png>>\r\n\r\nfootballmask = createFootballMask(football);\r\n\r\n%%\r\n% And remove the noise using the image region analyzer to remove small\r\n% areas.  You could use |bwareaopen| for this, but the app allows for\r\n% filtering based on many more properties with different boolean logic.\r\n%\r\n%   imageRegionAnalyzer(M)\r\n%\r\n% <<regionanalyzer.png>>\r\n\r\nfootballmask = imfill(filterSmallRegions(footballmask),'holes');\r\n\r\n%%\r\n% Now let's color it based on my favorite team using Alan's |nflcolor|.\r\n\r\n% Patriots colors from nflcolor\r\npatriots = [nflcolor('patriots'); nflcolor('patriots','name')];\r\n\r\n% Indices into colormap offset for zero\r\nind = rgb2ind(football,patriots)+1;\r\nind(~footballmask) = 0;\r\n\r\n% Show it!\r\nimshow(ind,[0 0 0; patriots])\r\n\r\n\r\n%% \r\n% Alan's function is a nice utility for grabbing any team's primary and\r\n% name colors.  It's well-written and it taught me how to use MATLAB to\r\n% take a HEX color code and convert it into an RGB color.\r\n%\r\n% In the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/16280-nflcolor#comments\r\n% comments>, John mentioned that the Giants being shadowed by the Jets when\r\n% querying _'New York'_ is a bug.  As a fix, I would probably argue that it\r\n% should just error for New York fans.  Of course that would limit it's\r\n% ability for people like me to show fun plots, like this one!\r\n\r\n% Information as of Wednesday, November 25th 2015.  I don't have to worry,\r\n% the Jets and Giants aren't playing on Thanksgiving so their records can't\r\n% get worse before this goes live on Friday, November 27th.\r\nrec = [5 5; 5 5; 10 0];\r\nteam = {'Jets', 'Giants', 'Patriots'};\r\n\r\nfor ii = 1:3\r\n    colormap([nflcolor(team{ii},'name'); nflcolor(team{ii})])\r\n    pie(rec(ii,:), {sprintf('%s\\nWon',team{ii}),sprintf('%s\\nLost', team{ii})})\r\n    snapnow\r\nend\r\n\r\n%%\r\n% Interesting warning, apparently pie charts don't like winners.\r\n\r\n\r\n%% Comments\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=6281#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/16280-nflcolor#comments\r\n% comment> for Alan.\r\n%\r\n \r\n\r\n##### SOURCE END ##### bd1aa995bdf24a499eb4d3d1d2df4357\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainnfl\/mainnfl_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is nflcolor by Alan Bindemann.\r\n      \r\n   \r\n\r\n   Let's take this plain old boring football and turn it into one with some team colors:football =... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2015\/11\/27\/nfl-colors\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6281"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=6281"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6281\/revisions"}],"predecessor-version":[{"id":6283,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6281\/revisions\/6283"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=6281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=6281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=6281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}