CMYK jpg to sRGB png

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?".
douderkirk
Posts: 2
Joined: 2019-05-09T09:36:26-07:00
Authentication code: 1152

CMYK jpg to sRGB png

Post by douderkirk » 2019-05-09T10:39:22-07:00

I'm seeing some color change when converting CMYK jpgs to sRGB pngs. For testing I created a cmyk jpg image with this command:

Code: Select all

convert -size 50x50 pattern:checkerboard -colorspace CMYK -fill "cmyk(38,152,66,1)" -draw 'rectangle 0,0 50,50' cmyk.jpg
Then I try converting it with:

Code: Select all

convert cmyk.jpg -colorspace sRGB rgb.png
But the colors come out wrong. I was able to correctly convert it using the Apple ColorSync Utility, but haven't been able to get it to work through ImageMagick. For reference, here's what I'm seeing:

Original image:
Image

Correct conversion from ColorSync:
Image

Incorrect conversion from ImageMagick:
Image

I'm running ImageMagick 7.0.8-43 on a Mac running Mojave 10.14.4

Any help would be very appreciated. Thank you.

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

Re: CMYK jpg to sRGB png

Post by fmw42 » 2019-05-09T11:04:23-07:00

I do not see any difference in your examples. What is wrong with the "bad" one? Conversion between color spaces is best done with profiles. You should draw in (s)RGB colorspace, then convert to CMYK with profiles. Then when you convert back use profiles. You can draw in (s)RGB colorspace and still specify CMYK color values. IM will convert them for you.

douderkirk
Posts: 2
Joined: 2019-05-09T09:36:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by douderkirk » 2019-05-09T14:03:35-07:00

Well, the profiles were the key. I had tried using a profile when converting from the cmyk image to the rgb image:

Code: Select all

convert cmyk.jpg -profile "AdobeRGB1998.icc" rgb.png
But that didn't work, however the cmyk image didn't have a profile on it. Once I added a profile to the cmyk image, the above command converted it fine.

Thank you very much for the help. And it doesn't really matter now, but here's another image showing the difference, it's fairly subtle:
Image

Phergus
Posts: 9
Joined: 2019-05-21T16:32:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by Phergus » 2019-05-21T16:42:30-07:00

I have a number of CMYK JPEG files that I would dearly love to convert to sRGB images in PNG or whatever. I'm on Windows 10, using ImageMagick 7.0.8. They appear to not have a profile but I'm not sure about that. What is the right sequence of command line options to convert these images? I have been trying every combination of -colorspace and -profile that I can think of with no luck.

Such as:

Code: Select all

magick image.jpg -profile USWebUncoated.icc -profile AdobeRGB1998.icc rgbimage.png
The resulting image looks identical whether in the File Explorer icon view or in ImageMagick's gui viewer.

Thanks for any guidance.

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

Re: CMYK jpg to sRGB png

Post by fmw42 » 2019-05-21T17:04:34-07:00

Just use profiles as you show above. If your input has a CMYK profile, then only use the RGB profile in your command. Use two profiles only when the input has no profile. You can test for profiles with the %[profiles] and %[profile:icc] and %[profile:icm] string formats. see https://imagemagick.org/script/escape.php

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

Re: CMYK jpg to sRGB png

Post by snibgo » 2019-05-21T17:28:12-07:00

Phergus wrote:... I would dearly love to convert to sRGB images ...
Phergus wrote:-profile AdobeRGB1998.icc
If you want sRGB images, use a sRGB profile. AdobeRGB1998 is not sRGB.
snibgo's IM pages: im.snibgo.com

Phergus
Posts: 9
Joined: 2019-05-21T16:32:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by Phergus » 2019-05-21T19:26:28-07:00

fmw42 wrote:
2019-05-21T17:04:34-07:00
Just use profiles as you show above. If your input has a CMYK profile, then only use the RGB profile in your command. Use two profiles only when the input has no profile. You can test for profiles with the %[profiles] and %[profile:icc] and %[profile:icm] string formats. see https://imagemagick.org/script/escape.php
Thanks.

Code: Select all

magick identify -format "%[colorspace]" bfoz014_1.jpg
Returns CMYK.

Code: Select all

magick identify -format "%[profiles]" bfoz014_1.jpg
Returns an error: identify: unknown image property "%[profiles]" @ warning/property.c/InterpretImageProperties/3994.
Which I take to mean that it doesn't have a profile. Doing identify -verbose doesn't mention one either (assuming it would normally).

So going back to calling out both profiles:

Code: Select all

magick bfoz014_1.jpg -profile USWebUncoated.icc -profile AdobeRGB1998.icc test.png
Produces an output image the displays identically as if it was not converted.

Code: Select all

magick identify -format "%[profile:icc]" test.png
Does show that the resulting image has a profile which is Adobe RGB 1998.

I feel like I missing an option that actually tells it to do the conversion.

One other thought. I have been assuming that IM will look in the current directory for the profiles. Perhaps that is incorrect?

Phergus
Posts: 9
Joined: 2019-05-21T16:32:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by Phergus » 2019-05-21T19:28:55-07:00

