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

function [imageRGB] = imageLAB2RGB(imageLAB)

load monitor;
load XYZ;

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

[row col lab] = size(imageLAB);

tempLAB = reshape(imageLAB, row*col, lab);
tempRGB = 255*(xyz2rgb*(lab2xyz(tempLAB,whiteXYZ))');

imageRGB = zeros(row, col, 3);

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