图像信号处理芯片设计原理----07 绿平衡+去马赛克
Green Imbalance
专利CN105530500的基本思路:
关键:在平衡Gr和Gb的同时,要尽量保持颜色边缘的清晰。
-
分别计算某范围内Gr和Gb的平均值,记为Gr_mean 和 Gb_mean,计算平均值的差值的一半,记为diff_mean:
d i f f _ m e a n = ∣ G r _ m e a n − G b _ m e a n ∣ 2 diff\_mean = \frac{|Gr\_mean-Gb\_mean|}{2} diff_mean=2∣Gr_mean−Gb_mean∣ -
计算各个2x2块中Gr和Gb的差值:
d i f f = ∣ G r − G b ∣ diff = |Gr-Gb| diff=∣Gr−Gb∣ -
判断diff_mean是否大于第一阈值thed1或者diff是否大于第二阈值thed2,二者满足其一则不修改Gr和Gb的值,否则执行下一步。
-
修改
G r = ( G r + G b ) / 2 G b = ( G r + G b ) / 2 Gr = (Gr + Gb)/2\\ Gb = (Gr + Gb)/2 Gr=(Gr+Gb)/2Gb=(Gr+Gb)/2
复现的MATLAB代码
function out_raw = GIC(img_raw,params,thed1,thed2)
H = [1 0 1 0 1; 0 0 0 0 0; 1 0 1 0 1; 0 0 0 0 0; 1 0 1 0 1]/9;
raw_mean = imfilter(img_raw,H,"symmetric");
out_raw = img_raw;
switch params.pattern
case 'rggb'
Gr = img_raw(1:2:end,2:2:end);
Gr_mean = raw_mean(1:2:end,2:2:end);
Gb = img_raw(2:2:end,1:2:end);
Gb_mean = raw_mean(2:2:end,1:2:end);
case 'bggr'
Gr = img_raw(2:2:end,1:2:end);
Gr_mean = raw_mean(2:2:end,1:2:end);
Gb = img_raw(1:2:end,2:2:end);
Gb_mean = raw_mean(1:2:end,2:2:end);
case 'grbg'
Gr = img_raw(1:2:end,1:2:end);
Gr_mean = raw_mean(1:2:end,1:2:end);
Gb = img_raw(2:2:end,2:2:end);
Gb_mean = raw_mean(2:2:end,2:2:end);
case 'gbrg'
Gr = img_raw(2:2:end,2:2:end);
Gr_mean = raw_mean(2:2:end,2:2:end);
Gb = img_raw(1:2:end,2:2:end);
Gb_mean = raw_mean(1:2:end,2:2:end);
end
mean_diff = abs(Gr_mean - Gb_mean) / 2;
diff = abs(Gr - Gb);
flag1 = (mean_diff > thed1);
flag2 = (diff > thed2);
flag = min(1,flag1+flag2);
% Gr_out = max(0,min(255,Gr + mean_diff));
% Gb_out = max(0,min(255,Gb - mean_diff));
Gr_out = max(0,min(255,(Gr + Gb)/2));
Gb_out = max(0,min(255,(Gr + Gb)/2));
Gr_out = Gr.*flag + Gr_out.*(1-flag);
Gb_out = Gb.*flag + Gb_out.*(1-flag);
switch params.pattern
case 'rggb'
out_raw(1:2:end,2:2:end) = Gr_out;
out_raw(2:2:end,1:2:end) = Gb_out;
case 'bggr'
out_raw(1:2:end,2:2:end) = Gb_out;
out_raw(2:2:end,1:2:end) = Gr_out;
case 'grbg'
out_raw(1:2:end,1:2:end) = Gr_out;
out_raw(2:2:end,2:2:end) = Gb_out;
case 'gbrg'
out_raw(1:2:end,1:2:end) = Gb_out;
out_raw(2:2:end,2:2:end) = Gr_out;
end