DNG格式图片还原为真正的RGGB拜耳阵列分布
小米手机调成专业模式可以保存为DNG格式,导入到电脑中
import rawpy
import numpy as np
import matplotlib.pyplot as plt
def process_raw_image(raw_path):
with rawpy.imread(raw_path) as raw:
# 获取未经处理的 RAW 数据
raw_data = raw.raw_image_visible.copy()
# 获取 RAW 数据的尺寸
height, width = raw_data.shape
# 创建一个空的 RGB 图像
rgb_image = np.zeros((height, width, 3), dtype=np.uint16)
# 处理红色通道 (R)
rgb_image[0:height:2, 0:width:2, 0] = raw_data[0:height:2, 0:width:2]
# 处理第一个绿色通道 (G)
rgb_image[0:height:2, 1:width:2, 1] = raw_data[0:height:2, 1:width:2]
# 处理第二个绿色通道 (G)
rgb_image[1:height:2, 0:width:2, 1] = raw_data[1:height:2, 0:width:2]
# 处理蓝色通道 (B)rgb_image
rgb_image[1:height:2, 1:width:2, 2] = raw_data[1:height:2, 1:width:2]
return rgb_image
# 读取并处理 RAW 图像
raw_path = 'D:/e/weChat_Receive/WeChat Files/wxid_h9j3rqwr2lan22/FileStorage/File/2024-01/IMG_20240116_113106/IMG_20240116_113106.dng' # 替换为您的 RAW 文件路径
rgb_image = process_raw_image(raw_path)
# 显示图像
plt.imshow(rgb_image)
plt.title('Processed RGB Image from RAW Data')
plt.show()
就能够得到传感器真正拍出来的图,像下面一样
挺好看的