Difference between revisions of "Working with raw image data"

From ElphelWiki
Jump to: navigation, search
Line 24: Line 24:
 
==<font color='darkblue'>Displaying</font>==
 
==<font color='darkblue'>Displaying</font>==
 
===ImageMagick===
 
===ImageMagick===
* Camera settings: 2592x1936 JPEG, actual pixels available: 2608x1940
+
* Camera settings: 2592x1936 JPEG, actual valid pixels - 2596x1940, pixels read - 2608x1940:
 
  <font size='2em'>convert -size 2608x1940 -depth 8 -endian MSB -normalize gray:test.raw -compress lzw result.tiff</font>
 
  <font size='2em'>convert -size 2608x1940 -depth 8 -endian MSB -normalize gray:test.raw -compress lzw result.tiff</font>
 
* Camera settings: 2592x1936 JP4, actual pixels available: 2592x1936
 
* Camera settings: 2592x1936 JP4, actual pixels available: 2592x1936
Line 33: Line 33:
 
===bayer2rgb program===
 
===bayer2rgb program===
 
* Available [https://github.com/jdthomas/bayer2rgb here].
 
* Available [https://github.com/jdthomas/bayer2rgb here].
* Camera settings: 2592x1936 JPEG, actual pixels available: 2608x1940
+
* Camera settings: 2592x1936 JPEG:
 
  <font size='2em'>bayer2rgb -w 2608 -v 1940 -b 8 -f GRBG -m AHD -t -i test.raw -o test.tiff</font>
 
  <font size='2em'>bayer2rgb -w 2608 -v 1940 -b 8 -f GRBG -m AHD -t -i test.raw -o test.tiff</font>
 
The result is a colored tiff image. Pixel values are linear.
 
The result is a colored tiff image. Pixel values are linear.
  
 
 
==<font color='darkblue'>Processing</font>==
 
 
===Python===
 
===Python===
* Camera settings: 2592x1936 JPEG, actual pixels available - 2608x1940:
+
* Camera settings: 2592x1936 JPEG:
 
  <font size='2em'>''#!/usr/bin/python3''
 
  <font size='2em'>''#!/usr/bin/python3''
 
  from PIL import Image
 
  from PIL import Image
Line 48: Line 45:
 
  img = Image.frombytes('L', imgSize, rawData)
 
  img = Image.frombytes('L', imgSize, rawData)
 
  img.save("result.jpeg")# can give any format you like .png</font>
 
  img.save("result.jpeg")# can give any format you like .png</font>
 +
 +
The result will be a grayscale image.
 +
 +
 +
 +
==<font color='darkblue'>Processing</font>==
 +
...
 +
 +
[[Category:393]]
 +
[[Category:raw image data]]
 +
[[Category:bayer pixel array]]

Revision as of 12:34, 12 January 2018

Downloading

  • Available options (channels can be 0..3):
# set receiving buffer size in 4kB pages (thus 4096 equals to 16MB)
echo {size} > /sys/devices/soc0/elphel393-mem\@0/buffer_pages_raw_chn2
# start from the N-th frame position in buffer. Currently, 0 or 1
echo 1 > /sys/devices/soc0/elphel393-videomem\@0/video_frame_number
# initiate transfer, wait for X-th frame (X - absolute frame number), 0 = no waiting
echo X > /sys/devices/soc0/elphel393-videomem\@0/membridge_start2
# copy to file
cat /dev/image_raw2 > /tmp/test.raw
# see in hex
hexdump /tmp/test.raw
# copy to PC
scp /tmp/test.raw user@address:/path/
  • Minimal:
echo 4096 > /sys/devices/soc0/elphel393-mem\@0/buffer_pages_raw_chn2
echo 0 > /sys/devices/soc0/elphel393-videomem\@0/membridge_start2
cat /dev/image_raw2 > /tmp/test.raw


Displaying

ImageMagick

  • Camera settings: 2592x1936 JPEG, actual valid pixels - 2596x1940, pixels read - 2608x1940:
convert -size 2608x1940 -depth 8 -endian MSB -normalize gray:test.raw -compress lzw result.tiff
  • Camera settings: 2592x1936 JP4, actual pixels available: 2592x1936
convert -size 2592x1936 -depth 8 -endian MSB -normalize gray:test.raw -compress lzw result.tiff

The result is a grayscale tiff

bayer2rgb program

  • Available here.
  • Camera settings: 2592x1936 JPEG:
bayer2rgb -w 2608 -v 1940 -b 8 -f GRBG -m AHD -t -i test.raw -o test.tiff

The result is a colored tiff image. Pixel values are linear.

Python

  • Camera settings: 2592x1936 JPEG:
#!/usr/bin/python3
from PIL import Image
rawData = open("test.raw", 'rb').read()
imgSize = (2608,1940)# the image size
img = Image.frombytes('L', imgSize, rawData)
img.save("result.jpeg")# can give any format you like .png

The result will be a grayscale image.


Processing

...