How to correctly convert RAW-image into JPG?

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
hryhorii
Posts: 4
Joined: 2020-01-10T09:06:29-07:00
Authentication code: 1152

How to correctly convert RAW-image into JPG?

Post 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!
Last edited by hryhorii on 2020-01-11T13:28:22-07:00, edited 2 times in total.

snibgo
Posts: 12575
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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?
snibgo's IM pages: im.snibgo.com

hryhorii
Posts: 4
Joined: 2020-01-10T09:06:29-07:00
Authentication code: 1152

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

Post 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.
Last edited by hryhorii on 2020-01-11T13:21:00-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 25944
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Your "original" link goes to a JPG, not a raw image.

snibgo
Posts: 12575
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com

hryhorii
Posts: 4
Joined: 2020-01-10T09:06:29-07:00
Authentication code: 1152

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

Post 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.

snibgo
Posts: 12575
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com

hryhorii
Posts: 4
Joined: 2020-01-10T09:06:29-07:00
Authentication code: 1152

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

Post 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?

Post Reply