function [Lab,mm,des]=transform_rgb2labO(A,h,calclab,calclabds,npuntos,calcul,modelo)
Lab=[];  mm=[];  des=[];
try
    origtitle=get(calcul,'String');
    met_conv=get(modelo,'value');
    s=size(A);clc
    if length(s)<3
        errordlg('La imagen no es en color','Error')
        return
    end

    set(gcf,'color','w')
    set(calcul,'BackgroundColor',[1 .4 .4],'string','Procesando...','FontSize',12)
    set(calclab,'string','');
    set(calclabds,'string','')
    pause(0.1)

    if met_conv==1
      Lab=modelo_cuad_int(A);
    elseif met_conv==2
      Lab=modelo_directo(A);
    end

    for i=1:3
        temp=Lab(:,:,i);
        mm(i)=mean(temp(:));
        des(i)=std(temp(:));
        mini(i)=min(temp(:));
        maxi(i)=max(temp(:));
    end

    S=size(Lab);
    np=S(1)*S(2);
    set(calclab,'string',num2str(mm,4));
    set(calclabds,'string',num2str(des,4));
    set(npuntos,'string',num2str(np,12));

    disp('-')
    disp(['   L*a*b* Promedio: ',num2str(mm(1:3))])
    disp(['L*a*b* D. ESTANDAR: ',num2str(des(1:3))])
    disp('-')
    disp(['     L*a*b* MINIMO: ',num2str(mini)])
    disp(['     L*a*b* MAXIMO: ',num2str(maxi)])
    disp('-')
    disp(['     NÂ° de píxeles: ',num2str(np)])
    disp('-')
    set(calcul,'BackgroundColor',[.5 .9 1],'string',origtitle,'FontSize',12)

catch
    set(gcf,'color','r')
    set(calcul,'BackgroundColor',[.5 .9 1],'string',origtitle,'FontSize',12)
    d=lasterr;
    errordlg([d],'Error')
    error(d)
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Lab=modelo_cuad_int(I)
try
    load -ascii parametros_modelo_cuad_int
    coef=parametros_modelo_cuad_int;
    I=double(I);
    for i=1:3
        Lab(:,:,i)=coef(1,i)*I(:,:,1)+coef(2,i)*I(:,:,2)+coef(3,i)*I(:,:,3)+coef(4,i)*I(:,:,1).*I(:,:,2)+...
            coef(5,i)*I(:,:,1).*I(:,:,3)+coef(6,i)*I(:,:,2).*I(:,:,3)+coef(7,i)*I(:,:,1).^2+coef(8,i)*I(:,:,2).^2+coef(9,i)*I(:,:,3).^2+...
            coef(10,i)*I(:,:,1).*I(:,:,2).*I(:,:,3)+coef(11,i);
    end
catch
    errordlg(lasterr,'Error')
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Lab=modelo_directo(I)
% RGB a L*a*b*, modelo directo.
% Referencia:
ref=[0.3127 0.3290 100];
I=double(I);
xref=ref(1);
yref=ref(2);
zref=1-(xref+yref);
YW=ref(3);
XW=xref*YW/yref;
ZW=zref*YW/yref;

try
% RGB ==> sRGB %%%%%%
    for i=1:3
        temp=I(:,:,i)/255;
        sRGB(:,:,i)=100*((temp>0.04045).*((temp+0.055)/1.055).^2.4+(temp<=0.04045).*(temp/12.92));
    end
% sRGB ==> XYZ %%%%%%
    RGB2XYZ=[0.412424 0.357579 0.180464;0.212656 0.715158 0.072186;0.019332 0.119193 0.950444];
    for i=1:3
        XYZ(:,:,i) = RGB2XYZ(i,1)*sRGB(:,:,1)+RGB2XYZ(i,2)*sRGB(:,:,2)+RGB2XYZ(i,3)*sRGB(:,:,3);
    end
% XYZ ==> L*a*b* %%%%%%
    temp=XYZ(:,:,1)/XW;
    escala=1/3*(29/6)^2;
    corte=(6/29)^3;
    hhX=(escala*temp+4/29).*(temp<=corte) + (temp.^(1/3)).*(temp>corte);
    temp=XYZ(:,:,2)/YW;
    hhY=(escala*temp+4/29).*(temp<=corte) + (temp.^(1/3)).*(temp>corte);
    temp=XYZ(:,:,3)/ZW;
    hhZ=(escala*temp+4/29).*(temp<=corte) + (temp.^(1/3)).*(temp>corte);

    L=116*hhY-16;
    L(L<0)=0;
    L(L>100)=100;
    a=500*(hhX-hhY);
    b=200*(hhY-hhZ);
    Lab=cat(3,L,a,b);

catch
    errordlg(lasterr,'Error')
end