dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.48k stars 416 forks source link

Output color mismatch while processing RAW image formats like CR2, CR3, NRW, etc #1364

Open guru248 opened 1 year ago

guru248 commented 1 year ago

Magick.NET version

13.0.0

Environment (Operating system, version and so on)

Windows 11, 22H2, x64

Description

I am trying to generate previews and thumbnails for raw image formats and facing a color mismatch in output for images with the following formats: ARW, CR2, CR3, CRW, DNG, NEF, NRW. Interestingly, the color mismatch happens even without any process performed by Magick.Net. This is the command snippet. var settings = new MagickReadSettings() { AntiAlias = true }; using (var image = new MagickImage(sourceFile, settings)) { ColorProfile currentProfile = (ColorProfile)image.GetColorProfile(); image.Thumbnail(1400, 1400); var format = image.Format; image.Settings.SetDefine(format, "use-default-raw-options", "false"); image.Format = MagickFormat.Jpg; image.WriteAsync(previewPath); }

Here is a screenshot reference for the observer color change: --Edit Removing Screenshot

Steps to Reproduce

dlemstra commented 1 year ago

Have you tried using the DngReadDefines and see if that would resolve your issue?

guru248 commented 1 year ago

Hi, thanks a lot for the input. I used UseCameraWhitebalance = true in DngReadDefines and the yellow shade is removed, but now the output image is a lot darker than the source image. Do you have any solution for that as well? Please find below the (.NEF) source image on the left and processed (.JPG) image on the right. (View the source image in Photoshop for correct color, windows photo viewer beautifies the image within a few seconds)

--Edit Removing Screenshot

dlemstra commented 1 year ago

Maybe OutputColor of DngReadDefines can be used for this?

guru248 commented 1 year ago

Checked with all 7 available DngOutputColor(s), nothing matching with the source file. Is there any other possible solution?

dlemstra commented 1 year ago

Maybe removing the color profile will work? All I know is that with raw files you really need to tweak those settings to get the output that you want. And even then the result might just be what the libraw library is providing.

guru248 commented 1 year ago

Hmm.. Removing the color profile doesn't work either. Messed around quite a bit with the DngReadDefines class. This is happening to almost every Camera Raw images. I can't do a manual change as this is to be used to handle large number of images. Is there any other solution that I could try?

dlemstra commented 1 year ago

You might want to ask your question here also: https://github.com/imagemagick/imagemagick/discussions. But make sure you ask how to do this on the command line since there are no people there who can help you with Magick.NET. And I can then later help you translate this to C# if you need help with that.

guru248 commented 1 year ago

Hmm. Will do that and keep this channel posted as well. Thanks!

dlemstra commented 1 year ago

Is saw that you were wondering how to get the thumbnail from the raw image. You can do that like this in Magick.NET:

var settings = new MagickReadSettings(new DngReadDefines
{
    ReadThumbnail = true,
});

using var image = new MagickImage("input.jpg", settings);
var thumbnailData = image.GetProfile("dng:thumbnail");
using var thumbnail = new MagickImage(thumbnailData.ToByteArray());
guru248 commented 1 year ago

This looks like it will solve my problem with the color, thanks! Will check on this.