Color space conversion tools

From RidgeRun Developer Wiki


Color Space Conversion Introduction

Typically, when you are developing drivers for any particular sensor you will come across the problem of capturing image data in a not compressed format such as Bayer(RAW8, RAW10, RAW12), YUV, NV12, etc. On this wiki page, 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 analyzing.

Raw Pixels

Note: Looks like this side doesn't exist anymore

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 following 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 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


And convert buffers with:

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

imagej

To install imagej, it is recommended to use the Java bundle obtained from: ImageJ bundled with Java 1.8.0_172

Download "Debayer Image" plugin from https://github.com/ij-plugins/ijp-DeBayer2SX

wget https://github.com/ij-plugins/ijp-DeBayer2SX/releases/download/v.1.3.2/ijp-debayer2sx_v.1.3.2.zip
unzip ijp-debayer2sx_v.1.3.2.zip #unzip inside ImageJ/plugins directory, directory inside ImageJ bundled download.

Open ImageJ

./ImageJ

A new option will appear inside the "Plugins" tab, use the Debayer2 option after opening the Bayer file: Plugins -> Raw Processing -> Debayer2

Contact Us



For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.


Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.