function [G Y]= rgbToxyz(green, yellow, leafColor)

M = [0.431 0.342 0.178; 0.222 0.707 0.071; 0.020 0.130 0.939];

% green = green';
% yellow = yellow';
% leafColor = leafColor';

green = abs(green');
yellow = abs(yellow');
leafColor = abs(leafColor');

%Converting green circles to xyz
c1 = mtimes(M, green);
green_x = c1(1) / (c1(1) + c1(2) + c1(3));
green_y = c1(2) / (c1(1) + c1(2) + c1(3));
green_z = c1(3) / (c1(1) + c1(2) + c1(3));

%Converting yellow circles to xyz
c2 = mtimes(M, yellow);
yellow_x = c2(1) / (c2(1) + c2(2) + c2(3));
yellow_y = c2(2) / (c2(1) + c2(2) + c2(3));
yellow_z = c2(3) / (c2(1) + c2(2) + c2(3));

%Converting leaf color to xyz
c3 = mtimes(M, leafColor);
leaf_x = c3(1) / (c3(1) + c3(2) + c3(3));
leaf_y = c3(2) / (c3(1) + c3(2) + c3(3));
leaf_z = c3(3) / (c3(1) + c3(2) + c3(3));

x = [abs(green_x) yellow_x abs(leaf_x)];
y = [abs(green_y) yellow_y abs(leaf_y)];

%Computing distance of leaf from green and yellow circles

d1 = sqrt((green_x - leaf_x).^2 + (green_y - leaf_y).^2);       % leaf distance from green
d2 = sqrt((yellow_x - leaf_x).^2 + (yellow_y - leaf_y).^2);     % leaf distance from yellow

G = 100 *(1- (d1/ (d1+d2)));       %Green percentage
Y = 100 *(1- (d2/(d1+d2)));        %Yellow percentage
