在Python中读取并显示RAW10/V4L2_PIX_FMT_SRGGB10('RG10')媒体格式

问题描述 投票:0回答:1

V4L2_PIX_FMT_SRGGB10 ('RG10') 媒体格式属性如下:

每个颜色分量存储在一个 16 位字中,其中 6 个未使用的高位用零填充。 所以深度是

深度:10(10位扩展到16位,6个MSB位中有0) 类似 000000xx xxxxxxxx

每个像素由 2 种颜色 R 和 G 组成,因此步幅是像素之间的距离,如果我们想从一个像素移动到下一个像素,那么 长度是 Rlow + Rhigh + Glow + Ghigh = 8 + 8 + 8 + 8 =(以位为单位)32或4字节

R 的偏移量为 0 字节,G 的偏移量为 2 字节

我有一个具有以下属性的图像(我假设),我猜这个图像类似于RAW10,我只需要知道如何在python中使用正确的参数读取和显示这个图像?

我附上了下面的图片: https://drive.google.com/file/d/1tmxDUUG4iiuXGHhezZkszmCMx1_uUlY_/view?usp=drive_link

图像尺寸如下, 宽度=4056,高度=3040

image-processing video-processing
1个回答
0
投票

我尝试阅读这篇文章,并想分享我到目前为止所得到的东西 - 也许你或其他一些勇敢的 StackOverflower 可以改进它:

#!/usr/bin/env python3

import numpy as np
import cv2 as cv

# Define width and height, open file and reshape
w, h = 4056, 3040
d = np.fromfile('SRGGB10test_fin.raw.raw', dtype=np.uint16).reshape((h,w))

# Red is every second row, every second column, starting from 0
R = d[0::2,0::2]
# Green is every second row, every second column, starting from 1
G = d[1::2,1::2]
# Synthesize Blue channel as being equal to Green
B = G

# Stack channels to make BGR image amd save
BGR = np.dstack((B,G,R))
cv.imwrite('result.png', BGR)

这给出了:

如果你旋转并增强对比度,你会得到这个:

© www.soinside.com 2019 - 2024. All rights reserved.