简体   繁体   English

Python中RGB数据到Bayer格式的转换

[英]RGB data to Bayer format conversion in Python

I am currently working on a HIL Simulation.我目前正在研究 HIL 模拟。 I am using CARLA platform, There exist a RGB camera sensor, by which I am able to get a RGB data values (3D array (Height, Width, 3(RGB))) for the Image frame.我正在使用 CARLA 平台,存在一个 RGB 相机传感器,通过它我能够获取图像帧的 RGB 数据值(3D 数组(高度、宽度、3(RGB)))。 I want to send the data over network layer, .....我想通过网络层发送数据,.....

The Question is I would like to convert the RGB format to a Bayer format array.问题是我想将 RGB 格式转换为拜耳格式数组。 I am not well aware of the details with the Bayer raw filter.我不太了解拜耳原始过滤器的细节。 I notice that there is a Opencv flag for Bayer to RGB conversions but not the other way round.我注意到拜耳到 RGB 的转换有一个 Opencv 标志,但反之则不然。 I need this format to reuse the libraries on the image unpacking or the server side.我需要这种格式来重用图像解包或服务器端的库。

Any suggestion regarding conversion from RGB to bayer format would help me a lot moving this project further.任何关于从 RGB 转换为 bayer 格式的建议都会帮助我进一步推动这个项目。

Ref (Pictorial ref - I want to do it from right to left)- https://theailearner.com/2018/10/28/bayer-filter/参考(图片参考 - 我想从右到左做)- https://theailearner.com/2018/10/28/bayer-filter/

Here's a naive code to generate the first bayer pattern in that link you have (GRBG?):这里有一个天真的代码来生成该链接的第一Bayer模式您有(GRBG?):

import numpy as np # of course

im = cv.imread(...)
(height, width) = im.shape[:2]
(B,G,R) = cv.split(im)

bayer = np.empty((height, width), np.uint8)

# strided slicing for this pattern:
#   G R
#   B G
bayer[0::2, 0::2] = G[0::2, 0::2] # top left
bayer[0::2, 1::2] = R[0::2, 1::2] # top right
bayer[1::2, 0::2] = B[1::2, 0::2] # bottom left
bayer[1::2, 1::2] = G[1::2, 1::2] # bottom right

This emulates image formation.这模拟图像形成。 You might want to lowpass ( GaussianBlur ) the input slightly, or else you'll see funny aliasing artefacts.您可能希望稍微低通 ( GaussianBlur ) 输入,否则您会看到有趣的混叠伪影。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM