Color space conversion tools

From RidgeRun Developer Wiki
Revision as of 19:27, 22 September 2017 by Jjimenez (talk | contribs)

Introduction

Typically, when you are developing drivers for any particular sensor you will come across the problem of capturing image data in a not compress format such as Bayer(RAW8,RAW10,RAW12), YUV, NV12, etc. In this wikipage you will find useful tips to convert from raw images to a compressed format.

RAW Data Viewer

In order to analyze raw image data, you probably will need to display memory dumps of frame buffers, image buffers and uncompressed image files. RawPixels is a web browser based image viewer that will allow you to explore with several settings the frame you are analizing.

Raw Pixels

Bayer 8-bit,10-bit and 12-bit (RAW8,RAW10,RAW12) compression

Python

The following commands can be used in order to convert the RAW image to grayscale PNG.


import numpy as np
from PIL import Image
a = np.fromfile("test.raw",np.uint8,$width*$height,"").reshape(($height,$width))
Image.fromarray(a).save("test.png")

Gstreamer

  • on Gstreamer 1.8, you can use the folllowing command to convert to JPEG
GST_DEBUG=WARNING gst-launch-1.0 -v filesrc location=test0.raw blocksize=42923008  !  "video/x-bayer,format=bggr,width=5344,height=4016,framerate=1/1" ! bayer2rgb ! videoconvert ! avenc_mjpeg ! filesink location=frame.jpeg  -v

Bayer2rgb

Command line utility to convert bayer data to RGB data. Integrates with ImageMagick.

https://github.com/jdthomas/bayer2rgb

git clone https://github.com/jdthomas/bayer2rgb.git
cd bayer2rgb/
make
./bayer2rgb --input=pic.raw --output=pic.tiff --width=1280 --height=800 --bpp=16 --first=RGGB --method=BILINEAR --tiff
convert pic.tiff pic.png
eog pic.png

raw2rgbpnm

Raw2rgbpnm is a tool to to convert bayer data to RGB data. The source code is available on: https://github.com/martinezjavier/raw2rgbpnm

So, run the following commands to download the tool and compile it:

git clone git clone git@github.com:martinezjavier/raw2rgbpnm.git
cd raw2rgbpnm

Open the file raw2rgbpnm.c and change the line 489 with:

int c = getopt(argc, argv, "a:b:f:ghs:wn");

This is to enable the option to extract multiple frames from a file. Now, you can build the application:

make

Important Note: This tool converts from GRBG10 to pnm.


In order to capture 10 buffers and save them in a file, you can run the following pipelines:


Check the buffers with:

./raw2rgbpnm -f SGRBG10 -s 1920x1080 -b 5.0 -n test_1920x1080.bayer output_1920x1080