conversion from xRGB to cmyk imagemagick - imagemagick

I am trying to convert an jpeg image from rgb to cmyk colorspace. Platform is ubuntu 14.04 lts, imagemagick 6.7.7-10
I start with two versions of the image, both rgb. One has an embedded sRGB profile, the other has AdobeRGB. Both are displayer fairly the same in Firefox or Gwenview, quite similar in EOG.
When I convert both images to cmyk using imagemagick:
convert input.jpg -colorspace cmyk test.jpg
then I get two files, that are displayed quite differently. One is considerably darker than the other and both are too dark. It looks like the original profiles have not been used to correctly compute new color values.
One more thing that I observed is, that the resulting image from the xRGB to CMYK conversion still appears to have the AdobeRGB profile embedded, when asking with "identify":
>$ identify -verbose test.jpg | grep -A 5 rofile
Profiles:
Profile-exif: 36738 bytes
Profile-icc: 560 bytes
Description: Adobe RGB (1998)
Manufacturer: Adobe RGB (1998)
Model: Adobe RGB (1998)
Copyright: Copyright 2000 Adobe Systems Incorporated
My understanding is, that a CMYK colorspace cannoth use a RGB profile.
Question: What's wrong in my understanding/usage of ImageMagick or Colorspaces/profiles?

To change both the color model and the ICC profile, I found it necessary to use both -profile and -colorspace. Like this:
convert image.jpg -colorspace CMYK -profile USWebCoatedSWOP.icc image_CMYK_cspace_profile.jpg

Many viewers will not display CMYK JPG correctly unless there is a CMYK profile. If you have an RGB image with a profile, then use profiles to convert rather than -colorspace. In ImageMagick do the following:
convert rgb.jpg -profile path/to/USWebCoatedSwop.icc cmyk.jpg
If the RGB has no profile, then you want to add the rgb profile before the CMYK profile
convert rgb.jpg -profile path/to/sRGB.icc -profile path/to/USWebCoatedSwop.icc cmyk.jpg
Also 6.7.7.10 is rather old and was a release during which many colorspace changes were occurring in ImageMagick. So I strong urge you to upgrade. At the time I write this, it is at 6.9.9.40 and 7.0.7.38.

I think you are confusing colorspaces with profiles. If you just change the colorspace, with -colorspace cmyk, you will only change the colorspace and not the profile, so your existing profile will remain embedded, as you have seen.
I think you need
convert input.jpg -profile cmyk.icm result.jpg
There is an excellent discussion, by Anthony Thyssen, here.

Related

ImageMagick: Invalid ICC profile after conversion

I wrote an application which trims and resizes a bunch of images via ImageMagick. The images are also converted to grayscale. But when I try to open a converted image in Photoshop CC, the following warning appears:
The embedded ICC profile cannot be used because the ICC profile is
invalid, ignoring the profile.
Plus, the image profile is in grayscale, but I want it to be in RGB. How can I achieve this with ImageMagick? I played around with the different parameters, but none worked for me.
This command is currently in use:
convert ${src} -type grayscale -set colorspace RGB -background white -gravity center -extent ${longest}x${longest} ${dest}
Also, this one didn't work either:
convert.exe ${src} -set colorspace RGB -set profile RGB.icc ${dest}
A simple way to force the output PNG to be RGB is to replace $(dest) in your command with PNG24:$(dest), or use PNG32:$(dest) if your image has transparency). If you do this, then your existing RGB color profile will be OK.
You can also try PNG8:$(dest) which will be OK if you have fewer than 256 gray levels, and will result in a smaller file size.

Apply and remove color profile with image magick

