%
% im2bw2 
%
% Since the im2bw command is not available on some versions,
% this can be used in its place.
% -Michael Weeks, October 2016
%
% Usage:
%   x = im2bw2(y);

function x = im2bw2(y)

% First, we need to get the input image in RBG components.
R = double(y(:,:,1));
G = double(y(:,:,2));
B = double(y(:,:,3));

% Find the average
AVG = (R + G + B)/3;

% return a logical image whenever the average exceeds the middle.
x = (AVG > 127);


