function [ output_args ] = hue ( filename )

clearvars -except filename;

a = imread(filename);

imSize = size(a);

redColor = a;
greenColor = a;
blueColor = a;
redColor(:,:,2) = 0; 
redColor(:,:,3) = 0; 
greenColor(:,:,1) = 0; 
greenColor(:,:,3) = 0;
blueColor(:,:,1) = 0; 
blueColor(:,:,2) = 0; 

redOnly = rgb2gray(redColor);
redLevel = graythresh(redOnly);
redMap = im2bw(redOnly,redLevel);
redSum = sum(sum(redMap));

greenOnly = rgb2gray(greenColor);
greenLevel = graythresh(greenOnly);
greenMap = im2bw(greenOnly,greenLevel);
greenSum = sum(sum(greenMap));

blueOnly = rgb2gray(blueColor);
blueLevel = graythresh(blueOnly);
blueMap = im2bw(blueOnly,blueLevel);
blueSum = sum(sum(blueMap));

if ((redSum >= greenSum) && (redSum >= blueSum))
    redTone = mean(mean(a(:,:,1)))/255;
    greenTone = (greenSum/redSum)*(mean(mean(a(:,:,2)))/255);
    blueTone = (blueSum/redSum)*(mean(mean(a(:,:,3)))/255);
    weightedTone = [redTone greenTone blueTone];
elseif ((greenSum >= redSum) && (greenSum >= blueSum))
    redTone = (redSum/greenSum)*mean(mean(a(:,:,1)))/255;
    greenTone = (mean(mean(a(:,:,2)))/255);
    blueTone = (blueSum/greenSum)*(mean(mean(a(:,:,3)))/255);
    weightedTone = [redTone greenTone blueTone];
elseif ((blueSum >= redSum) && (blueSum >= greenSum))
    redTone = (redSum/blueSum)*mean(mean(a(:,:,1)))/255;
    greenTone = (greenSum/blueSum)*(mean(mean(a(:,:,2)))/255);
    blueTone = (mean(mean(a(:,:,3)))/255);
    weightedTone = [redTone greenTone blueTone];
end

showColor3.fh = figure('units','pix',...
    'position',[0 0 ((imSize(1:2)).*1.25)],...
    'menubar','none',...
    'name','Weighted tone',...
    'Color', weightedTone,...
    'numbertitle','off',...
    'resize','off');
movegui(showColor3.fh,'center')
imshow(a);

end