I have Tiff images with embedded specific ICC profiles.
I want to convert these by means of imagemagick to JPG-Files.
The JPG-Files should use colorspace sRGB (which is the default) and no embedded profile. In other words I want to apply the profile to the image and want to save it without profile.
When I use a simple convert command like this
convert source.tif target.jpg
the ICC-Profile is preserved in the JPG file. You can remove it with a command like this
convert source.tif +profile "*" target.jpg
But that does not seem to apply the profile.
A -colorspace RGB (or -colorspace sRGB?) should do the trick. But any combination I have tried so far does not work.
Is there a color management guru out there who can give me hint?
`
Some iterations later I come up with this
convert source.tif -profile MY_PROFILE_PATH/sRGB.icc +profile * target.jpg
I used the ICC profile from http://www.color.org/profiles/srgb_appearance.xalter

Incorporating a grayscale TIFF as alpha channel in another TIFF with ImageMagick

When I scan negatives Sane provides 16-bit grayscale files containing infrared information along with the 48-bit RGB files that contain the image information.
Is there any way to combine these two files using ImageMagick in order to obtain a 64-bit RGBA TIFF file whose Alpha channel (infrared) is somehow recognized in Photoshop? Photoshop may detect it as transparency, separate layer or even outright Alpha channel. All these are fine by me.
I haven't been able to obtain much following numerous ImageMagick tutorials on the internet. All TIFFs I get are devoid of transparency information. Libtiff's tiff2rgba does not seem to be of much help either.
My ImageMagick version information:
$ convert --version
Version: ImageMagick 6.8.8-6 Q16 x86_64 2014-02-17 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC
Delegates: bzlib fftw fontconfig freetype jng jpeg lcms lzma png tiff webp x xml zlib
I am not 100% certain I have got your filetypes and needs exactly understood, but if I create a red square TIFF like this:
convert -size 512x512 xc:red rgb.tiff
and a synthetic (faked) greysale gradient to represent your IR image, like this:
convert -size 512x512 -colorspace gray gradient:\#000000-\#ffffff ir.tiff
I can combine them using the IR as opacity like this:
convert rgb.tiff ir.tiff -compose copyopacity -composite out.tiff
to give this, which at least my version of Photoshop CC 2014 understands.
By the way. it seems equally happy creating a Photoshop PSD format directly:
convert rgb.tiff ir.tiff -compose copyopacity -composite out.psd

imagemagick convert CMYK pdf to RGB jpeg or PNG and preseerve colors

I have a cmyk pdf that I am trying to convert to a RGB jpeg or png file but have the colors stay pretty close to what the CMYK version is (compared to how photoshop does it)
I am trying the following command but the colors change drastically from a red color to almost bright neon red and so on.
Here is the command
convert cmykpdf.pdf +profile icc -profile AdobeRGB1998.icc -colorspace sRGB jpegtesting.jpg
Any ideas? or thoughts on how to do this. I tried saving it as a PNG also and same issue occurs and have tried changing sRGB to just RGB
NOTE: It doesnt necessarily need to be RGB jpeg it can even be CMYK jpeg but i just need it to be displayed in the browser correctly and I know safari does not display cmyk jpegs correctly
My goal is to just display a img in the browser that shows the correct color and correct resolution nothing pixilated
The solution is fairly easy, there's nothing voodoo or special about Photoshop's CMYK to RGB nowadays. Imagemagick uses LCMS color engine, which does its job just fine.
But first you'll need to edit delegates.xml file inside IM's directory. Find the line with delegate decode="ps:cmyk" and insert -dUseCIEColor=false near the end, so it looks like that:
<delegate decode="ps:cmyk" restrain="True" command=""#PSDelegate#" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" -dUseCIEColor=false "-f%s" "-f%s""/>
It's necessary because otherwise Ghostscript (before returning pam image to ImageMagick) will perform CMYK to CMYK convertion (assuming DeviceCMYK to be CIEbased CMYK), and you probably don't want that, as colors will shift considerably.
Then try this command:
convert -density 144 cmyk.pdf -profile USWebCoatedSWOP.icc -resample 72 -profile "sRGB Color Space Profile.icm" -quality 100 out.jpg
Here we take cmyk.pdf (rather, temporary pam image that GS returns to IM), assign CMYK profile (just as you do in Photoshop, when you open a file or do it explicitly - therefore choose profile that describes you input CMYK best), convert it to sRGB profile (because I don't think you want AdobeRGB as color space of images for Internet) and save to jpeg. Reduce quality parameter as needed.
One more trick here is additional manual anti-aliasing -- note intermediate resolution of 144 dpi and final 72 dpi. Because I don't think that Ghostscript's anti-aliasing with -dGraphicsAlphaBits=4 is en par with Photoshop's anti-aliasing.
The result of this command looks exactly the same as converted in Photoshop.
You could try this:
convert -negate -colorspace RGB srcfile.jpg outputfile.jpg
Let me know if it works!
Based on previous answers, I finally managed to keep natural colors from a CMYK pdf to a RGB png simply using:
convert -colorspace sRGB cmyk.pdf rbg.png

ImageMagick: convert keeps changing the colorspace to Gray. How to preserve sRGB colorspace?

I have a batch script that converts my PNG-24 (with Transparency) images to 50% and 25% size (for mobile development). Usually these images have colors in them but now I am trying to convert an image that has no colors and ImageMagick keeps changing the colorspace profile to "Gray", which messes up my image in the 3d engine I'm using (Unity).
I have tried forcing it to use type TrueColor, colorspace sRGB, and the sRGB.icc profile (the one included with OSX) but it doesn't seem to care. It still changes it to Gray.
> convert old.png -profile srgb.icc -colorspace sRGB -type TrueColor new.png
> identify *.png
old.png PNG 140x140 140x140+0+0 8-bit sRGB 3.68KB 0.000u 0:00.000
new.png PNG 140x140 140x140+0+0 8-bit sRGB 256c 2.33KB 0.000u 0:00.000
ImageMagick still identifies it as an 8-bit sRGB image but it puts "256c" after it which I'm assuming means it has reduced it down to 256 colors, which I don't want either. When I look at the image in OSX Preview.app, it says it is using the Gray color profile. The image also visually looks a lot different.
Here is the image I'm using: https://dl.dropbox.com/u/59304/old.png
There is a duplicate question here, ImageMagick Reduces Colorspace to Gray, but the answer does not work for me and I don't have enough reputation to comment on his answer, unfortunately. I imagine my case is different because I'm using PNG and not JPG.
Version: ImageMagick 6.8.0-7 2013-01-02 Q16 http://www.imagemagick.org
Features: OpenCL
edit- After reading the ImageMagick forums as specified in one of the answers, it looks like just prepending PNG32: or PNG24: to the output file solves the problem.
The proper way to keep a grayscale PNG as RGB is to use PNG24:result.png
Input:
convert lena.png -colorspace gray PNG24:lenag_rgb.png
identify -verbose lenag_rgb.png
Image: lenag_rgb.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 256x256+0+0
Units: Undefined
Colorspace: sRGB
Type: Grayscale
So as you see above, Colorspace is RGB while the type is Grayscale.
For other image formats such as JPG and TIFF, use -define colorspace:auto-grayscale=false along with -type truecolor.
You may pass -set colorspace:auto-grayscale off to convert to disable automatic conversion of RGB channels to a single grayscale channel.
This solution was not yet available at the time of your question, but was introduced in 2015 with version 6.9.2:
2015-07-25 6.9.2-0 Dirk Lemstra <dirk#lem.....org>
Added -set colorspace:auto-grayscale=false that will prevent automatic conversion to grayscale inside coders that support grayscale.

Resources