import numpy as np
import matplotlib.pyplot as plt
def extract_g_channel_info(raw_path, width, height, bit_depth=12, bayer_pattern='RGGB'):
"""
从拜耳阵列RAW图中提取G通道信息
:return: 原始数组、G通道掩码、最大亮度值
"""
# 读取RAW数据并解析为数组
dtype = np.uint16
with open(raw_path, 'rb') as f:
raw_data = f.read()
raw_array = np.frombuffer(raw_data, dtype=dtype).reshape(height, width)
# 修正位深(去除无效高位)
max_value = (1 << bit_depth) - 1
raw_array = np.clip(raw_array, 0, max_value)
# 创建G通道掩码(True表示该位置是G通道)
g_mask = np.zeros((height, width), dtype=bool)
# 根据拜耳阵列模式标记G通道位置
if bayer_pattern == 'RGGB':
# G通道位置:(偶数行, 奇数列) 和 (奇数行, 偶数列)
g_mask[::2, 1::2] = True # 偶数行,奇数列
g_mask[1::2, ::2] = True # 奇数行,偶数列
elif bayer_pattern == 'BGGR':
# G通道位置:
raw图G通道
最新推荐文章于 2025-12-03 17:07:06 发布

最低0.47元/天 解锁文章
1259

被折叠的 条评论
为什么被折叠?



