How to correct inverted CMYK image

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
Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

How to correct inverted CMYK image

Post by Roman80 » 2017-08-28T12:29:16-07:00

Hello,

i've extracted the jpg and icc profile from a pdf. The image seems to have inverted colors. How could i correct the image color?

Thanks in advance
Regards

https://www.dropbox.com/s/mbo7z95o1jgb1 ... k.jpg?dl=0
https://www.dropbox.com/s/7ispvjldpfvvb ... k.icc?dl=0

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: How to correct inverted CMYK image

Post by fmw42 » 2017-08-28T13:45:27-07:00

Your file has no CMYK embedded profile.

Do either of these work for you? I am not sure if your file is corrupted, since these do not work for me

Code: Select all

convert testcase_cmyk.jpg -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc testcase_rgb.jpg

convert testcase_cmyk.jpg -colorspace sRGB testcase_rgb.jpg
If not, then try

Code: Select all

convert testcase_cmyk.jpg -negate testcase_rgb.jpg

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

Re: How to correct inverted CMYK image

Post by snibgo » 2017-08-28T13:56:35-07:00

Roman80 wrote:i've extracted the jpg and icc profile from a pdf.
We could guess at how to undo the damage to this jpg file, but it is probably better to extract it without causing damage.

How did you extract it? What commands? Why is there a separate ICC file?

It would help if you could link to the PDF file.
snibgo's IM pages: im.snibgo.com

Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to correct inverted CMYK image

Post by Roman80 » 2017-08-28T15:40:50-07:00

It comes from a photoshop PDF document, so the icc was embedded.
If I extract the same from an rgb image/PDF, then it works.
I will try the negate command

Regards

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: How to correct inverted CMYK image

Post by fmw42 » 2017-08-28T16:15:09-07:00

If you provide the original PDF document, perhaps we can just convert from that and show you how. Did you really mean PDF and PSD?

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

Re: How to correct inverted CMYK image

Post by snibgo » 2017-08-28T17:34:12-07:00

Roman80 wrote:... so the icc was embedded.
But the ICC isn't embedded in the JPEG.

My point is that you have a JPEG file that is valid but contains wrong data. We might guess what is wrong and how to correct it, but I suspect it can be extracted correctly.

Unless you tell us how you extracted the JPEG and ICC, and ideally link to the PDF, all we can do is guess.
snibgo's IM pages: im.snibgo.com

Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to correct inverted CMYK image

Post by Roman80 » 2017-08-28T21:39:51-07:00

I've attached those pdf files. I extracted it with our lightweight pdf parser which reads the required things without transformation according to the pdf 1-7 reference.https://www.google.at/url?sa=t&rct=j&q= ... 12RpbpRRYg

Both files are photoshop PDFs. The RGB version is correct and also the cmyk
data is the raw data from the pdf, in each pdf there are ICC profiles,
the jpg encoded preview and the original 8BIM Photoshop file.

CMYK version
https://www.dropbox.com/s/ulxgk07l2u71l ... k.pdf?dl=0

RGB version
https://www.dropbox.com/s/t64yay3b1b85z ... b.pdf?dl=0

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: How to correct inverted CMYK image

Post by fmw42 » 2017-08-28T22:12:07-07:00

Your PDF does not show any profiles using

Code: Select all

identify -verbose pdf_cmyk.pdf
So providing and input cmyk profile and output surge profile, this command works for me to convert to sRGB.

Code: Select all

convert pdf_cmyk.pdf -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc test1.jpg
With Imagemagick 7, change convert to magick. If you want a larger pixel dimension image, then add -density before reading the input. For example

Code: Select all

convert -density 300 pdf_cmyk.pdf -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc -profile /Users/fred/images/profiles/sRGB.icc test2.jpg
Alternately, you might extract the image that is imbedded within the vector pdf. If you can do that and create a cmyk jpg with its embedded profile, then post that.

I tried using pdfimages to extract the image, but it is not a jpg and so is extracted as PPM RGB format without profile. So I added an sRGB profile as follows:

Code: Select all

pdfimages pdf_cmyk.pdf ./
convert -000.ppm -profile /Users/fred/images/profiles/sRGB.icc test3.jpg

Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to correct inverted CMYK image

