close all
 clear all
tic

%% Load the leaf image
[filename, pathname] = uigetfile({ '*.jpg'}, 'Pick a leaf Image' );
inputImage = imread([pathname,filename]);

%% Choose the color distance model (dm)
% 1 : Euclidean Distance   2 : Delta C 
% 3 : CIEXYZ               4 : CIE76  
% 5 : CIE94                6 : DelE-00  
% 7 : CMC l:c
dm = 6;


%% Detect the reference color circles and leaf region
%Detect Circles
circles= circleDetect(inputImage);

%Detect leaf
leaf= leafDetect(inputImage);

%computing mean color of circles
Color1 = meanCircle(circles{1});
Color2 = meanCircle(circles{2});
  


if(Color1(1)> Color2(1)) % yellow has more red than green
    yellow= Color1;
    green= Color2;

else
    yellow= Color2;
    green= Color1;
end

leafColor= mean_leaf(leaf);
if (dm==1)
    [G, Y] = rgbDifference(green , yellow, leafColor); %D1
elseif (dm == 2)
    [G, Y] = rgbDifference2(green, yellow, leafColor); %D2
elseif (dm == 3)
    [G, Y] = rgbToxyz(green , yellow, leafColor); %D3
elseif (dm == 4)
    [G, Y] = labDifference(green, yellow, leafColor); %D4
elseif (dm == 5)
    [G, Y] = delE94(green, yellow,leafColor); %D5
elseif (dm == 6)
    [G, Y] = delE00(green, yellow,leafColor); %D6
elseif (dm == 7)
    [G, Y] = delEcmc(green, yellow,leafColor); %D7 
else
    [G, Y] = delE00(green, yellow,leafColor); %D6
end

plotColors(green, yellow, leafColor)  %Plotting of both Reference and leaf colors

fprintf('Percentage of Nitrogen: %d \n', round(G) );



toc

