绿平衡(Green Balance)

图像信号处理芯片设计原理----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=2Gr_meanGb_mean

  • 计算各个2x2块中Gr和Gb的差值:
    d i f f = ∣ G r − G b ∣ diff = |Gr-Gb| diff=GrGb

  • 判断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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值