function calibracionrapida(qcal,A)
try
    s=size(A); clc
    if length(s)<3
        errordlg('La imagen no es en color o es indexada','Error')
        return
    end
    hf2=figure(2);
    set(hf2,'position',[80 120 1000 600],'Name','','menubar','none','color','w')
    origtitle=get(qcal,'string');    origcolor=get(qcal,'BackgroundColor');

    set(qcal,'BackgroundColor',[.9 .4 .4],'string','Obteniendo centros...')

    posg=[0.1 0.1 0.7 0.7];
    axes('Position',posg,'Box','on','Color',[.5 .5 .5]);
    imshow(A),     axis off
    title('SELECCIONE EL PARCHE MARRON (ARRIBA, IZQUIERDA) Y NEGRO (ABAJO, DERECHA)')

    % Selección de parches
    [x,y,but]=ginput(2);
    mask=zeros(s(1),s(2));
    px=6; % Colorchecker, número de columnas
    py=4; % Colorchecker, número de filas

    npix=(diff(y)*0.8)/6;
    xx=fix(linspace(x(1),x(2),px));
    yy=fix(linspace(y(1),y(2),py));
    hold on
    cor=fix([-npix/2:npix/2]);
    p=0;

    hold on
    for j=1:length(yy)
        for i=1:length(xx)
            p=p+1;
            plot(xx(i),yy(j),'pg','markerfacecolor','g')
                xcor=xx(i)+cor;
                xcor(xcor<1)=[];
                xcor(xcor>s(2))=[];
                ycor=yy(j)+cor;
                ycor(ycor<1)=[];
                ycor(ycor>s(1))=[];
                mask(ycor,xcor)=1;
                for k=1:3
                    temp=double(A(ycor,xcor,k));
                    rgb(p,k)=mean2(temp);
                    sdrgb(p,k)=std2(temp);
                end
        end
    end

    contour(mask,1,'r-','linewidth',2)
    mask=logical(mask);
    axis off
    datos=[37.85	12.72	14.07
            65.43	17.18	17.21
            50.15	-1.91	-21.79
            43.17	-15.08	22.44
            55.40	11.58	-25.06
            70.92	-33.22	0.29
            62.06	33.37	56.24
            40.59	16.15	-45.14
            50.58	47.55	15.17
            30.51	25.11	-21.74
            72.31	-27.84	57.83
            71.43	15.50	67.80
            29.46	20.74	-49.34
            55.26	-41.23	32.03
            41.53	52.67	26.92
            81.08	-0.33	80.10
            51.74	51.26	-15.48
            52.41	-18.46	-26.64
            96.49	-0.35	0.96
            81.17	-0.69	-0.24
            66.84	-0.71	-0.25
            50.86	0.20	-0.55
            35.61	-0.36	-1.44
            20.40	0.47	-1.27]; %Pascale (2006)
    R=rgb(:,1);
    G=rgb(:,2);
    B=rgb(:,3);

    [coef,Lab,E]=ajuste_cuad_int(R,G,B,datos);
    save -ascii parametros_modelo_cuad_int coef

    uicontrol('style','push','string','Listo - Cerrar','position',[700 10 180 30],...
        'callback','close','Fontsize',16,'Backgroundcolor',[.7 1 .3]);

    set(qcal,'string',origtitle);
    set(qcal,'BackgroundColor',origcolor);
    deltaE=mean(E);
    disp('DE')
    disp(deltaE)

catch
    set(hf2,'color',[1 .6 .3])
    set(qcal,'string',origtitle,'BackgroundColor',origcolor);
    errordlg(lasterr)
end

%%%%%%%%%%%%% Modelo empírico (polinomio de 2° grado, con interacción de variables) %%%%%%%%%%%%%%%%%%%%
function [coef,Lab,E]=ajuste_cuad_int(R,G,B,datos)
try
    A=[R G B R.*G R.*B G.*B R.^2 G.^2 B.^2 R.*G.*B R*0+1];
    coef=A\datos; % Regresión lineal
    Lab=A*coef;
    E=(sum((datos-Lab).^2,2)).^0.5;

    var={'L*' 'a*' 'b*'};
    for i=1:3
        disp([var{i},'=[R G B R*G R*B G*B R^2 G^2 B^2 R*G*B 1]*[',num2str(coef(:,i)'),']'])
    end
    disp('-')

catch
    errordlg(lasterr,'Error')
end
