Converting colour profile oddity - help please

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
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Converting colour profile oddity - help please

Post by jdc3 »

Usually I edit and produce Tiffs in the ProPhoto colour space. I have a correct colour profile for my monitor installed.

I use this to convert to jpgs for distribution:

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -colorspace lab -depth 8 -colorspace sRGB -unsharp 0x2 -quality 100 "%~n1_fullunsharp.jpg
And the results are spot on without any change in colours (the result is also the same if I use Photoshop). If I remove the -colorspace lab, then the image changes and is not like the original Tiff or Photoshop conversion.

However, when changing to a colour profile that is not sRGB, the results are not correct with -colorspace lab.

This does not work (where I change to the profile of DS colour labs printers):

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\DC-Colour-labs-Frontier-Lustre.icc" -colorspace lab -depth 8 -colorspace sRGB -unsharp 0x2 -quality 100 "%~n1_fullunsharpDSCLabsl2.jpg
If I remove the -colorspace lab, then the results are the same as the Photoshop relative intent conversion, so all seems well, but it isn't like my original so...

...when I change from relative intent to perceptual it gets close:

Code: Select all

magick %1 -black-point-compensation -intent Perceptual -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\DC-Colour-labs-Frontier-Lustre.icc" -depth 8  -unsharp 0x2 -quality 100 "%~n1_fullunsharpDSCLabsl2.jpg
Again, the same result as Photoshop, when using perceptual intent in both, but, note I have removed - colorspace lab. If I include it, it all goes wrong.

So my question is, why do I need the -colorspace lab before changing to 8 bit and then back to a perceptual colour space when converting to sRGB, but when converting to another profile, it messes it up and I get better results just converting to 8 bit in the perceptual colour space it is already in without the intermediate lab color space?

If anyone can shed light on this please, I would be most grateful. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting colour profile oddity - help please

Post by fmw42 »

You should not be using both profiles and -colorspace. In fact, I do not see what good it does not convert to lab and then back to srgb with -colorspace. Using -colorspace after using profiles, in general, just degrades the color accuracy.

Does your input image have a color profile already. If not you need to add one.

What format is your input image?

Can you provide one by posting to some free hosting service that won't change the image and place the URL here.

___________________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

The input image is a tif with the colour profile embedded. Usually this is produced by Lightroom, DxO, or Cyberlink photo director.

If we just look at converting to sRGB, the (non)issue really is the conversion from 16 bit to 8 bit, as it doesn't work without the lab conversion. I can either put in the -colorspace lab before or after the - depth 8. If I do, the result is perfect. I convert the colour profile before this as that is done in 16 bit. It does not work correctly the other way around, similar I think, to the color change when resizing in a perceptual colour space vs coverting to lab first: http://www.imagemagick.org/Usage/resize ... colorspace

I'm happy with that though. Using -colorspace lab when converting to sRGB is perfect with perfect colour conversion.

What I struggle with is converting to any other color profile (I've tried the profile above, I've tried AdobeRGB and others previously). In the above scripts, with the image I was using, a perceptual intent worked ok, but this is not always the case. The image I link to below will only convert to the sRGB colour profile reliably. If I convert to any other, the colours all change too much whether I use the lab conversion, perceptual or relative intent, or anything. I would expect some change, but why does it work so perfectly with sRGB? (Naturally, I am looking at these in a fully colour managed application.)

I'm using ImageMagick-7.0.7-Q16-HDRI, it is the same across all recent versions, it was slightly different many, many versions ago.

The scripts above are the full scripts saved as a Windows batch file on to which I drag and drop the images.

Link to image here: https://1drv.ms/u/s!Atx8lntMOSfZjvV47479koHnBAQl6A Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting colour profile oddity - help please

Post by fmw42 »

I am not an expert on profiles and -colorspace. But if you need to use -colorspace lab and then convert to sRGB, it would seem to me that you should remove the profile from the beginning, then replace the -colorspace sRGB at the end with the profile to sRGB. Or keep the original profile at the beginning and replace the -colorspace sRGB at the end with the sRGB profile again.

How do you know what the proper look should be. How do you convert it in PS?

Perhaps one of the other users with more experience with profiles can give you better suggestions.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting colour profile oddity - help please

Post by fmw42 »

To my eyes, these two are very close and close to the original tiff

Your command

Code: Select all

convert example.tif -quiet -black-point-compensation -intent Relative -profile /Users/fred/images/profiles/sRGB.icc -colorspace lab -depth 8 -colorspace sRGB -unsharp 0x2 -quality 100 example1.jpg
Image

No -colorspace lab and no colorspace srgb

Code: Select all

convert example.tif -quiet -depth 8 -black-point-compensation -intent Relative -profile /Users/fred/images/profiles/sRGB.icc -unsharp 0x2 -quality 100 example2.jpg
Image

The second form may give better results when using a different output profile.

Here is my first command using AdobeRGB for the output profile.

Code: Select all

convert example.tif -quiet -depth 8 -black-point-compensation -intent Relative -profile /Users/fred/images/profiles/AdobeRGB1998.icc -unsharp 0x2 -quality 100 example3.jpg
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting colour profile oddity - help please

Post by snibgo »

What version of IM? Does it have HDRI? On what platform (though that should make no difference)?

Your image is too large for me to download, but I may be able to later today.

As Fred says, using both "-profile" and "-colorspace" is usually a bad idea. These are two different systems for specifying colour spaces.

I don't use Photoshop, so can't check with that. But PS stores its own metadata about colorspaces in tiff files, and IM doesn't update that when it changes colorspaces. This might be the problem you are seeing. Try "-strip" to remove PS metadata.
snibgo's IM pages: im.snibgo.com
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

Edited. This sums it up nicely

