Convert Lab tif to color profile (CMYK or RGB)

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?".
Locked
Mike_B
Posts: 6
Joined: 2019-12-27T08:13:18-07:00
Authentication code: 1152

Convert Lab tif to color profile (CMYK or RGB)

Post by Mike_B »

Hi.
I am trying to do simple conversion from Lab TIF file to an CMYK TIF file using some custom CMYK icc color profile. But as a result, I got the same TIF in the Lab color space. Please advise what I'm doing wrong:

Code: Select all

convert -set colorspace lab -size 20x20 xc:lab\(112,25,-50\) -profile ISOcoated_v2_eci.icc test.tif
I tried to check the inverse transform (from CMYK to Lab) for some tif files (which has embedded color profiles) and this occurs as expected... but what about conversion from Lab?
Thanx in advance!

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

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by snibgo »

What version of IM, on what platform?
Mike_B wrote:... conversion from Lab TIF file ...
But your command has no input file.

If you have an input file that is Lab, then you might convert using "colorspace"...

Code: Select all

convert in.tiff -set colorspace Lab -colorspace CMYK out.tiff
... or using profiles:

Code: Select all

convert in.tiff -set profile Lab-D50-Identity-elle-V4.icc -profile ISOcoated_v2_eci.icc out.tiff
In both cases, we first tell IM that the image is Lab, then we convert to CMYK. In general, don't mix the two methods.

Lab-D50-Identity-elle-V4.icc is from https://github.com/ellelstone/elles_icc ... r/profiles .
snibgo's IM pages: im.snibgo.com

Mike_B
Posts: 6
Joined: 2019-12-27T08:13:18-07:00
Authentication code: 1152

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by Mike_B »

Snibgo, thank you for your reply!
snibgo wrote:
2019-12-27T08:54:12-07:00
What version of IM, on what platform?
I used the latest available version of ImageMagick (7.0.9) and tried on linux, macos and windows with the same result. Let's continue to use the syntax for Windows command line.
snibgo wrote:
2019-12-27T08:54:12-07:00
But your command has no input file.
Yes, but I just create it in memory by provided command '-set colorspace lab -size 20x20 xc:lab(112,25,-50)' that make an Lab image 20x20 pixels and fill it by Lab color = 44, 25, -50 (light purple). If you think that it does matter than we can firstly write that image to file:

Code: Select all

convert -set colorspace lab -size 20x20 xc:lab(112,25,-50) in.tiff
Now we get Lab file 'in.tiff' for testing purpose.
snibgo wrote:
2019-12-27T08:54:12-07:00
If you have an input file that is Lab, then you might convert using "colorspace"
Yes, I know that. And that conversion work fine for me. But I need convert Lab image to custom RGB or CMYK profile to get right colors in resulting file and exactly this still does not work as expected.
I thought that for the lab color, we do not need to specify the source profile, but only the destination profile is enough (as for images with a built-in profile). I tried to downloaded Lab-D50-Identity-elle-V4.icc and test your command

Code: Select all

convert in.tiff -set profile Lab-D50-Identity-elle-V4.icc -profile ISOcoated_v2_eci.icc out.tiff
but it does not work correctly: after the conversion, we really get a CMYK file but the color completely unpredictable. We got C=4, M=95, Y=67, B=17 (red) instead of expected ~ C=71, M=70, Y=0, B=0 (purple).
I uploaded used profile ISOcoated_v2_eci.icc for tests.
Any suggestion?

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

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by fmw42 »

You must put -set colorspace after creating/or reading an image. But it is not needed. Consider:

convert xc:"lab(112,25,-50)" x.tif
identify x.tif
x.tif TIFF 1x1 1x1+0+0 16-bit CIELab 270B 0.000u 0:00.001

convert xc:"lab(112,25,-50)" -colorspace cmyk x.tif
identify x.tif
x.tif TIFF 1x1 1x1+0+0 16-bit CMYK 286B 0.000u 0:00.000

Note that on Unix systems (Linux, MacOSX), you need to enclose such color definitions with quotes.

Similarly:

convert xc:"lab(112,25,-50)" txt:
# ImageMagick pixel enumeration: 1,1,65535,cielab
0,0: (28784,6425,-12850) #707019190000 cielab(43.9216%,9.80392%,-19.6078%)

convert xc:"lab(112,25,-50)" -colorspace cmyk txt:
# ImageMagick pixel enumeration: 1,1,65535,cmyk
0,0: (33854,32754,0,17345) #843E7FF2000043C1 cmyk(52%,50%,0%,26%)