snibgo wrote:
2019-05-21T17:28:12-07:00
Phergus wrote:... I would dearly love to convert to sRGB images ...
Phergus wrote:-profile AdobeRGB1998.icc
If you want sRGB images, use a sRGB profile. AdobeRGB1998 is not sRGB.
Thank you. I am aware of that but I haven't found an actual sRGB profile file yet. For that matter, the CMYK profile is just one I chose at random. Until I get the right commands that actually converts I'm not really worried about getting the profiles perfect.

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

Re: CMYK jpg to sRGB png

Post by fmw42 » 2019-05-21T19:34:08-07:00

I typically use USWebCoatedSwop.icc for CMYK and you can find sRGB.icc at http://www.color.org/srgbprofiles.xalter

Phergus
Posts: 9
Joined: 2019-05-21T16:32:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by Phergus » 2019-05-21T19:36:36-07:00

FWIW, here is a link to one of the images.

https://www.dropbox.com/s/tq8kiub1b15o3 ... 1.jpg?dl=0

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

Re: CMYK jpg to sRGB png

Post by fmw42 » 2019-05-21T19:42:07-07:00

Works fine for me on IM 6.9.10.46 Q16 Mac OSX

Code: Select all

convert bfoz014_1.jpg -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc bfoz014_1_cmyk_to_srgb.jpg
Image

If on IM7, replace convert with magick.

Phergus
Posts: 9
Joined: 2019-05-21T16:32:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by Phergus » 2019-05-22T05:25:12-07:00

Actually, this is what it should look like.

https://www.dropbox.com/s/ab2xgjkmatfsi ... s.png?dl=0

Curiously, if I display it with a little Java program it looks correct. GIMP can't handle it but has no CMYK support so not unexpected. IrfanView treats it like RGBA. The ImageMagick viewer doesn't get it right. Embedded in a PDF, it displays correctly.

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

Re: CMYK jpg to sRGB png

Post by fmw42 » 2019-05-22T09:09:59-07:00

I have no idea what your java program is doing or even if it is correct code. But as it appears to be displaying wrong. I suspect it is malformed in some way. Profiles should handle it properly. Any further information would have to come from one of the developers who might be able to look at the header to see if it is malformed or not.

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

Re: CMYK jpg to sRGB png

Post by snibgo » 2019-05-22T09:22:52-07:00

Compared to CorrectColors.png, the colors in bfoz014_1.jpg are screwed up, beyond a simple profile mismatch.

How was the jpg image made? From the png file? How do you know the png file is "correct?
Phergus wrote:Curiously, if I display it with a little Java program it looks correct.
It might help if you show that Java program.
snibgo's IM pages: im.snibgo.com

Phergus
Posts: 9
Joined: 2019-05-21T16:32:26-07:00
Authentication code: 1152

Re: CMYK jpg to sRGB png

Post by Phergus » 2019-05-22T17:15:47-07:00

fmw42 wrote:
2019-05-22T09:09:59-07:00
I have no idea what your java program is doing or even if it is correct code. But as it appears to be displaying wrong.
That PNG matches the PDF the JPEG came out of, which matches the published book from the same source. What you posted is what you get if you have CMYK image data and display it as if it were RGBA.
snibgo wrote:
2019-05-22T09:22:52-07:00
Compared to CorrectColors.png, the colors in bfoz014_1.jpg are screwed up, beyond a simple profile mismatch.
They aren't screwed up; the JPEG images are CMYK. It says so right in the metadata of the image and I said this at the beginning. The images do not include a profile but adding one isn't going to fix them as I already knew. The goal was to convert these CMYK images to RGB and not just slap on a profile. My searches here in this forum and elsewhere suggested that IM could do so and that specifying the original and target profiles would make this conversion happen as part of the process.

Most JPEG readers just automatically assume RGB when they open a JPEG file. This is why pretty much nothing on Windows so far will display them correctly. Even Adobe's own Acrobat Pro won't load them correctly as images even though the PDF they came from was created with InDesign. The JPGs are fine(ish). They are just not in a useful format for non-print purposes.
snibgo wrote:
2019-05-22T09:22:52-07:00
How was the jpg image made? From the png file?
The JPEG was extracted from a PDF file created by Adobe InDesign CC using Apache PDFBox
snibgo wrote:
2019-05-22T09:22:52-07:00
How do you know the png file is "correct?
Because I can compare it with the image in the source PDF and with that in the printed book.

As this is a copyrighted publication (though the company that produced it is gone) I won't share the whole thing. I'm not really comfortable with what I have shared but they did fail to fully deliver on their Kickstarter so oh well. Here is the page that the image came from. This page was extracted with Adobe Acrobat Pro 10 and if opened in any PDF reader I tried displays the page as it is seen in the printed book.
https://www.dropbox.com/s/ub0h8vbsikdlh ... 3.pdf?dl=0
snibgo wrote:
2019-05-22T09:22:52-07:00
It might help if you show that Java program.
You can download the code and/or the program from GitHub: TokenTool
Assuming you are on Windows, grab the .exe version as that bundles the required JVM within it. Once installed select File -> Open PDF from the menu and select the PDF above. It will open a window with two images: the background and the two figures. Select the image of the two figures and note how it is displayed. Drag the image from the PDF viewing window into the main TokenTool window. You'll see what it should look like. It's also possible to save the whole image out of TokenTool if desired.

The PNG file linked previously was from a screenshot of the bfoz014_1.jpg image dropped onto a map in MapTool. Also available on GitHub.

Disclaimer: While a contributor to both projects, I am not the lead developer on either.

Post Reply