I am struggling a bit with a problem, I was wondering if someone with more experience might notice what am I doing wrong:
I have a binary file of 6'266'880 bytes that contain an image saved with an unknown Bayer pattern.
About the image I know that it's format is 2176x1920 pixels, and that it has a bit_per_pixel = 12.
I would like to discover which one is the bayern format used to save the image, so I thought to convert it with cv2.cvtColor(src, cv2.COLOR_BayerGR2BGR) using all the conversion options provided by the cv2 library for bayern input, which are:
cv::COLOR_BayerBG2BGR
cv::COLOR_BayerGB2BGR
cv::COLOR_BayerRG2BGR
cv::COLOR_BayerGR2BGR
Until I would have found the one that provide as output a "clean" image.
However, I get always something dirty like this Img after cv2 conversion
Here's the code that I am using:
import numpy as np
import matplotlib.pyplot as plt
import cv2
pixels = np.fromfile("0000.raw", dtype = 'uint8')
""" CONVERT THE BYTE STREAM, EVERY PIXEL HAS 12 BIT, SO BYTE HAS TO BE SPLITTED AND PUTTED IN A UINT16 VARIABLE"""
data = pixels
data1 = data.astype(np.uint16)
data1[::3] = data1[::3]*256 + data1[1::3] // 16
data1[1::3] = (data[1::3] & 0x0f)*16 + data[2::3]
result = np.ravel(data1.reshape(-1,3)[:,:2])
img = result.reshape(2176, 1920)
convertedImage = cv2.demosaicing(img_scaled, cv2.COLOR_BayerGR2BGR)
cv2.imshow("tmp", convertedImage)
cv2.waitKey(0)
Also, Here there are 10 samples of the same image saved as raw file, and for each of them a json with their properties
Any idea on what else to try to convert it? Or either some other approach to find the bayern format?
Aucun commentaire:
Enregistrer un commentaire