function [final] = remove_shadow(imagine);

I = imagine;
Id = double(I);
I1 = log10(Id(:,:,1)/255+1);
I2 = log10(Id(:,:,2)/255+1);
I3 = log10(Id(:,:,3)/255+1);
r = I1 - I2;
b = I3 - I2;
rv=reshape(r,size(r,1)*size(r,2),1);
bv=reshape(b,size(b,1)*size(b,2),1);

p = polyfit(rv,bv,1);

f = polyval(p,rv);

w2 = 1/(sqrt(p(1)^2+1));
w1 = -p(1)/(sqrt(p(1)^2+1));

I_invar=-w2*r+w1*b;
Imin=min(min(I_invar));
Imax=max(max(I_invar));
Iscal=((I_invar-Imin)/(Imax-Imin))*255;

% figure(12);
% imshow(uint8(Iscal));

% figure();
Y=rgb2gray(uint8(Id));
% imshow(Y);

% Ye=edge(Y,'canny',0.5,3);
Img=double(Y)-double(Iscal);
% figure(5);
% imshow(Ye);
% 
% Ye1=edge(Iscal,'canny',0.5,3);
% Img=double(Y)-double(Iscal);
% figure(6);
% imshow(Ye1);


s = strel('disk',2);
rez = imopen(Img, s);
% Iscale=edge(uint8(Iscal),'canny',0.5,3);

% figure();
% imshow(Img), pixval;
% figure();
% imshow(rez), pixval;

for i=1:size(rez,1)
    for j=1:size(rez,2)
        if (rez(i,j)<0)
            rez(i,j) = 0;
        else
            rez(i,j) = 1;
        end
    end
end
imwrite(rez, 'masca_binara.png', 'png');
% save rez;

%load rez;
s = strel('disk',10);
rez1 = imerode(rez, s);
rez2 = imerode(rez1, s);
masca1 = rez2-rez1;
% figure(7);
% imagesc(masca1), pixval;

rez11 = imdilate(rez, s);
rez22 = imdilate(rez11, s);
masca2 = rez11 - rez22;
% figure(8);
% imagesc(masca2), pixval;

masca_mare = rez1-rez11;
% figure();
% imagesc(masca_mare), pixval;

k = 1; l = 1; MuR1 = 0; MuG1 = 0; MuB1 = 0;
MuR2 = 0; MuG2 = 0; MuB2 = 0;
for i=1:size(Id,1)
    for j=1:size(Id,2)
        if (masca1(i,j) == -1)
            MuR1 = MuR1 + Id(i,j,1);
            MuG1 = MuG1 + Id(i,j,2);
            MuB1 = MuB1 + Id(i,j,3);
            Y1(k) = double(Y(i,j));
            k = k+1;
        end
        
        if (masca2(i,j) == -1)
            MuR2 = MuR2 + Id(i,j,1);
            MuG2 = MuG2 + Id(i,j,2);
            MuB2 = MuB2 + Id(i,j,3);
            Y2(l) = double(Y(i,j));
            l = l+1;
        end
    end
end
N1 = k-1;
N2 = l-1;

MuR1 = MuR1/N1;
MuG1 = MuG1/N1;
MuB1 = MuB1/N1;

MuR2 = MuR2/N2;
MuG2 = MuG2/N2;
MuB2 = MuB2/N2;

sigma1 = std(Y1);
sigma2 = std(Y2);

gamma = sigma1/sigma2;
alfaR = MuR1 - gamma*MuR2;
alfaG = MuG1 - gamma*MuG2;
alfaB = MuB1 - gamma*MuB2;

for i=1:size(Id,1)
    for j=1:size(Id,2)
        if (rez(i,j) == 0)
            Id(i,j,1) = alfaR + gamma*Id(i,j,1);
            Id(i,j,2) = alfaG + gamma*Id(i,j,2);
            Id(i,j,3) = alfaB + gamma*Id(i,j,3);
        end
    end
end

% figure(9);
% imshow(uint8(Id));
imwrite(uint8(Id), 'imagine.png', 'png');


for i=1:size(Id,1)
    for j=1:size(Id,2)
        if (masca_mare(i,j) == -1)
            Masca(i,j,1) = 0;
            Masca(i,j,2) = 255;
            Masca(i,j,3) = 0;
        else
            Masca(i,j,1) = uint8(Id(i,j,1));
            Masca(i,j,2) = uint8(Id(i,j,2));
            Masca(i,j,3) = uint8(Id(i,j,3));
        end
    end
end

% figure(10);
% imshow(Masca);
imwrite(Masca, 'masca.png', 'png');
% 
% 
[i1,i2,i3,c,d,mov] = inpaint7('imagine.png','masca.png',[0 255 0]);
%plotall;
final = uint8(i1);
% figure();
% imshow(uint8(i1));
% imwrite(uint8(i1), 'final.png', 'png');
% imshow(Iscale);
% Idif=abs(double(Iscale)-double(Ye));
% figure();
% imshow(uint8(Idif*255));