File Exchange

image thumbnail

DNG to RGB Converter

version 1.0.0 (6.83 KB) by Rafael Villamor Lora
This function converts RAW image images file to RGB (Truecolor) Images. It follows Rob Sumner's "Processing RAW Images in MATLAB" guide

8 Downloads

Updated 30 Apr 2019

View License

Commercial Grade Digital cameras incorporate built-in image processing software that makes photographs look aesthetically pleasing to the human eye, but and introduce non-linearities and compression artifacts that hinder their use as scientific instruments. However, their image sensor originally produce linear outputs. Access to this linear data requires specific image processing which is detailed in this function.

Here we follow Rob Sumner's (2014) "Processing RAW Images in MATLAB" guide. The full document can be found here: http://www.rcsumner.net/raw_guide/RAWguide.pdf

Our implementation of the guide mimics the following workflow (that happens under-the-hood within the camera's built-in software). The function outputs all the intermediate image steps, including the original raw file and the camera settings.

Function:
[lin_srgb, lin_rgb, balanced_bayer, lin_bayer, raw, camSettings] = dng2rgb(imagename)

Inputs:
- imagename [string] = Original raw (DNG) file name (e.g. 'DSC_0001.dng')

Outputs:
- lin_srgb [nxmx3 double][0-1] = 16-bit, RGB image that has color corrected and exists in the right color space
- lin_rgb [nxmx3 double][0-1] = RGB image from balanced_bayer using demosaic()
- balanced_bayer [nxm double] [0-1] = White Balanced-linearized raw data (Bayer array)
- lin_bayer [nxm double] [0-1] = Linearized raw data with black level and saturation level corrected
- raw [nxm double] [0-1] = Raw data (Bayer array) from the camera's sensor
- camSettings [structure] = Contains camera settings used for convertion from RAW -> lin_srgb

Cite As

Rafael Villamor Lora (2020). DNG to RGB Converter (https://www.mathworks.com/matlabcentral/fileexchange/71420-dng-to-rgb-converter), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Ha Phu

The black level is not consistent with the value read by the dcraw, so the color of the output image is not totally correct. Second, I have a problem when applying the code with the data set: https://www.kaggle.com/knn165897/s7-isp-dataset, this code doesn't work well, the color is inconsistent with the one from dcraw

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!