Thanks, doing it Fred's way works perfectly, but that means I have to have depth -8 first and I am changing colour profile on the 8 bit image, not 16. Does that matter? Even if it doesn't, see below, there does seem to be a discrepancy?

For AdobeRGB, this:
1.

Code: Select all

magick %1 -depth 8 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\AdobeRGB1998.icc" -unsharp 0x2 -quality 100 "%~n1_fullunsharpAdobe.jpg
Is visually the same as this (all that is different is that -depth 8 is after the profile change):
2.

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\AdobeRGB1998.icc" -depth 8 -unsharp 0x2 -quality 100 "%~n1_fullunsharpAdobe2.jpg
If I substitute sRGB, this:
3.

Code: Select all

magick %1 -depth 8 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -unsharp 0x2 -quality 100 "%~n1_fullunsharp.jpg
Is not the same as this (all that is different is that -depth 8 is after the profile change):
4.

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -depth 8 -unsharp 0x2 -quality 100 "%~n1_fullunsharp2.jpg
The -colorspace lab fixes it for some reason.

P.S. Yes HDRI version on Windows
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

By the way, that is a Skomer vole
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting colour profile oddity - help please

Post by snibgo »

Okay, now I've got a decent internet connection...

"-depth 8" is a setting, not an operation. It doesn't change pixel values. Instead, it affects what following operations do.

"-depth 8" does affect the "-colorspace" operation, but I'm not sure how.

Experiments show that for your image, "-colorspace Lab -colorspace sRGB" has virtually no effect. (The slight effect is probably last-decimal-place.) Inserting "-depth 8" in there does change things.

I don't know why you have "-depth 8" at all. Nor do I know why you have "-colorspace Lab -colorspace sRGB".
snibgo's IM pages: im.snibgo.com
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

How would I change a 16 bit tif to 8 bit without - depth 8?
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

I have - colorspace lab then back to RGB because when resizing, it is better, see here : http://www.imagemagick.org/Usage/resiz ... colorspace

I couldn't preserve the colours when resizing any other way.

I noted that all my resized photos converted colour profile correctly and the ones I didn't resize (and hence didn't have that) converted incorrectly, so I added it back in.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting colour profile oddity - help please

Post by snibgo »

I wouldn't use Lab in this application because there is no need. Nor would I mix "-profile" and "-colorspace" because there is no need, and it adds superfluous complexity.

When an image is saved to an 8-bit format such as JPG, demotion to 8 bits happens automatically. Formats such as PNG can save as 8-bit or 16-bit, so we can use "-depth 8" immediately before saving.

Yes, if you are resizing or sharpening or doing anything that merges pixel values, you may prefer to do the operation in linear colorspace. This is a simple power function when using ProPhotoRGB. For example, as the input is in that colorspace:

Code: Select all

magick _DSC9167LR_Example.tif -evaluate Pow 1.8 -resize 10% -unsharp 0x2 -evaluate Pow %[fx:1/1.8] -profile sRGB.icc out.jpg
Any profile could be used instead of sRGB.
snibgo's IM pages: im.snibgo.com
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

Ok, got it, nearly. Thanks for bearing with me. I have removed -depth 8 and the lab business from all the scripts for any other colour profile, except sRGB. All work, except sRGB.

This does not look like my original*, but would work for other colour profiles:
1.

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -unsharp 0x2 -quality 100 "%~n1_fullunsharp4.jpg
This looks different to the above and the original:
2.

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -colorspace lab -unsharp 0x2 -quality 100 "%~n1_fullunsharp5.jpg
This looks different to the above and the original too:
3.

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -depth 8 -unsharp 0x2 -quality 100 "%~n1_fullunsharp5.jpg
And this looks visually exactly the same as the original*:
4.

Code: Select all

magick %1 -black-point-compensation -intent Relative -profile "C:\Program Files\ImageMagick-7.0.7-Q16-HDRI\sRGB.icc" -colorspace lab -depth 8 -unsharp 0x2 -quality 100 "%~n1_fullunsharp6.jpg
So this bit of unecessary, seemingly pointless code:

Code: Select all

-colorspace lab -depth 8
definitely does something that is only and very much needed with an sRGB color profile conversion and no other.

*I realise that converting to other colour profiles can never be an exact match, but visually 3. is exact on my monitor and others and corresponds with the Photoshop conversion and also with the soft proofing in Lightroom and Cyberlink Photo Director.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting colour profile oddity - help please

Post by snibgo »

"-colorspace Lab" isn't pointless, as it means the "-unsharp" will be done in linear space instead of non-linear sRGB. Another possibility is "-colorspace RGB".

I think doing "-colorspace Lab" without a corresponding "-colorspace sRGB" to put it back to sRGB is bad practice. True, IM knows that JPG can't store Lab values, so IM converts it to sRGB for you, but I think doing it explicitly is better.

"-colorspace Lab" discards the embedded profile (even if you then convert it back to "-colorspace sRGB), so you need to re-embed the profile, eg "-set profile sRGB.icc".

Yes, doing the unsharp in (linear) Lab space gives a different result to doing it in (non-linear) sRGB. I don't know what difference "-depth 8" makes to the "-unsharp" process. But if that makes it "look like" the result from some other process, and that's what you want, than that's good.
snibgo's IM pages: im.snibgo.com
jdc3
Posts: 8
Joined: 2018-12-15T17:38:16-07:00
Authentication code: 1152

Re: Converting colour profile oddity - help please

Post by jdc3 »

Thanks, I'll add that back in for a long as I have the lab bit in then.

All this is for is to look as it does when I edit it in Lightroom or use soft proofing (so that I can edit a photo only export the tif, and always know what my final result will look like if and when I make Jpeg). I'm not trying to emulate Photoshop, I'm trying to do without it!
Post Reply