Command Line Read DNG Images

1.6k views Asked by At

After some time, after trying the "tips", "hints", "guesses" and "trials" in here, here, here, here and here, even through the given SO questions in here and others, and using several software in here, here and here, i am still not being able to find a functional example of how to convert a DNG raw image file through command line.

I am not looking for an all case solutions, just a functional command line example converting any given DNG image.

This is the best, but, great, do not run because "one would miss out on that important step" (thanks!).

This is nothing but a "tip", leaving out without any file actually converted. From here, i cannot go further in making the proper conversion required (the image looks too "dark").

The dcraw command line program, require some "configuration" (which one?) for not getting deviation of the colors, and a "shadow ring from the center of the picture to the outside", while comparing its tiff output with the proper Adobe Converter, which is not command line unfortunately (Command Line Call):

dcraw -T filename

The best functional incomplete code for which should be a simple dngread function is the following (Matlab Code):

function img=dngread(filename,options)
%% READ DNG IMAGE FILES

% READ BASIC INFO
info = imfinfo(filename);
info.SubIFDs{1};

% READ COLOR FILTER ARRAY
warning off MATLAB:tifflib:TIFFReadDirectory:libraryWarning
t = Tiff(filename,'r');
offsets = getTag(t,'SubIFD');
setSubDirectory(t,offsets(1));
cfa = read(t);
close(t);

% LINEARIZATION TABLE
%curve = info.SubIFDs{1}.LinearizationTable

% DEMOSAIC COLOR FILTER ARRAY
options.filter='rggb'
img=demosaic(cfa,options.filter);
% Image in here looks "dark"
imshow(img);
2

There are 2 answers

5
informaton On

You can try this function

function [rawData, tinfo]= loadDNG(dngFilename)   
    if(exist(dngFilename,'file'))
        tinfo = imfinfo(dngFilename);
        t = Tiff(dngFilename,'r');
        rawData = t.read();
        t.close();
    else
        if(nargin<1 || isempty(dngFilename))
            dngFilename = 'File';
        end
        fprintf(1,'%s could not be found\n',dngFilename);
        rawData = [];
    end
end

To test it, I downloaded 'L1004235.DNG' from this website and placed it in the same directory as this function.

rawData = loadDNG('L1004235.DNG'); % load it "functionally" from the command line
imtool(rawData);                   % display it as proof of concept.

Reference: I put this code together based on this blog post that you reference and help Tiff.

3
Fimagena On

raw2dng does what you're looking for - Linux command-line tool to convert any raw format (incl. DNG) to DNG/JPG/TIFF.

Please note that conversion/'development' of raw-formats is not a well-defined process - you will get different results with different programmes. Additionally, cameras (esp. mobile phone ones) apply all kinds of processing to their JPG (e.g., sharpening) that is missing from their DNGs.