% matlab彩色图像分离通道并合并成处理后的彩色图像(彩色变灰度再变彩色)
% 白平衡算法(灰度世界法)消除RGB受光照影响
clear all;
close all;
%读入原始图像
srcImage = imread('7.jpg');
figure,imshow(srcImage);
srcImageGray = rgb2gray(srcImage);
figure,imshow(srcImageGray);
%白平衡算法
R = srcImage(:,:,);
G = srcImage(:,:,);
B = srcImage(:,:,);
%求其各通道平均值及增益
Raver = mean(mean(R));
Gaver = mean(mean(G));
Baver = mean(mean(B));
K = (Raver+Gaver+Baver)/;
Kr = K/Raver;
Kg = K/Gaver;
Kb = K/Baver;
%更新RGB值
Rnew = R*Kr;
Gnew = G*Kg;
Bnew = B*Kb;
%合并通道
% [m,n,k] = size(srcImage);
% dstImage = zeros(m,n,k);
dstImage(:,:,) = Rnew;
dstImage(:,:,) = Gnew;
dstImage(:,:,) = Bnew; figure,imshow(dstImage);
dstImageGray = rgb2gray(dstImage);
figure,imshow(dstImageGray);
结果图如下:
原图:
白平衡后图: