function [  ] = makeBoxes( fileName , numberOfBoxes, mixLevel, colorSpace, mixType)

if ~(exist('mixLevel','var'))
    mixLevel = 0.25;
end

if ~(exist('colorSpace','var'))
    colorSpace = 0;
end

if ~(exist('mixType','var'))
    mixType = 0;
end

if (mixLevel > 1)
    mixLevel = 1;
elseif (mixLevel < 0)
    mixLevel = 0;
end

imageData = imread(fileName);
newImage = imageData;

imSize = size(imageData);

vectorOfElements = linspace(0,1-1/numberOfBoxes,numberOfBoxes);
vectorOfHeightPixels = round(vectorOfElements.*imSize(1)+1);
vectorOfWidthPixels = round(vectorOfElements.*imSize(2)+1);

for i=1:length(vectorOfElements)
    for k=1:length(vectorOfElements)
        if i==length(vectorOfElements) && k==length(vectorOfElements)
            a = imageData(vectorOfHeightPixels(i):max(vectorOfHeightPixels),vectorOfWidthPixels(k):max(vectorOfWidthPixels),:);
        elseif k==length(vectorOfElements) && i<length(vectorOfElements)
            a = imageData(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):max(vectorOfWidthPixels),:);
        elseif i==length(vectorOfElements) && k<length(vectorOfElements)
            a = imageData(vectorOfHeightPixels(i):max(vectorOfHeightPixels),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),:);
        else
            a = imageData(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),:);
        end
        
        % --- Weighting using colormaps
        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)));
            greenTone = (greenSum/redSum)*(mean(mean(a(:,:,2))));
            blueTone = (blueSum/redSum)*(mean(mean(a(:,:,3))));
            weightedTone = [redTone greenTone blueTone];
        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 = [redTone greenTone blueTone];
        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 = [redTone greenTone blueTone];
        end


        if i==length(vectorOfElements) && k==length(vectorOfElements)
            newImage(vectorOfHeightPixels(i):max(imSize(1)),vectorOfWidthPixels(k):max(imSize(2)),1) = round(weightedTone(1));
            newImage(vectorOfHeightPixels(i):max(imSize(1)),vectorOfWidthPixels(k):max(imSize(2)),2) = round(weightedTone(2));
            newImage(vectorOfHeightPixels(i):max(imSize(1)),vectorOfWidthPixels(k):max(imSize(2)),3) = round(weightedTone(3));
        elseif k==length(vectorOfElements) && i<length(vectorOfElements)
            newImage(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):max(imSize(2)),1) = round(weightedTone(1));
            newImage(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):max(imSize(2)),2) = round(weightedTone(2));
            newImage(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):max(imSize(2)),3) = round(weightedTone(3));
        elseif i==length(vectorOfElements) && k<length(vectorOfElements)
            newImage(vectorOfHeightPixels(i):max(imSize(1)),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),1) = round(weightedTone(1));
            newImage(vectorOfHeightPixels(i):max(imSize(1)),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),2) = round(weightedTone(2));
            newImage(vectorOfHeightPixels(i):max(imSize(1)),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),3) = round(weightedTone(3));
        else
            newImage(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),1) = round(weightedTone(1));
            newImage(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),2) = round(weightedTone(2));
            newImage(vectorOfHeightPixels(i):vectorOfHeightPixels(i+1),vectorOfWidthPixels(k):vectorOfWidthPixels(k+1),3) = round(weightedTone(3));
        end
    end
end

originalImage = imageData;
if (colorSpace == 0)
    grayOfOriginalImage = rgb2gray(imageData);
    originalImage = repmat(grayOfOriginalImage,[1 1 3]);
end

if (mixType == 0)
    finalImage = (newImage.*(1-mixLevel)+originalImage.*(0+mixLevel));
else
    finalImage = ((double(newImage)).*(double(originalImage))/65025);
end
showColor3.fh = figure('units','pix',...
    'menubar','none',...
    'numbertitle','off',...
    'resize','off');
movegui(showColor3.fh,'center')
imshow(finalImage);

newFileName = strcat('makeBoxes_',fileName);

%imwrite(finalImage,newFileName);


end

