chaiNNer-org / chaiNNer

A node-based image processing GUI aimed at making chaining image processing tasks easy and customizable. Born as an AI upscaling application, chaiNNer has grown into an extremely flexible and powerful programmatic image processing application.
https://chaiNNer.app
GNU General Public License v3.0
4.48k stars 280 forks source link

Is there an option to covert Pro Photo image to sRGB? #2117

Open zelenooki87 opened 1 year ago

zelenooki87 commented 1 year ago

Have a big gallery. (>20 000 pics) Is there a way to convert 48bit pro photo colored images(Tiff) to srgb cause models doesnt properly output this color space. Yea I know last solution would be to reconvert those images to srgb in other third party software, but is this doable in chainner?

RunDevelopment commented 1 year ago

sRGB is pretty much just a gamma applied to linear RGB. So assuming that your TIFF images are linear RGB, you can use the Gamma node like this to convert linear RGB to sRGB:

image

Uncheck "Invert Gamma" to convert sRGB to linear.

zelenooki87 commented 1 year ago

BIG thanks you included SCUNET native support. I have tried and when I setup node like your screenshot, output is more brighter. do I need to uncheck invert Gamma? Btw, I was not so clear. I batched via some actions files in PS in 16 bit mode in ProPhoto color space. Maybe is fastest solution to be visualy same output, to batch again and in action set only to convert color space to sRGB.. thanks

RunDevelopment commented 1 year ago

ProPhoto color space

Ah, I assumed that this was just a name, but it's an actual color space. We need to explicitly add support for that. Do you have an example file that you could share? It would be nice to have a TIFF file with the issue and a PNG (or screenshot in your photo editor) of what the TIFF is supposed to look like. Then I can add support for it.

zelenooki87 commented 1 year ago

yes, here you are files https://mega.nz/folder/O3oykZxa#M5PJfO9R-z1w-qBhOJD_YQ btw, srgb format is reccomended for web upload and original file (TIFF) should look like identical as preview on your pc once you download it.

RunDevelopment commented 1 year ago

Okay, this is interesting. Chainner isn't the only program that handles ProPhoto RGB incorrectly. Here's a screenshot of how the TIFF image is displayed in Paint.net, Gimp, Windows Photo, and chaiNNer.

image

Gimp and Windows Photo display it correctly, Paint.net and chaiNNer do not.


What is the issue

These difference occur because ProPhoto RGB has a larger gamut than sRGB. Basically, ProPhoto has a higher dynamic range for colors. So interpreting the raw ProPhoto RGB values as sRGB is just wrong.

How to fix this

The fix is to apply the ProPhoto color profile. This SO answer explains it pretty well. Unfortunately, the library they reference produces different results compared to Gimp and others...

Here, I implemented the SO answer in the Color Profile node: image

Very nice saturated colors. Still wrong. I played around with the colour package a little, and I just couldn't get it to produce anything near the target.

So I'm pretty much stuck now. I am decidedly not an expert on colors, so I have no idea what else to do here...

hurodal commented 1 year ago

I don' have programming skills but I know well the color management stuff.

For a color conversion a special math has to be applied to the image, and it's not just a gamma curve. This can be done with a 3x3 matrix as the easiest way. It's like the channel mixer in Photoshop. You just have to know the particular matrix for any given source color space (Prophoto) and destination color space (sRGB).

The link posted by RunDevelopment explains it very well, and also the other link to an online matrix calculator. In fact a color space conversion node would be great.

In case you don't know them, there are free libraries out there that I guess can be used into chainner:

The color accuracy of these two is good enough for 95% of the tasks, but the OS has it's own color engine (both windows and OSX and both are excellent in terms of color accuracy), and Adobe offers their engine for free: https://helpx.adobe.com/photoshop/kb/adobe-color-management-module.html

All these will allow to perform color conversions from one color space to another, but when both are implemented into Chainner. Another different thing would be chainner reading the image's color profile and let the user convert to any installed profile. This would require to deal to many different kind of profiles. Anyway, these libraries allow so.

mrjschulte commented 7 months ago

Found this issue and I can help @RunDevelopment ! Let me know how you want to catch up about this?

hurodal commented 7 months ago

That is great news. I guess you are asking @RunDevelopment and not me, but if you need something from me, I'm here to help.

RunDevelopment commented 7 months ago

Let me know how you want to catch up about this?

That would be nice. I know very little about color management, so it would be amazing, if you could find a solution for this issue.

hurodal commented 6 months ago

What do you need exactly? I don't have programming skills but I know the theory and the equations for it...

zelenooki87 commented 5 months ago

Is there any progress on this topic?

By the way, the ProPhoto RGB color space has a significantly larger color gamut than the sRGB color mode, especially at higher bit depths. ProPhoto belongs to the RGB color space.

If implementing native support for ProPhoto is not feasible, would it be possible to introduce a manual color profile transform option using a node? In this node, the user could specify the input ICC profile (in this case, ProPhoto) and the output ICC profile (in this case, sRGB, if that's the only RGB color space the software can handle).

If this is technically impossible, could some code be "borrowed" from ImageMagick (imagemagick convert) to perform the conversion in the background?

This would be a huge help, thank you very much!

zelenooki87 commented 4 months ago

In this node, the user could specify the input ICC profile (in this case, ProPhoto) and the output ICC profile (in this case, sRGB, if that's the only RGB color space the software can handle).

Maybe I wasn't clear. I meant that the user would import the ICC profile file, for example from C:\Windows\System32\spool\drivers\color or downloaded from the internet, and choose which one they want to use. If the Python code is not limited by that?

zelenooki87 commented 4 months ago

Please, dear devs, is it possible to implement this? For example, it would be interesting to introduce SDR to HDR conversions or color space changes to ACES, and so on. Thank you.

joeyballentine commented 4 months ago

Are you able to convert these outside of chaiNNer and then process them as normal? This probably won't be implemented by us any time soon

zelenooki87 commented 4 months ago

@joeyballentine Yes, of course I can perform color conversion in other editors (like Photoshop and similar). However, it would be very desirable for chaiNNer to convert to sRGB before the upscaling node. Because, without conversion, if the input files are in other color spaces, the colors of the output file will be drastically changed. And the file will be practically unusable. This would be especially important for me for larger batch renders, where, for example, I want to run 10,000 files through chaiNNer and I'm not sure what their input color space is.

It would also be convenient if chaiNNer could also support raw files. If this is not theoretically feasible, then let's rely on, for example, ImageMagick again, and borrow some code or the convert.exe file that would do this in the background for us. For example, files with extensions like .DNG, then Nikon raw .nef extensions, Sony .arw, and other manufacturers, should be supported. So that we are not limited to compressed formats only.

Thank you very much for your understanding and everything you do for us.

Regards