function [ output_args ] = activity( filename )

clearvars -except filename;

colorList = {'Yellow','Magenta','Cyan','Red','Green','Blue'};
rgbList = {[1 1 0],[1 0 1],[0 1 1],[1 0 0],[0 1 0],[0 0 1]};

showColor.fh = figure('units','pix',...
    'position',[0 0 680 680],...
    'menubar','none',...
    'name','Color tone',...
    'Color', [0 0 0],...
    'numbertitle','off',...
    'resize','off');
showColor.infotexts = uibuttongroup('units','pixels',...
    'pos',[10 10 660 60],...
    'fontsize',14,...
    'backgroundcolor',[1,1,1],...
    'Visible','on');
showColor.activity = uicontrol(showColor.infotexts,...
    'style','text',...
    'unit','pix',...
    'backgroundcolor',[1,1,1],...
    'position',[10 10 140 15],...
    'horizontalalignment','left',...
    'fontsize',12,...
    'string','');
showColor.colorCount = uicontrol(showColor.infotexts,...
    'style','text',...
    'unit','pix',...
    'backgroundcolor',[1,1,1],...
    'position',[150 10 180 15],...
    'horizontalalignment','left',...
    'fontsize',12,...
    'string','');
showColor.lightLevel = uicontrol(showColor.infotexts,...
    'style','text',...
    'unit','pix',...
    'backgroundcolor',[1,1,1],...
    'position',[330 10 180 15],...
    'horizontalalignment','left',...
    'fontsize',12,...
    'string','');
showColor.colorTone = uicontrol(showColor.infotexts,...
    'style','text',...
    'unit','pix',...
    'backgroundcolor',[1,1,1],...
    'position',[10 35 180 15],...
    'horizontalalignment','left',...
    'fontsize',12,...
    'string','');
showColor.rgbValueText = uicontrol(showColor.infotexts,...
    'style','text',...
    'unit','pix',...
    'backgroundcolor',[1,1,1],...
    'position',[150 35 180 15],...
    'horizontalalignment','left',...
    'fontsize',12,...
    'string','');
movegui(showColor.fh,'center')

a = imread(filename);
imSize = size(a);

RGB = rand(100, 100, 3);
HSV = rgb2hsv(a);
HSV(:, :, 2) = HSV(:, :, 2) * 50;
HSV(HSV > 1) = 1;
saturatedRGB = hsv2rgb(HSV);

% --- Weighting using colormaps
redColor = saturatedRGB;
redColor(:,:,2) = 0; 
redColor(:,:,3) = 0;
redOnly = rgb2gray(redColor);
redLevel = graythresh(redOnly);
redMap = im2bw(redOnly,redLevel);
redSum = sum(sum(redMap));

greenColor = saturatedRGB;
greenColor(:,:,1) = 0; 
greenColor(:,:,3) = 0;
greenOnly = rgb2gray(greenColor);
greenLevel = graythresh(greenOnly);
greenMap = im2bw(greenOnly,greenLevel);
greenSum = sum(sum(greenMap));

blueColor = saturatedRGB;
blueColor(:,:,1) = 0; 
blueColor(:,:,2) = 0; 
blueOnly = rgb2gray(blueColor);
blueLevel = graythresh(blueOnly);
blueMap = im2bw(blueOnly,blueLevel);
blueSum = sum(sum(blueMap));

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

rgbMean = round([mean(mean(a(:,:,1))), mean(mean(a(:,:,2))), mean(mean(a(:,:,3)))]);

tempRGB = rgbMean.*rgbMean;
newRGB = round(tempRGB.*((max(rgbMean))/(max(tempRGB))));

largestRgbColorTone = find(rgbMean == max(rgbMean));
if (largestRgbColorTone == 1)
elseif (largestRgbColorTone == 2)
elseif (largestRgbColorTone == 3)
end

% --- Comparing colormap with color list
tempTone = round([mean(mean(a(:,:,1))), mean(mean(a(:,:,2))), mean(mean(a(:,:,3)))]);
weightedTone;
tempRGBcomp = 256*3;
for j=1:length(colorList)
    tempRGB = abs(rgbList{j}-(tempTone./256));
    tempRGBsum = tempRGB(1)+tempRGB(2)+tempRGB(3);
    if (tempRGBsum < tempRGBcomp)
        colorPosition = j;
        tempRGBcomp = tempRGBsum;
    end
end

% --- Check contrasts/similar areas
largestRGBvaluePosition = find(weightedTone == max(weightedTone));
window = round((max(imSize))/100);
h = fspecial('gaussian',[window window],(window*5));
blurredImage = imfilter(a,h,'same');
img1 = blurredImage(:,:,largestRGBvaluePosition);
img2 = ~(im2bw(img1,graythresh(img1)));
B = bwboundaries(img2);
activityString = horzcat('Activity/contrasts: ',num2str(num2str(length(B))));

% --- Check lightness level
lightLevel = round((mean(mean(a(:,:,1))) + mean(mean(a(:,:,2))) + mean(mean(a(:,:,3)))) / 3);
lightLevelString = horzcat('Light level (0-255): ',num2str(lightLevel));

% --- Count colors
rgb_columns = reshape(saturatedRGB, [], 3);
[unique_colors, m, n] = unique(rgb_columns, 'rows');
colorCounts = accumarray(n, 1);
[max_count, idx] = max(colorCounts);
bw = n == idx;
bw = reshape(bw, size(a, 1), size(a, 2));

% --- Show image
set(showColor.fh,'Color',(newRGB./256));
set(showColor.activity,'str',activityString);
set(showColor.lightLevel,'str',lightLevelString);
set(showColor.colorTone,'str',colorList{colorPosition});
set(showColor.colorCount,'str',horzcat('Color count: ',num2str(length(colorCounts))));
set(showColor.rgbValueText,'str',horzcat('RGB-value: ',num2str(tempTone)));
hAxes = gca; 

imshow(a,'Parent',hAxes);

end

