function ycxcz2rgb(filename)

%back2rgb transform YyCxCz source gamut back to XYZ to sRGB and save to a tif image
%with your choice on name. 
    close all
    
    folderName = ['output/',filename];
    
    load('data/imgYyCxCzUniqueUpdate.mat')
    load('data/ic.mat')
    load('data/imgSize.mat')
    
    %YCxCz to XYZ
    %Indigo press white point
    Xn=0.8594;
    Yn=0.8872;
    Zn=0.7945;

    y0=imgYyCxCzUniqueUpdate(:,1)/116;
    x0=imgYyCxCzUniqueUpdate(:,2)/500+y0;
    z0=y0-imgYyCxCzUniqueUpdate(:,3)/200;
    xyz=[x0*Xn y0*Yn z0*Zn];
    
    % use index vectors to locate unique xyz value back to image pixel
    % locations. 
    num=length(ic);
    xyz_update=zeros(num,1,3);
    for i=1:num
        xyz_update(i,:)=xyz(ic(i),:);
    end
    XYZ(1:num,:)= xyz_update;

    %Reshape to orginal image dimension
    XYZ = reshape(XYZ,row,col,l);
    %XYZ to sRGB
    img_sRGB=XYZ2sRGB(XYZ,50);
    %gamma correction
    imgGamutMapped=uint8((255*(img_sRGB).^(1/2.2)));

    % imshow(imgGamutMapped)
    imwrite(real(imgGamutMapped),folderName)
end


