how can i read 10-bit raw image? which contain rgb-ir data

  • Last Update :
  • Techknowledgy :

According to the RGB image you added, I found the CFA order.
The CFA (color filter array) order is:

B | G
   -- --
IR | R

Suggestion : 2

I have read a post with a similar question, but actually doesn't work for me. His image's resolution is 1280×720, file size is 1,843,200 bytes. The camera store 10 bits meta data into 16 bits space for each pixel. Although it is not containing true 16 bits data, but a linear stretching can do the job. What a real 10-bit format raw image is probably encoded like this.,Download the raw file. (The driver doesn't have exposure control feature, the actual image might be over exposure),My raw image is from OV5670 camera and output format is red in R1C2 (GRBG, not 100% sure, the driver is set in that way). Resolution is 1920×1080, size of the file: 2,592,000 bytes. Each pixel is exactly 10 bits.,I have the datasheet but it is confidential. The pixel is format like my graph above. Act means active lines, blk means black lines. The subsampling is using 2×2 binning.

The structure of the sensor pixel is:

╔═══════╦═══════╦═══════╦═══════╗║
B G║...║║8 act║║ G R║...║║dummy║╠═══════╬═══════╬═══════╬═══════╣║...║║║1944║║...║║║active║╠═══════╬═══════╬═══════╬═══════╣║║║║ 8 act║║║║║ dummy║╠═══════╬═══════╬═══════╬═══════╣║║║║ 20║║║║║ blk║╠═══════╬═══════╬═══════╬═══════╣║ 16 act║ 259216║║║ dummy║ active║ dummy║║╚═══════╩═══════╩═══════╩═══════╝

I used this OV5620 datasheet for reference and assumed that the same should be applicable for OV5670. The sheet states that the encoding is 10 bit per pixel which I was able to read directly in matlab with fread(). Also I followed BGGR format as mentioned in the sheet. Then using simple demosaic and scaling I was able to read the image :

% Reading
r = 1920;
c = 1080;

fin = fopen('v4l2srcnew03.raw');
I = fread(fin, r * c, '*ubit10');
I_r = reshape(I, r, c);

%
Demosaic
I_d = demosaic(I_r, 'bggr');

%
Scale
I_d_r = mat2gray(I_d(: ,: , 1));
I_d_g = mat2gray(I_d(: ,: , 2));
I_d_b = mat2gray(I_d(: ,: , 3));
I_bggr_rgb = cat(3, I_d_r, I_d_g, I_d_b);
imshow(I_bggr_rgb)

Suggestion : 3

Rawview will not work directly with binary raw or manufacturer’s raw files.  These files should be converted into standard image file formats (PNG, JPEG, etc.), typically without demosaicing, using Read Raw or LibRaw.,NOTE: Rawview will not work directly with binary raw or manufacturer’s raw files. These files should be converted into standard image file formats (PNG, JPEG, etc.), typically without demosaicing, using Read Raw or dcraw.,Although DNG format offers little advantage when files are demosaiced, it has a significant advantage for measuring,In addition to demosaicing, converting raw images into standard interchangeable image formats may include

Decompanding file based on the companding table in the above link

{
   "dcData": {
      "decompanding_data_source": "https://www.onsemi.com/pub/Collateral/AR0331-D.PDF",
      "decompanding_data_details": "Fig. 19 and Table 9, pp. 20-21",
      "user_comment": "",
      "decompand_type": "piecewise linear",
      "input_code_range_low": [0, 1024, 4096, 32768],
      "input_code_range_high": [1023, 4095, 32767, 65535],
      "output_code_range_low": [0, 1024, 2560, 3456],
      "output_code_range_high": [1023, 2559, 3455, 3967],
      "pedestal": 0
   }
}

Decompanding file based on the customer-supplied “knee points”

{
   "dcData": {
      "decompanding_data_source": "Customer-supplied data",
      "decompanding_data_details": "Input is uncompanded; output is companded",
      "user_comment": "",
      "decompand_type": "piecewise linear",
      "bitshift_first": -4,
      "kneePoints_input": [0, 2048, 65536, 1048576],
      "kneePoints_companded": [0, 2048, 3040, 4001],
      "pedestal": 16
   }
}

We have added an alternate INI input format, which is quite robust and easy to get right. To read with the INI format, the decompanding file extension must be INI. Here is an example of the INI formatted for the same data as the above box.

[dcData]
decompanding_data_source = Customer - supplied data
decompanding_data_details = Input is uncompanded;
output is companded
user_comment =
   decompand_type = piecewise linear
bitshift_first = -4
kneePoints_input = 0 2048 65536 1048576
kneePoints_companded = 0 2048 3040 4001
pedestal = 16