I am currently working on a HIL Simulation. 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. 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. 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. 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.
Ref (Pictorial ref - I want to do it from right to left)- 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?):
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.