Page 2 of 2

Re: CMYK jpg to sRGB png

Posted: 2019-05-22T17:43:04-07:00
by fmw42
If your JPG was a proper CMYK image, then adding two profiles would have converted it properly from CMYK to sRGB as in my command. I do not know how your tool extracted the JPG from inside the PDF. If the JPG was imbedded as RGB but the PDF vector shell was coded as CMYK, then the JPG might be tagged as CMYK rather than its proper RGB. Just a guess. Do you have the PDF from which the JPG was extracted. Can you post it? Can you try extracting it with pdfimages? If you can, then what colorspace is obtained from that extracted JPG

Re: CMYK jpg to sRGB png

Posted: 2019-05-22T18:01:58-07:00
by snibgo
By "the colours in bfoz014_1.jpg are screwed up", I meant that when converting that CMYK JPG to sRGB, I can't get the colours to be close to your "correct" version. For example, the woman's shoulder pads are dull green in the "correct" version, but brown (dull yellow) when converted from the CMYK JPG. No messing with profiles will correct that.

I'm not familiar with Apache PDFBox.

From your linked PDF:

Code: Select all

pdfimages -all "Page 13.pdf" p13
The required image is then p13-002.jpg. It is RGB, with no alpha and no profile, and looks the same as your "correct" image.

EDIT: We can get the same "correct" colours by opening the PDF in Adobe Reader, clicking on the image, then running...

Code: Select all

magick clipboard: x.png
... but the background is now black instead of white.

Re: CMYK jpg to sRGB png

Posted: 2019-05-24T18:02:53-07:00
by Phergus
fmw42 wrote: 2019-05-22T17:43:04-07:00If the JPG was imbedded as RGB but the PDF vector shell was coded as CMYK, then the JPG might be tagged as CMYK rather than its proper RGB. Just a guess.
That is a possibility though I think it might present an issue during JPEG decoding as it software expecting 4 channels of data (CMYK) would run out of data if only 3 channels (RGB) were present.
fmw42 wrote: 2019-05-22T17:43:04-07:00Do you have the PDF from which the JPG was extracted. Can you post it?
Attached in previous post.
fmw42 wrote: 2019-05-22T17:43:04-07:00Can you try extracting it with pdfimages? If you can, then what colorspace is obtained from that extracted JPG.
Didn't see that option for IM. Will try that.

Re: CMYK jpg to sRGB png

Posted: 2019-05-24T18:39:27-07:00
by fmw42
pdfimages is not part of ImageMagick. See https://en.wikipedia.org/wiki/Pdfimages.

See snibgo's comments above. He used pdfimages to extract your JPG from inside the PDF.

Re: CMYK jpg to sRGB png

Posted: 2019-05-25T04:22:32-07:00
by snibgo
pdfimages is a program available for many Unix distributions, and Cygwin for Windows. It directly extracts images that are embedded in PDF files, without changing them. Sadly, ICC profiles don't survive the process of writing the PDF then reading from it.

By contrast, IM makes raster images from PDF pages. Each PDF page might contain any number of embedded images. This is useful when we want the output to represent entire page layouts, but a pain when we only want embedded images.

Re: CMYK jpg to sRGB png

Posted: 2019-05-27T07:08:16-07:00
by Phergus
One of my replies apparently didn't make it. Probably one of the frequent network outages we've been experiencing lately.
snibgo wrote: 2019-05-22T18:01:58-07:00 By "the colours in bfoz014_1.jpg are screwed up", I meant that when converting that CMYK JPG to sRGB, I can't get the colours to be close to your "correct" version. For example, the woman's shoulder pads are dull green in the "correct" version, but brown (dull yellow) when converted from the CMYK JPG. No messing with profiles will correct that.
The image and colors seen when viewing the PDF are correct. The PDF matches the published book. It seems clear at this point that IM can't actually convert the CMYK jpegs correctly.
snibgo wrote: 2019-05-22T18:01:58-07:00From your linked PDF:

Code: Select all

pdfimages -all "Page 13.pdf" p13
The required image is then p13-002.jpg. It is RGB, with no alpha and no profile, and looks the same as your "correct" image.
Obviously, pdfimages is converting the image to RGB. Not too surprising as in most cases that would be the correct choice. PDFBox's command line ExtractImages function can do the same thing though it defaults to not converting.
snibgo wrote: 2019-05-22T18:01:58-07:00EDIT: We can get the same "correct" colours by opening the PDF in Adobe Reader, clicking on the image, then running...

Code: Select all

magick clipboard: x.png
... but the background is now black instead of white.
Which makes complete sense. Acrobat Reader must have RGB image data to show it on your monitor and that is what will end up on the clipboard. It would be a stupid waste of memory to hang onto both CMYK and RGB data. Once it is on the clipboard, GIMP, IrfanView, MS Paint, will all display the image directly from the clipboard. The black background is because the clipboard data only has RGB channels.

Re: CMYK jpg to sRGB png

Posted: 2019-05-27T07:56:09-07:00
by snibgo
Phergus wrote:Obviously, pdfimages is converting the image to RGB. Not too surprising as in most cases that would be the correct choice.
Well, if I use IM to create a PDF with embedded CMYK image (with ICC profile), pdfimages creates a CMYK raster file (without ICC profile). I don't know if the profile problem occurs when IM writes the PDF or when pdfimages reads it. (According to pdfimages, the embedded image has an ICC profile, so I don't understand why it doesn't embed the ICC profile in the result.)

pdfimages says your file "Page 13.pdf", image 2, has an ICC profile, and creates a RGB image, so I conclude that the embedded image is RGB.

IM (using the Ghostscript delegate) successfully rasterizes the single page in "Page 13.pdf", giving a RGB image.

IM and Gimp and Microsoft Photo Viewer can all read your bfoz014_1.jpg, and they all show similar wrong colours. I suspect the problem is in the file, not the programs.

Re: CMYK jpg to sRGB png

Posted: 2019-06-02T07:50:42-07:00
by Phergus
IM and Gimp and Microsoft Photo Viewer can all read your bfoz014_1.jpg, and they all show similar wrong colours.
Neither GIMP nor MS Photo Viewer can handle CMYK images so, of course, they show it wrong.
I suspect the problem is in the file, not the programs.
And yet the source PDF displays correctly.

Fortunately, I solved all this a week ago by just pulling the images out of the PDF with PDFBox and then saving them as PNG files. So IM's shortcomings are no longer relevant.

Re: CMYK jpg to sRGB png

Posted: 2019-06-02T08:53:49-07:00
by snibgo
Phergus wrote:Neither GIMP nor MS Photo Viewer can handle CMYK images so, of course, they show it wrong.
You are mistaken. Both programs (and my browser) can convert CMYK images to RGB, which are shown. If the images contain embedded ICC profiles, the colours are correct. If there is no profile, the programs guess at the correct profile. For example:

With embedded profile:

Code: Select all

magick toes.png -profile sRGB.icc -profile JapanColor2001Coated.icc toes_cmyk.jpg
Image

Converted with profile, but profile stripped:

Code: Select all

magick toes.png -profile sRGB.icc -profile JapanColor2001Coated.icc -strip toes_cmyk_noprof.jpg
Image

Those images are CMYK, and are handled by Gimp and Windows Photo Viewer.
Phergus wrote:And yet the source PDF displays correctly.
Yes. There is no problem with the PDF.
Phergus wrote:So IM's shortcomings are no longer relevant.
We are keen to rectify shortcomings. The only shortcoming you have identified is that IM shows wrong colours in bfoz014_1.jpg. But so do the other programs I have tested.