function y=new_wb(Image)
im = im2double(Image);
r=mat2gray(im(:,:,1));%mat2gray将一个数据矩阵转换为灰度图
g=mat2gray(im(:,:,2));
b=mat2gray(im(:,:,3));
% r=guiyi(im(:,:,1));%mat2gray将一个数据矩阵转换为灰度图
% g=guiyi(im(:,:,2));
% b=guiyi(im(:,:,3));
avgR = mean(mean(r));
avgG = mean(mean(g));
avgB = mean(mean(b));
rc = r + (avgG - avgR).*(1-r).*g;
bc = b + (avgG - avgB).*(1-b).*g;
%bc = b + (avgR - avgB).*(1-b).*r;
rc = min(rc,1);%把大于1的变成1
bc = min(bc,1);
% rc =guiyi(rc);
% bc =guiyi(bc);
newr = rc;%红色通道补偿
newb = bc; %蓝色通道补偿
newg = g;
avgR = mean(mean(newr));
avgG = mean(mean(newg));
avgB = mean(mean(newb));
factor = avgG/avgB;
avgGray = (avgR + avgG + avgB)/3;
kg = avgGray/avgG;
kb = avgGray/avgB;
kr = avgGray/avgR;
fr=kr.*newr;
fg=kg.*newg;
fb=kb.*newb;
y = cat(3,fr,fg,fb);
end