Post by Roman80 » 2017-08-28T23:09:31-07:00

What we want is to
1.) extract the image and ICC from the pdf and
2.) convert or modify it afterwards with ImageMagick

Step 1.) is done, the problem is the step 2.).
With an RGB image/pdf it works like a charm.

If I understand it correctly, then there is no way to directly convert the extracted CMYK image with the extracted ICC?

The PDF include an ICC, which is within an compressed stream.
You could read and verify the ICC when you use the header (http://www.color.org/icProfileHeader.h)

You could find the ICC in the PDF in object (9 0 obj).
The image is in object (10 0 obj)

Regards

Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to correct inverted CMYK image

Post by Roman80 » 2017-08-28T23:27:47-07:00

What i found out is that the embedded jpg image is encoded. So, the question is how I could decode it with ImageMagick?

Here is the description from the PDF reference:
If the image has three color components, transform RGB values to YUV before encoding and from YUV to RGB after decoding. If the image has four components, transform CMYK values to YUVK before encoding and from YUVK to CMYK after decoding. This option is ignored if the image has one or two color components.
Regards

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: How to correct inverted CMYK image

Post by fmw42 » 2017-08-28T23:31:36-07:00

What we want is to
1.) extract the image and ICC from the pdf and
2.) convert or modify it afterwards with ImageMagick
You only need to extract the image with its IC profile. Once you have that, you can change profiles and convert back and forth between CMYK and sRGB. You process of extracting the ICC is corrupting your image. If you can find the ICC profile name from any method, then you know which profile you start with and only need to provide (from an externals source) along with your destination profile, since it does not show to Imagemagick. But you do not need to extract the ICC profile, only find out what it is. Perhaps EXIFTOOL will tell you what profile is associated with the PDF. I have not yet tried that.

Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to correct inverted CMYK image

Post by Roman80 » 2017-08-29T00:30:20-07:00

What do you exactly mean with ICC profile name?

All I get from the ICC is the following:

https://www.dropbox.com/s/v6b6mp21dtuji ... 9.JPG?dl=0

Regards

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

Re: How to correct inverted CMYK image

Post by snibgo » 2017-08-29T00:34:31-07:00

Pdfimages can extract the CMYK image:

Code: Select all

f:\web\im>pdfimages -all pdf_cmyk.pdf pdfx

f:\web\im>dir pdfx*
 Volume in drive F is New Volume
 Volume Serial Number is F8C5-053E

 Directory of f:\web\im

29/08/2017  08:18         3,149,030 pdfx-000.tif
               1 File(s)      3,149,030 bytes
               0 Dir(s)  54,198,243,328 bytes free

f:\web\im>%IM%identify pdfx*
pdfx-000.tif TIFF 1024x768 1024x768+0+0 8-bit CMYK 3.149MB 0.000u 0:00.000
Exiftool finds the ICC profile:

Code: Select all

f:\web\im>exiftool pdf_cmyk.pdf | grep Profile
ICC Profile Name                : U.S. Web Coated (SWOP) v2
So IM can convert the CMYK tif to whatever we want, such as an sRGB png:

Code: Select all

f:\web\im>%IM%convert pdfx-000.tif -profile USWebCoatedSWOP.icc -profile sRGB.icc out.png
snibgo's IM pages: im.snibgo.com

Roman80
Posts: 12
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to correct inverted CMYK image

Post by Roman80 » 2017-08-29T01:17:14-07:00

fmw42 wrote:
2017-08-28T13:45:27-07:00

Code: Select all

convert testcase_cmyk.jpg -negate testcase_rgb.jpg
This seems to work, but which function did i need to call if I use the API not the ImageMagick binaries?

Thanks to all for your great help
Regards

Roman

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

Re: How to correct inverted CMYK image

Post by snibgo » 2017-08-29T01:35:58-07:00

Roman80 wrote:This seems to work, but which function did i need to call if I use the API not the ImageMagick binaries?
Which API? To do what? To negate? Try looking for a function with "negate" in the name. For example, with the MagickCore API, use the NegateImage() function.
snibgo's IM pages: im.snibgo.com

Post Reply