Difference between revisions of "RAW12"

From apertus wiki
Jump to: navigation, search
Line 64: Line 64:


  cat image.raw12 | dd bs=256 skip=73728 | ./metadatareader
  cat image.raw12 | dd bs=256 skip=73728 | ./metadatareader
====Understanding the RAW12 file format====
While reading a RAW12 image file such as one given at [[files.apertus.org/AXIOM-Beta/snapshots/clipped_wall-BSProt8282-gainx1-offset2047-80ms-01.raw12]], the following points are to be taken into consideration:
* each sensor cell stores 12 bits of data and there is no header information in file. This means that RAW12 files should have pixel data from byte 0. For image size of 4096 x 3072, the file size is thus 4096 x 3072 x 12 = 150994944 bits = 18 MB.
* Information is stored in row major order. Hence the first row is RGRGRGRGRG.... (for 4096 items) and after this, it would be GBGBGBGB.... (for 4096 items) and so on. (for RGGB bayer pattern)
A suggested way to extract the bayer channel values is to read the file as binary and treat the cell values 3 bytes at a time. This will encapsulate the values as [RG][RG][RG]... sets for the odd rows and [GB][GB][GB]... for even rows.
For each such set ([RG] or [GB]), the representation is as follows:
[[File:Bayer_bits.png]]
This representation is for odd rows. On even rows, R is swapped by G and G by B bits (for RGGB).
Here, R11 is the MSB of the 12-bit data for Red channel and consecutively, R0 is the LSB. A similar argument goes for G11 and G0.
For getting values of 12 bit channels, the following is a plausible way:
* For red channel:
RedChannel = First8bits<<4 | (Second8bits & 0x0F);
* For green channel:
GreenChannel = (Second8bits & 0xF0)<<4 | Third8bits;
As always, Red channel is to be swapped with Green Channel and Green Channel with Blue Channel for even rows. (for RGGB)

Revision as of 12:59, 18 March 2018

1 Raw16

1.1 Format Specifications

  • no header, little endian, 16bit (12msb padded with 4lsb zeroes)
  • starting at the top left, with 3072 rows of 4096 columns
  • the data is in bayer pattern RG/GB
  • optional image sensor registers dump (128 x 16bit, big endian) appended

RAW12 uses less space than RAW16 but contains identical image data and has no downsides. So we recommend using RAW12 instead (see below).

1.2 Opening in Photoshop

  • rename the file extension from ".raw16" to ".raw"

Raw16-ps.jpg

1.2.1 Samples

XZ compressed sample files (use 7Zip to uncompress under windows: http://www.7-zip.org/)

http://vserver.13thfloor.at/Stuff/AXIOM/ALPHA/RAW/

1.2.2 Metadata block

To display the metadata (optional image sensor registers dump (128 x 16bit, big endian) appended) from a RAW16 file:

cat image.raw16 | dd bs=256 skip=98304 | ./metadatareader 

The DNG converter expects the register block to be present so if it has not been saved with the image in camera:

To append an empty metadata block (sensor registers):

(cat old.raw16; dd if=/dev/zero bs=256 count=1) > new.raw16

To append an existing register block dumped into a file:

cat old.raw16 some.reg > new.raw16

2 RAW12

2.1 Format Specifications

  • no header, little endian, 12bit (leaves out the 4 lsb zeros of RAW16)
  • starting at the top left, with 3072 rows of 4096 columns
  • the data is in bayer pattern RG/GB
  • optional image sensor registers dump (128 x 16bit, big endian) appended

2.2 Samples

http://files.apertus.org/AXIOM-Beta/snapshots/

2.3 Quick debayer

cat test.raw12 | convert \( -size 4096x3072 -depth 12 gray:- \) \( -clone 0 -crop -1-1 \) \( -clone 0 -crop -1+0 \) \( -clone 0 -crop +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 0,1 +swap -combine test_color.png

2.4 Conversion to RAW16

Convert RAW12 -> RAW16 with imagemagick:

convert -size 4096x3072 -depth 12 gray:input.raw12 -depth 16 gray:output.raw16

2.5 Conversion to DNG

Convert RAW12 -> DNG with raw2dng:

raw2dng file.raw12

Output will be file.DNG; width is assumed 4096, height is auto-detected from file size. For more options, run raw2dng without any arguments.

2.6 Metadata handling

Show metadata from a raw12 file (without converting it):

raw2dng file.raw12 --dump-regs

or, with metadatareader:

cat image.raw12 | dd bs=256 skip=73728 | ./metadatareader

2.7 Understanding the RAW12 file format

While reading a RAW12 image file such as one given at files.apertus.org/AXIOM-Beta/snapshots/clipped_wall-BSProt8282-gainx1-offset2047-80ms-01.raw12, the following points are to be taken into consideration:

  • each sensor cell stores 12 bits of data and there is no header information in file. This means that RAW12 files should have pixel data from byte 0. For image size of 4096 x 3072, the file size is thus 4096 x 3072 x 12 = 150994944 bits = 18 MB.
  • Information is stored in row major order. Hence the first row is RGRGRGRGRG.... (for 4096 items) and after this, it would be GBGBGBGB.... (for 4096 items) and so on. (for RGGB bayer pattern)

A suggested way to extract the bayer channel values is to read the file as binary and treat the cell values 3 bytes at a time. This will encapsulate the values as [RG][RG][RG]... sets for the odd rows and [GB][GB][GB]... for even rows. For each such set ([RG] or [GB]), the representation is as follows:

Bayer bits.png

This representation is for odd rows. On even rows, R is swapped by G and G by B bits (for RGGB). Here, R11 is the MSB of the 12-bit data for Red channel and consecutively, R0 is the LSB. A similar argument goes for G11 and G0.

For getting values of 12 bit channels, the following is a plausible way:

  • For red channel:
RedChannel = First8bits<<4 | (Second8bits & 0x0F);
  • For green channel:
GreenChannel = (Second8bits & 0xF0)<<4 | Third8bits;

As always, Red channel is to be swapped with Green Channel and Green Channel with Blue Channel for even rows. (for RGGB)