Mike_B
Posts: 6
Joined: 2019-12-27T08:13:18-07:00
Authentication code: 1152

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by Mike_B »

fmw42 wrote:
2019-12-27T12:52:31-07:00
You must put -set colorspace after creating/or reading an image. But it is not needed
OK, I will take this into account.
fmw42 wrote:
2019-12-27T12:52:31-07:00
convert xc:"lab(112,25,-50)" -colorspace cmyk x.tif
Thanks, fmw42, but as I wrote before converting to CMYK just by using '-colorspace cmyk' does not solve my problem... I need convert Lab to custom (!!) CMYK or RGB profile. While I do not see a way to do it ... maybe it's a bug?

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

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by fmw42 »

You can do that if you have an appropriate LAB profile. See snibgo's comments above for a link to one and his command.

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

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by snibgo »

You are using IM v7. I suggest you use "magick", not "convert".

The commands work as expected in IM v6.9.9-50:

Code: Select all

convert -set colorspace lab -size 20x20 xc:lab(112,25,-50) in.tiff
convert  in.tiff txt:
All pixel are cielab(43.9216%,9.8024%,-19.6094%).

Code: Select all

convert in.tiff -set profile Lab-D50-Identity-elle-V4.icc -profile ISOcoated_v2_eci.icc out.tiff
convert out.tiff txt:
All pixels are cmyk(74%,70%,2%,0%). This is close to your "expected" result.

V7.0.8-64 gives the same results for the first two commands but different results for the last two commands, with all pixels cmyk(4.43427%,95.1247%,66.9261%,17.3205%).

I conclude there is a bug in v7.0.8-64.
snibgo's IM pages: im.snibgo.com

Mike_B
Posts: 6
Joined: 2019-12-27T08:13:18-07:00
Authentication code: 1152

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by Mike_B »

fmw42 wrote:
2019-12-27T14:18:28-07:00
You can do that if you have an appropriate LAB profile. See snibgo's comments above for a link to one and his command.
I already tried to use it, the result is unsatisfactory (wrote above). Logically, imagemagick for a color in the lab format should not require a profile. A color profile is needed only for device-dependent color spaces to convert color to the profile connection device-independent space (still the same Lab, XYZ etc.) Does such a profile (something like Lab to Lab conversion) exists at all? By the way, it is also impossible to convert with imagemagick to a custom profile from other device-independent color spaces (XYZ, xyY etc.)
snibgo wrote:
2019-12-27T14:22:17-07:00
The commands work as expected in IM v6.9.9-50
Thank you for paying attention to this! I will try version 6.

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

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by fmw42 »

Profiles are also used to change colorspaces, not just for display.

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

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by snibgo »

Mike_B wrote:Logically, imagemagick for a color in the lab format should not require a profile.
Profiles often use Lab as the connection space, so I can see what you mean. But IM always converts images from one profile to some other profile. If an input image doesn't have a profile, we need to assign one before we can convert it to another profile. In this case, we assign a Lab profile, which also uses Lab as a connection space so it has null transformations.
Mike_B wrote:Does such a profile (something like Lab to Lab conversion) exists at all?
Yes, the Lab profile I showed.
Mike_B wrote:By the way, it is also impossible to convert with imagemagick to a custom profile from other device-independent color spaces (XYZ, xyY etc.)
It is possible. If your image is encoded as XYZ: first, assign an XYZ profile eg from Elle's list I linked above. Then convert to whatever profile you want.

If your image is encoded as xyY then first use "-set colorspace xyY -colorspace XYZ" to convert from xyY to XYZ, then convert that with profiles. This is one of the rare cases that we use both "-colorspace" and "-profile" in the same command.
snibgo's IM pages: im.snibgo.com

Mike_B
Posts: 6
Joined: 2019-12-27T08:13:18-07:00
Authentication code: 1152

Re: Convert Lab tif to color profile (CMYK or RGB)

Post by Mike_B »

Thank you all for your help!
I rollback to version 6 and it solved my problem.

Code: Select all

convert xc:"lab(112,25,-50)" -set profile Lab-D50-Identity-elle-V2.icc -intent absolute -profile ISOcoated_v2_eci.icc txt:
Result on ImageMagick 7.0.9-11:
0,0: (2028,62941,47537,7786) #07ECF5DDB9B11E6A cmyk(3.09453%,96.0418%,72.5368%,11.8807%)

Result on ImageMagick 6.9.10:
0,0: (45981,46184,0,0) #B39DB46800000000 cmyk(70%,70%,0%,0%)

Unfortunately it seems really a bug in version 7 which makes it impossible to use for such type of conversions.

Locked