Properly combining color conversions with resizing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
fvm
Posts: 2
Joined: 2017-05-01T06:09:06-07:00
Authentication code: 1151

Properly combining color conversions with resizing

Post by fvm »

Hi,

I'm posed with the problem of how to properly handle files from a very diverse range of input properties, notably regarding color spaces. Now, I've been going through all the documentation on the matter and have found (amongst others) this topic very helpful, as well as the part of the usage exaples on color profiles and tutorials such as this one from Cambridge in Colour and "Color management is for wimps". So, thanks to everybody for contributing to that.

Unfortunately, I'm still left with one matter on which I would appreciate some clarification and it concerns the combination of resizing and conversion of color spaces. There's this part of the usage documentation on resizing and colorspaces, which is clearly noted as 'deprecated', but it's become quite unclear to me which colorspace is best suited for the mathematics of resizing and whether or not to take gamma correction into account. This is especially so when combined with the possibility of being provided with various CMYK images and what have you. For example, is an intermediate color space in order in such cases? Should we leave everything in their own color space whenever possible and just use a conversion to sRGB as the last step?

In short, how should I properly convert color spaces such that the mathematics of resizing work properly (note that I won't be upscaling) and the colors end up as close to intended in sRGB space?

Should I have overlooked the answer, my apologies, but I'm getting a bit overwhelmed with all the different aspects and sometimes apparently contradictory information. :shock:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Properly combining color conversions with resizing

Post by snibgo »

fvm wrote:... it's become quite unclear to me which colorspace is best suited for the mathematics of resizing and whether or not to take gamma correction into account.
Well, for the correct maths, just resize in whatever colorspace you are in. The results will be mathematically accurate.

On the other hand, the colour purist says that all colour blending (which includes resizing, compositing, blurring and sharpening) should be done as if light were being blended. This means doing the operation in linear RGB, not sRGB. Similarly all other colorspaces should be converted to their linear equivalents before the operation, and back afterwards. For CMYK, this would mean converting to a wide-gamut RGB colorspace, linearizing this, doing the operation, and going back the other way.

On the third hand, the pragmatist says that what looks right, is right.

You may also care about sharpness. Bartvander Wolf, Nicolas Robidoux and others worked on this in 2014, creating a bash script using IM, and I wrote it up as page with my own version, as a BAT script: Resampling with halo minimization. Personally, I was impressed with that technique, for downscaling only.
snibgo's IM pages: im.snibgo.com
fvm
Posts: 2
Joined: 2017-05-01T06:09:06-07:00
Authentication code: 1151

Re: Properly combining color conversions with resizing

Post by fvm »

snibgo wrote: 2017-05-02T04:47:28-07:00 Well, for the correct maths, just resize in whatever colorspace you are in. The results will be mathematically accurate.
I'm guessing you're referring to the fact that +1 will be +1 in whatever space we're in?
snibgo wrote: 2017-05-02T04:47:28-07:00 On the other hand, the colour purist says that all colour blending (which includes resizing, compositing, blurring and sharpening) should be done as if light were being blended. This means doing the operation in linear RGB, not sRGB. Similarly all other colorspaces should be converted to their linear equivalents before the operation, and back afterwards. For CMYK, this would mean converting to a wide-gamut RGB colorspace, linearizing this, doing the operation, and going back the other way.
Although complex, that would be the thing I'm looking for.
snibgo wrote: 2017-05-02T04:47:28-07:00 On the third hand, the pragmatist says that what looks right, is right.
Makes sense, but his would lead me down the empirical testing road, which, given the number of images (millions) I have to deal with, I daren't turn into. The fringe edge cases would be very easy to miss, whilst still significant.
snibgo wrote: 2017-05-02T04:47:28-07:00 You may also care about sharpness. Bartvander Wolf, Nicolas Robidoux and others worked on this in 2014, creating a bash script using IM, and I wrote it up as page with my own version, as a BAT script: Resampling with halo minimization. Personally, I was impressed with that technique, for downscaling only.
Awesome, thanks for that and again for the above. As a side note, I'd already started looking for your web page based on links in previous post, but couldn't find it (and overlooking the footer in your posts of course). Really appreciate the effort.

I'll go down this rabbit hole and see where it leads. :D
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Properly combining color conversions with resizing

Post by snibgo »

fvm wrote:I'm guessing you're referring to the fact that +1 will be +1 in whatever space we're in?
Yes, and the average of 0% and 100% is, mathematically, 50%. But the colour purist will say that it should be 50% only when the colorspace is linear, and that the average of 0% and 100% in sRGB is really 72.97%, etc.

Ideally, IM would have two new operators: "-push-colorspace-and-make-linear" and "-pop-colorspace". This is easy when "-colorspace" is used. But when "-profile" is used, we need a colorspace that contains the gamut of all other colorspaces (so it might be xyY or XYZ) but we also need to know how to linearize it (and delinearize). And the operation could create colours in this super-colorspace that aren't inside the gamut of the original colorspace, so we would need to deal with that (presumably with "-intent").
snibgo's IM pages: im.snibgo.com
Post Reply