2

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);
Brethlosze
  • 1,533
  • 1
  • 22
  • 41
  • 1
    Please update your post with the real reason that the "raw guide" did not work for you; and keep it professional. – informaton Sep 04 '17 at 18:38
  • In both methods, the image turn out to be "darkened". I think there is a nonlinear filter, a `demosaic`ing stage, and some brightness setup missing. Which one (if not all) and|or in which order is a complete mistery from all the given references. – Brethlosze Sep 04 '17 at 23:34

2 Answers2

1

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.

informaton
  • 1,462
  • 2
  • 11
  • 20
  • 1
    If this does not work, you may want to check out the [raw guide](http://www.rcsumner.net/raw_guide/) again. It sounds and looks like the author's script will load DNG files just fine. However, rather than conveniently including DNG example files, he/she thought it was import for readers to practice converting to .DNG. Since you already have .DNG files, can't you just skip this step? – informaton Sep 01 '17 at 21:40
  • But this code is the same i already made from that "tips" reference!, of course without the check if the file is there (we know it is). I further included the `demosaic` stage, but the image i obtain is much "darker" than the real scene, and with a ring shadow from the center. So the "tip" given there is just the trivial part of the problem. And the code in the "raw guide" do not run. It fails in a multiplication between a `mxnx3` (the image?) by a `nxn` matrix (a filter?), even with the given data (!). – Brethlosze Sep 02 '17 at 01:56
  • 1
    @hyprfrcb Please take another look at this code. It is not the same in a very key part (i.e. 'SubIFD'). I get a much darker image too when including this. You may get more mileage with `imtool` as well. – informaton Sep 04 '17 at 18:39
  • I have the same darkness problem. That is the part in which i am failing. – Brethlosze Sep 04 '17 at 23:25
  • Also, by doing `t.read();` you are reading the thumbnail image stored at the DNG file. At least that is what the reference said. I will check if this is true. – Brethlosze Sep 04 '17 at 23:27
1

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.

Fimagena
  • 321
  • 2
  • 7
  • 1
    Reposting this in slightly shorter form, since it answers the question but the original post got deleted. – Fimagena Sep 04 '17 at 21:26
  • The previous post was truly complete i think... Though i am not sure yet if this tool works (i have to try it :) ) – Brethlosze Sep 04 '17 at 23:23
  • Yes, it does. Make sure you have all the stated dependencies. If you're having issues file a bug with a description. – Fimagena Oct 06 '17 at 19:54