Page 1 of 1

How to correctly convert RAW-image into JPG?

Posted: 2020-01-10T10:22:35-07:00
by hryhorii
Hi,

I have tried a lot of Magick.NET things to convert RAW-image into JPG (I need to convert DNG by the way) but I can’t get a satisfactory result. You see, it's brighter then source:

Image

Original picture looks like:

Image

DNG-source: https://drive.google.com/file/d/1m5NTRZ ... sp=sharing

Here is my C# code for a simple console app:

Code: Select all

static void ConvertToJpgWithMagickImage(string dngPath, string savePath)
{
    try
    {
        using (MagickImage image = new MagickImage())
        {
            var magicReadSettings = new MagickReadSettings
            {
                Format = MagickFormat.Dng,
                ColorSpace = ColorSpace.sRGB
            };

            image.Read(dngPath, magicReadSettings);
            image.Quality = 100;
            image.TransformColorSpace(ColorProfile.SRGB, ColorProfile.AdobeRGB1998);
            image.Settings.Compression = CompressionMethod.LosslessJPEG;
            image.FilterType = FilterType.Sync;
            image.Format = MagickFormat.Jpg;
            image.Write($"{savePath}_converted_with_magickimage.jpg");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}
I really like ImageMagick for .NET and hope there is any way to do this close to the original. Any suggestions would be appreciated!

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-10T13:02:15-07:00
by snibgo
Your images don't show for me.

What version of IM?

IM uses a delegate to read DNG files. The delegate might be built-in libraw, or external programs dcraw or ufaw-batch. Which delegate does your IM use?

You say you have a "Original picture". What does that mean?

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-11T12:50:42-07:00
by hryhorii
Hm, here're direct links to images:
I use the latest Magick.NET-Q8-x64 NuGet package. I try to convert an original image using the code posted in the first post.

Original picture - the unconverted picture with DNG extension. Converted - the picture with JPG extension, converted with Magick.NET.

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-11T13:16:19-07:00
by fmw42
Your "original" link goes to a JPG, not a raw image.

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-11T13:21:15-07:00
by snibgo
Your "original picture" is a JPG, not DNG. So where did it come from? Did the camera make that JPG, or some other software?

There are two obvious differences: colour and tone. I suspect the colour difference is due to different colour balances being used. If your IM uses an external delegate such as dcraw, you can edit delegates.xml to suit, eg insert "-w" to tell dcraw to use the camera white balance.

The other major difference is tone. This is likely due to whatever make your "original" jpg prettifying the image. For example, this almost merges the rope and background top-left. Manufacturers don't publish their "prettifying" algorithms.

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-11T13:27:20-07:00
by hryhorii
fmw42 wrote:
2020-01-11T13:16:19-07:00
Your "original" link goes to a JPG, not a raw image.
snibgo wrote:
2020-01-11T13:21:15-07:00
Your "original picture" is a JPG, not DNG. So where did it come from? Did the camera make that JPG, or some other software?
Sorry, I didn't notice it. Here's the link to the real original on google disc: https://drive.google.com/file/d/1m5NTRZ ... sp=sharing Hope you can see it now.
snibgo wrote:
2020-01-11T13:21:15-07:00
There are two obvious differences: colour and tone. I suspect the colour difference is due to different colour balances being used. If your IM uses an external delegate such as dcraw, you can edit delegates.xml to suit, eg insert "-w" to tell dcraw to use the camera white balance.

The other major difference is tone. This is likely due to whatever make your "original" jpg prettifying the image. For example, this almost merges the rope and background top-left. Manufacturers don't publish their "prettifying" algorithms.
Thanks for the very interesting info. I'll try it on Monday.

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-11T15:41:38-07:00
by snibgo
With IM v7.0.8-64 on Windows 8.1, using libraw as the delegate:

Code: Select all

magick rope.dng -resize 600 rope_dng_mgk.jpg
Image
The result looks reasonable to me.

Re: How to correctly convert RAW-image into JPG?

Posted: 2020-01-13T02:17:49-07:00
by hryhorii
The problem was in Magick.NET-Q8 version. I used the latest and it converts my DNG-images into JPG with that yellow tone that wasn't related to original pictures.

And when I rolled back to 7.14.5 version everything began to work as I expected - JPG-result looks close to original DNG from the camera.

Sounds like a problem or bug, do I need to report it somewhere?