% Description:
%
%       imageRGB2LAB.m converts an image from RGB to LAB
%       
% Input:
%
%       imageRGB - image in RGB coordinates
%
% Output:
%
%       imageLAB - image in LAB coordinates
%

function [imageLAB] = imageRGB2LAB(imageRGB)

load monitor;
load XYZ;

XYZ = data;
rgb2xyz = XYZ'*phosphors;
xyz2rgb = inv(rgb2xyz);
whiteXYZ = [100 100 100];

[row col rgb] = size(imageRGB);

tempRGB = (reshape(imageRGB, row*col, rgb))/255;
tempLAB = vcXYZ2lab((rgb2xyz*tempRGB')',whiteXYZ);

imageLAB = zeros(row, col, 3);

for x = 1:1:row,
    for y = 1:1:col,
        imageLAB(x,y,:) = tempLAB(x+(y-1)*row,:);
    end
end