File Exchange Pick of the Week

Our best user submissions

NFL Colors

Sean's pick this week is nflcolor by Alan Bindemann.

Let's take this plain old boring football and turn it into one with some team colors:

football = imread('football.jpg');
imshow(football);

Segment the football using color thresholder in the Image Processing Toolbox to identify it and then generate a masking function:

colorThresholder(football)

footballmask = createFootballMask(football);

And remove the noise using the image region analyzer to remove small areas. You could use bwareaopen for this, but the app allows for filtering based on many more properties with different boolean logic.

imageRegionAnalyzer(M)

footballmask = imfill(filterSmallRegions(footballmask),'holes');

Now let's color it based on my favorite team using Alan's nflcolor.

% Patriots colors from nflcolor
patriots = [nflcolor('patriots'); nflcolor('patriots','name')];

% Indices into colormap offset for zero
ind = rgb2ind(football,patriots)+1;
ind(~footballmask) = 0;

% Show it!
imshow(ind,[0 0 0; patriots])

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 to use MATLAB to take a HEX color code and convert it into an RGB color.

In the comments, John mentioned that the Giants being shadowed by the Jets when querying 'New York' 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 ability for people like me to show fun plots, like this one!

% Information as of Wednesday, November 25th 2015.  I don't have to worry,
% the Jets and Giants aren't playing on Thanksgiving so their records can't
% get worse before this goes live on Friday, November 27th.
rec = [5 5; 5 5; 10 0];
team = {'Jets', 'Giants', 'Patriots'};

for ii = 1:3
    colormap([nflcolor(team{ii},'name'); nflcolor(team{ii})])
    pie(rec(ii,:), {sprintf('%s\nWon',team{ii}),sprintf('%s\nLost', team{ii})})
    snapnow
end
Warning: Ignoring non-positive data in pie chart. 

Interesting warning, apparently pie charts don't like winners.

Comments

Give it a try and let us know what you think here or leave a comment for Alan.




Published with MATLAB® R2015b

|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.