gpt4 book ai didi

Python RAW 图像奇怪的方格图案

转载 作者:太空宇宙 更新时间:2023-11-03 21:59:55 31 4
gpt4 key购买 nike

使用以下 python 读取和显示(灰度)RAW 图像:

import numpy as np
import matplotlib.pyplot as plt
path = 'path\\to\\where\\image\\is\\downloaded'
f = open(path,'rb')
height = 2500
width = 1000
bin_image = np.fromstring(f.read(), dtype=np.uint16)
bin_image.shape = (height, width)
plt.imshow(bin_image)
plt.show(block=True)

我可以找到指向 bayer (RAW) 数据的链接 here bin_image.txt

结果是这张带有奇怪方格图案的图像: enter image description here

我不确定是什么原因造成的?

最佳答案

拜耳图像不像常规 RGB 图像,其中每个像素都有一些红色、绿色和蓝色分量。相反,拜耳图像在每个像素位置具有不同强度的单一红色、绿色或蓝色值。这在很多传感器上都很典型,因此每个像素都可以捕获特定波长的光。 Wikipedia entry on Bayer filters可能会有帮助。

首先,您必须对图像进行去拜耳,即将这些值内插到 RGB,然后您可以将其转换为灰度以供显示。这有 OpenCV 标签,所以假设您使用的是 OpenCV,您可以使用 cv2.cvtColor() 完成这两个步骤。 :

import numpy as np
import matplotlib.pyplot as plt
import cv2

path = 'bin_image.txt'
f = open(path,'rb')
height = 2500
width = 1000
bin_image = np.fromstring(f.read(), dtype=np.uint16)
bin_image.shape = (height, width)
bin_image = cv2.cvtColor(bin_image, cv2.COLOR_BayerBG2RGB)
bin_image = cv2.cvtColor(bin_image, cv2.COLOR_RGB2GRAY)
plt.imshow(bin_image, cmap='gray')
plt.show(block=True)

De-bayered grayscale image

典型的拜耳图像有三种不同的顺序;在 OpenCV 中,它们被列为 BayerBG(最常见)、BayerRGBayerGR。您应该弄清楚您的原始图像以哪种模式存储以获得最佳效果。

关于Python RAW 图像奇怪的方格图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45424917/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com