Problem converting gray image to sRGB

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
marc
Posts: 3
Joined: 2014-09-23T02:20:19-07:00
Authentication code: 6789

Problem converting gray image to sRGB

Post by marc »

Hi,

using ImageMagick 6.7.7-10 2014-03-06 Q16 on Linux Mint 64-bit.

I have a problem with converting some gray image to sRGB. I have lots of images in different colorspaces which already contain color profiles. Then I have a sRGB profile which I use to convert the gray images to sRGB using the following command:

Code: Select all

convert input.jpg -profile sRGB.icm -type TrueColor output.jpg
This works well for most images but for some images the resulting image is still grayscale (identify says "Type: Grayscale"). It seems to have something to do with that the original image already contains a sRGB profile which I do not understand because it is a grayscale image!?

I tried forcing the colorspace to sRGB with the following command:

Code: Select all

convert input.jpg -profile sRGB.icm -colorspace sRGB -type TrueColor output.jpg
This yields a sRGB image but the image is much too light. I do not understand this either because as the image already contains a color profile I cannot understand why using the "-colorspace sRGB" shifts colors here.

Of course I can try to convert the image to an explicit "gray" profile like Gray Gamma 2.2 and then convert it back to sRGB using this command:

Code: Select all

convert input.jpg -profile gray_gamma_22.icm -profile sRGB.icm -type TrueColor output.jpg
This works. However, this only works for gray images and it also is another conversion which is not necessary.

I would like to have a command which works for any image and colorspace and converts any image to a sRGB JPEG. What should I use?

Test files are here: http://www.mesw.de/downloads/gray_to_srgb_problem.zip

Best regards
Markus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem converting gray image to sRGB

Post by snibgo »

I don't understand what you are trying to do. Perhaps you have input.jpg which contains one 8-bit channel and you want to convert it to out.jpg which has three equal 8-bit channels.

Code: Select all

convert -type truecolor out.jpg
This does the job. As I recently wrote on another thread: To see how many channels are saved by IM, always use an external tool such as exiftool. IM only tells us how many channels an image (not a file) has, after it has been read in.
snibgo's IM pages: im.snibgo.com
marc
Posts: 3
Joined: 2014-09-23T02:20:19-07:00
Authentication code: 6789

Re: Problem converting gray image to sRGB

Post by marc »

Thanks for your answer. However, the command you suggest does not work for me. See the following session transcript:

Code: Select all

$ identify -format "%[colorspace]" input.jpg
Gray
$ convert input.jpg -type truecolor output.jpg
$ identify -format "%[colorspace]" output.jpg
Gray
$ exiftool output.jpg | grep "Color Mode\|Color Components"
Color Mode                      : Grayscale
Color Components                : 1
You see, the resulting image still only contains one Grayscale channel.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem converting gray image to sRGB

Post by snibgo »

IM v6.8.9-5 on Windows 8.1 gives 3 components for me. You are using a very old version of IM. I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
marc
Posts: 3
Joined: 2014-09-23T02:20:19-07:00
Authentication code: 6789

Re: Problem converting gray image to sRGB

Post by marc »

snibgo wrote:IM v6.8.9-5 on Windows 8.1 gives 3 components for me. You are using a very old version of IM. I suggest you upgrade.
My version is about half a year old and is the "official" package of my Linux distribution. I would not call that "very old". But you are right, the newest Windows version gives different results. For me it seems as if this was this bug:

viewtopic.php?f=3&t=24814

This means it would have been fixed in 6.8.8-3.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem converting gray image to sRGB

Post by snibgo »

That's the compilation date. v6.7.7-10 was released in June 2012. See changelog.txt in your IM installation directory.
snibgo's IM pages: im.snibgo.com
Post Reply