旷视low-level系列(一):Bayer Pattern Unification and Bayer Preserving Augmentation

本文提出BayerUnify方法,将不同Bayer模式的RAW图像转换为统一模式,以便利用异源数据进行更有效的训练。同时,BayerAug是一种保持Bayer模式不变的RAW图像增强策略,以避免数据增强带来的伪影。
摘要由CSDN通过智能技术生成

1. Motivation

对于RAW域去噪,通常会将单通道bayer格式的RAW图打包成4通道,然后送入神经网络。不同厂家生产的sensor出的RAW图可能具有不同的bayer模式,通常是RGGB,BGGR, GRBG和GBRG。
业内做AI-ISP的攻城狮们应该都会遇到这样一个问题,在适配不同sensor的过程中会积累大量具有不同Bayer模式的数据,然后在训练模型时都想用上,这时大家都会将这些异源的数据统一成相同的bayer模式,常用的操作有:① 在裁剪patch时根据目标bayer模式选择合适的起点;② 打包成4通道,然后交换通道顺序。论文作者发现第二种方式会产生伪影,而第一种方式不会。
另外,数据增强是训练神经网络时提升性能的一种常用手段,对于RAW数据,为了避免破坏bayer模式,通常会选择在打包成4通道后再做翻转和旋转等增强。然而作者发现这样也会产生伪影,并提出了相应的解决方案。
在这里插入图片描述

2. Contribution

  • 提出了BayerUnify,将不同的bayer模式转换为一个统一的模式,充分利用异源数据,扩大训练集规模
  • 提出了BayerAug,一种有效的RAW图像的数据增强方式

3. Methods

3.1 BayerUnify

训练阶段采用crop的方式将当前bayer模式转换为目标bayer模式
在这里插入图片描述
推理阶段采用先pad的方式转换bayer模式(crop会丢失信息),对神经网络的输出再做crop得到与原始图像格式一致的结果。
在这里插入图片描述

def bayer_unify(raw: np.ndarray, input_pattern: str, target_pattern: str, mode: str) -> Tuple:
    """
    Convert a bayer raw image from one bayer pattern to another.

    Parameters
    ----------
    raw : np.ndarray in shape (H, W)
        Bayer raw image to be unified.
    input_pattern : {"RGGB", "BGGR", "GRBG", "GBRG"}
        The bayer pattern of the input image.
    target_pattern : {"RGGB", "BGGR", "GRBG", "GBRG"}
        The expected output pattern.
    mode: {"crop", "pad"}
        The way to handle submosaic shift. "crop" abandons the outmost pixels,
        and "pad" introduces extra pixels. Use "crop" in training and "pad" in
        testing.
    """
    if input_pattern not in BAYER_PATTERNS:
        raise ValueError('Unknown input bayer pattern!')
    if target_pattern not in BAYER_PATTERNS:
        raise ValueError('Unknown target bayer pattern!')
    if mode not in NORMALIZATION_MODE:
        raise ValueError('Unknown normalization mode!')
    if not isinstance(raw, np.ndarray) or len(raw.shape) != 2:
        raise ValueError('raw should be a 2-dimensional numpy.ndarray!')

    if input_pattern == target_pattern:
        h_offset, w_offset = 0, 0
    elif input_pattern[0] == target_pattern[2] and input_pattern[1] == target_pattern[3]:
        h_offset, w_offset = 1, 0
    elif input_pattern[0] == target_pattern[1] and input_pattern[2] == target_pattern[3]:
        h_offset, w_offset = 0, 1
    elif input_pattern[0] == target_pattern[3] and input_pattern[1] == target_pattern[2]:
        h_offset, w_offset = 1, 1
    else:  # This is not happening in ["RGGB", "BGGR", "GRBG", "GBRG"]
        raise RuntimeError('Unexpected pair of input and target bayer pattern!')

    if mode == "pad":
        out = np.pad(raw, [[h_offset, h_offset], [w_offset, w_offset]], 'reflect')
    elif mode == "crop":
        h, w = raw.shape
        out = raw[h_offset:h - h_offset, w_offset:w - w_offset]
    else:
        raise ValueError('Unknown normalization mode!')

    return out, h_offset, w_offset

3.2 BayerAug

直接对RAW数据做翻转会改变bayer模式,BayerAug先翻转再执行BayerUnify,保证bayer模式不变。
在这里插入图片描述

def bayer_aug(raw: np.ndarray, flip_h: bool, flip_w: bool, transpose: bool, input_pattern: str) -> np.ndarray:
    """
    Apply augmentation to a bayer raw image.

    Parameters
    ----------
    raw : np.ndarray in shape (H, W)
        Bayer raw image to be augmented. H and W must be even numbers.
    flip_h : bool
        If True, do vertical flip.
    flip_w : bool
        If True, do horizontal flip.
    transpose : bool
        If True, do transpose.
    input_pattern : {"RGGB", "BGGR", "GRBG", "GBRG"}
        The bayer pattern of the input image.
    """

    if input_pattern not in BAYER_PATTERNS:
        raise ValueError('Unknown input bayer pattern!')
    if not isinstance(raw, np.ndarray) or len(raw.shape) != 2:
        raise ValueError('raw should be a 2-dimensional numpy.ndarray')
    if raw.shape[0] % 2 == 1 or raw.shape[1] % 2 == 1:
        raise ValueError('raw should have even number of height and width!')

    aug_pattern, target_pattern = input_pattern, input_pattern

    out = raw
    if flip_h:
        out = out[::-1, :]
        aug_pattern = aug_pattern[2] + aug_pattern[3] + aug_pattern[0] + aug_pattern[1]
    if flip_w:
        out = out[:, ::-1]
        aug_pattern = aug_pattern[1] + aug_pattern[0] + aug_pattern[3] + aug_pattern[2]
    if transpose:
        out = out.T
        aug_pattern = aug_pattern[0] + aug_pattern[2] + aug_pattern[1] + aug_pattern[3]

    out = bayer_unify(out, aug_pattern, target_pattern, "crop")
    return out

4. Comments

初看,就这?用起来,还挺香。没有很大的创新,胜在工程价值较高。

Reference

[1] Learning Raw Image Denoising with Bayer Pattern Unification and Bayer Preserving Augmentation
[2] 官方代码

  • 23
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Bayer模式是由伊士曼·柯达公司科学家Bryce Bayer发明的一种数字图像处理技术,也被称为Bayer格式。它是一种用于记录彩色图像的方法,通过在图像传感器上安排红、绿、蓝三种滤光片的不同排列,以捕捉并编码不同颜色的信息。Bayer模式通常以2×2的矩阵形式表示,其中每个单元格代表一个像素,通过在每个像素上使用不同的滤光片,实现对红、绿、蓝三种颜色的采样。通常情况下,Bayer模式采用绿色滤光片的数量最多,因为人眼对绿色的感知更为敏感。 Bayer模式的排列方式可以用来还原彩色图像,并且可以通过一些方法进行统一和增强,而不会破坏原始图像的空间关系。其中一种方法是使用翻转和裁剪进行数据增强,同时保持图像的Bayer模式。这种方法被称为Bayer Preserving AugmentationBayerAug)。首先,图像被翻转,然后通过裁剪来逆转Bayer模式的变化,以使图像恢复到原来的样子。这样可以对Bayer模式图像进行增强处理而不会引入伪影。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [图像bayer pattern介绍及插值原理](https://blog.csdn.net/q2519008/article/details/122937687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Learning Raw Image Denoising with Bayer Pattern Unification and Bayer Preserving Augmentation](https://blog.csdn.net/qq_27871973/article/details/96869379)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值