Hi, I think the problem you have is that in the raw image you have only 1 colour sample per pixel, not 3. You probably want to save a fully sampled RGB image? You could create an RGB image of half the raw resolution (in each dimension), and fill in the RGB values from the Bayer pattern. If you want an RGB image of the same resolution as the raw image, you'll have to "demosaic" the data in some way.Another follow-up,
I've written the following code in an attempt to separate the RGB channels of camera module 3/IMX708:Code:
import timeimport cv2 import numpy as npfrom pprintpp import pprint as ppraw = np.loadtxt('RawData.txt', dtype=int)print('shape: ', raw.shape)print(raw.max())# # convert to 8 bit, as the sensor outputs 10 bits per pixel which was saved as a 16 bit integer.raw = raw >> 2raw = raw.astype(np.uint8)# Now to split the data up into its red, green, and blue components. The# Bayer pattern of the IMX708 sensor is RGGB. In other words the first# row contains alternating red/green elements, the second row contains# alternating blue/green elements:rgb = np.zeros(raw.shape + (3,), dtype=raw.dtype)rgb[0::2, 0::2, 0] = raw[0::2, 0::2] # Red rgb[0::2, 1::2, 1] = raw[0::2, 1::2] # Green rgb[1::2, 0::2, 1] = raw[1::2, 0::2] # Green rgb[1::2, 1::2, 2] = raw[1::2, 1::2] # Blue
However, I think I have made a mistake, because my red and blue layers almost have no colour, even in a well-lit environment when I take an image of a red object.
Perhaps the usual way to save a raw file is as a DNG, so you might use
Code:
picam2.capture_file("test.dng", 'raw')
Statistics: Posted by therealdavidp — Tue Jan 02, 2024 10:05 am