当前位置: 首页 > news >正文

ISP Pipeline(6): Color Filter Array Interpolation 色彩滤波阵列

Color Filter Array Interpolation(CFA插值) 是图像信号处理(ISP)中的核心步骤之一。它的目标是:

将原始 Bayer 图像(只有每个像素一个颜色分量)还原成完整的 RGB 图像,即为每个像素补全缺失的两个颜色通道 —— 这个过程称为 Demosaicing

什么是 Color Filter Array(CFA)?

  • 传感器每个像素只能采集一个颜色通道(R、G、B);

  • 为了同时获取三种颜色信息,我们使用了 Bayer Pattern(最常见的一种 CFA):

 Bayer图的像素排序:

R G R G R G...
G B G B...
R G R G...
G B G B...
...

Bayer 图中的每个像素只有 R、G 或 B 中的一个值,其余两个颜色是空的。

插值的目标

对每个像素位置,估算出缺失的两个颜色值,使其成为完整的 (R, G, B) 三通道像素。

插值方法种类

1.  最近邻插值(Nearest Neighbor)

  • 简单快速:从邻近像素直接复制缺失值;

  • 缺点:容易出现伪影或马赛克纹理。

2.  双线性插值(Bilinear Interpolation)

  • 使用上下左右的加权平均估算;

  • 比最近邻更平滑,但边缘保留能力差。

3.  双立方插值、方向感知插值(Edge-Aware)

  • 更复杂,考虑图像边缘信息;

  • 可以减少色彩混叠和锯齿,质量更高。

 代码实现:

def CFA(awb_img):"""inputs:awb_img = bayer domain image after auto white balance gain controloutputs:cfa_img = 8 bit RGB image"""awb_img = awb_img.astype(np.uint32) # change dtype to allow for larger numbers during demosaicingmax_val = np.max(awb_img)r = np.empty(awb_img.shape) # create empty arrays for R, G, and B channelsg = np.empty(awb_img.shape)b = np.empty(awb_img.shape)padded_img = np.pad(awb_img, (1,1), 'reflect') # pad image to extract shifted channels# R-channelr_on_r = padded_img[1:-2:2, 1:-2:2] # red intensity values on red pixelsr_right = padded_img[1:-2:2, 3::2] # shifted matrix of red intensity values in specified direction, same size as r_on_rr_down = padded_img[3::2, 1:-2:2]r_down_right = padded_img[3::2, 3::2]r_on_gr = np.right_shift((r_on_r + r_right), 1) # calculate red intensity values from green and blue pixelsr_on_gb = np.right_shift((r_on_r + r_down), 1)r_on_b = np.right_shift((r_on_r + r_right + r_down + r_down_right), 2)r[::2, ::2] = r_on_r # map red intensity values to the entire red channel arrayr[::2, 1::2] = r_on_grr[1::2, ::2] = r_on_gbr[1::2, 1::2] = r_on_b#G-channelg_on_gr = padded_img[1:-2:2, 2:-1:2] # green intensity values on green pixelsg_on_gb = padded_img[2:-1:2, 1:-2:2]g_up = padded_img[:-3:2, 1:-2:2] # shifted matrix of green intensity values in specified direction, same size as g_on_grg_right = padded_img[2:-1:2, 3::2]g_left = padded_img[1:-2:2, :-3:2]g_down = padded_img[3::2, 2:-1:2]g_on_r = np.right_shift((g_left + g_up + g_on_gr + g_on_gb), 2) # calculate green intensity values from red and blue pixelsg_on_b = np.right_shift((g_right + g_down + g_on_gr + g_on_gb), 2)g[::2, ::2] = g_on_r # map green intensity values to the entire green channel arrayg[::2, 1::2] = g_on_grg[1::2, ::2] = g_on_gbg[1::2, 1::2] = g_on_b# B-channelb_on_b = padded_img[2:-1:2, 2:-1:2] # blue intensity values on green pixelsb_left = padded_img[2:-1:2, :-3:2] # shifted matrix of blue intensity values in specified direction, same size as b_on_bb_up = padded_img[:-3:2, 2:-1:2]b_up_left = padded_img[:-3:2, :-3:2]b_on_gr = np.right_shift((b_on_b + b_up), 1) # calculate blue intensity values from red and green pixelsb_on_gb = np.right_shift((b_on_b + b_left), 1)b_on_r = np.right_shift((b_on_b + b_left + b_up + b_up_left), 2)b[::2, ::2] = b_on_r # map blue intensity values to the entire blue channel arrayb[::2, 1::2] = b_on_grb[1::2, ::2] = b_on_gbb[1::2, 1::2] = b_on_br = np.clip(r, 0, max_val) # ensure all values are of the correct and same dtype before stackingg = np.clip(g, 0, max_val)b = np.clip(b, 0, max_val)cfa_img = np.dstack((r, g, b)) # Resize and stack the channels to RGBcfa_img = ((cfa_img / max_val) * 255).astype(np.uint8) # rescale the image to 8 bit to skip color correction matrixreturn cfa_img
位置插值策略
R使用右、下、右下邻域平均
G on R/B使用上下左右平均
B使用上、左、左上邻域平均

相关文章:

  • 做家宴网站yahoo引擎入口
  • 甘肃泾川县门户网站两学一做淘宝关键词怎么优化
  • 大连网站制作seo综合查询是啥意思
  • 本溪网站开发杭州网站建设公司
  • 珠海做网站的公司介绍网站安全检测
  • 网站单页生成器网络营销效果评估
  • 创客匠人解析视频号公私域互通逻辑:知识变现的破圈与沉淀之道
  • Pycharm无法运行Vue项目的解决办法
  • Qt实现tcp通信(QTcpServer和QTcpSocket的应用)详细教程
  • 智能客服三大模型解析:扩展问数量如何因架构差异撬动90%匹配率?
  • CentOS下Nginx服务器搭建全攻略
  • kotlin中::class.java的意义
  • 简单使用python
  • 【零基础学AI】第5讲:Pandas数据处理
  • CSMA/CD相关习题---谢希仁课后题
  • 【redis使用场景——缓存——数据过期策略 】
  • 国外开源客服系统chathoot部署,使用教程
  • Python实例题:基于 Flask 的博客系统
  • 人工智能编程三大核心流程详解--机器学习、神经网络、NLP自然语言处理
  • K8s: Kubernetes
  • 权威认证!华宇TAS应用中间件荣获CCRC“中间件产品安全认证”
  • Beam2.61.0版本消费kafka重复问题排查
  • SQL SERVER存储过程
  • SQL重置自增
  • Solidity学习 - 认识Solidity合约结构
  • Windows命令连接符的安全风险分析与防御策略