Page 1 of 1

Watchout for Greyscale Jpeg!

Posted: 2012-05-17T17:21:56-07:00
by anthony
With teh colorspace changes, and the backporting of some coders from IMv7 (which has true single-channel grayscale images in memory). A inconsistency has developed in JPEG colorspace management.

In older (last year) versions of IM, saving a grayscale image in JPEG, will generate a light weight single channel grayscale JPEG image file format.

An example is... invitation_box.jpg
Image
Newer versions of IM however will save this as a sRGB multi-channel image, in which case the next step has no problems.

Now the problem is this image is marked as 'grayscale' so if you load, color it, and save again. IM still thinks it is grayscale, and IM JPEG saves a grayscale version of the image!

Code: Select all

convert invitation_box.jpg +level-colors navy,lightblue invitation_still_black_and_white.jpg
Image

This I would regard as a bug, though IM does think of it as Grayscale, so realy the bug could be considered to be in +level-colors. I have not tested in IMv7 where this type of this is more common.

The workaround, is to ensure the image is not thought of as grayscale before saving (can be done at any time).

Code: Select all

convert invitation_box.jpg -colorspace sRGB \
         +level-colors navy,lightblue invitation_still_black_and_white.jpg
Image

Note this problem will probably happen for ANY operator that may convert a image marked as being grayscale, to a colored image, in BOTH IMv6 and IMv7.

ASIDE: the example used come from IM Examples, Coloring a Gray-scale Text Image
http://www.imagemagick.org/Usage/text/#coloring_text

Re: Watchout for Greyscale Jpeg!

Posted: 2012-05-17T17:52:57-07:00
by fmw42
The same issue happens with pgm and miff and psd

I would have also thought it would happen with tif as I believe that tif supports grayscale format (and bilevel).

It would seem not a really good thing if IM functions behaved differently with different image formats, especially as one may not know which ones behave this way.

This means that users will always have to add -colorspace sRGB before using any function that "colorizes" grayscale images in some way.

But if the list of such functions is small, then perhaps the functions should be modified. Functions that come to mind are -fill -opaque, -colorize, -tint, +level colors.

Then there are functions that may process each channels separately, such as -channel r -contrast-stretch. For example

This makes no change.
convert invitation_box.jpg -channel r -contrast-stretch 10,10% invitation_cs10_red.jpg

This does the color change.
convert invitation_box.jpg -colorspace sRGB -channel r -contrast-stretch 10,10% invitation_cs10_red.jpg

But I believe that there are not that many of these and the use of -channel r, is an indication to promote to sRGB.

So my question is how many such functions behave this way. If small enough is it worth while to modify the functions in stead of having to add -colorspace sRGB for any such function that colorizes a grayscale image?

What is the intent for IM 7 with respect to more/new channel sensitive functions?

Re: Watchout for Greyscale Jpeg!

Posted: 2012-05-17T18:20:43-07:00
by magick
We can reproduce the problem you reported and have a patch. Look for it in ImageMagick 6.7.7-0 Beta within a day or two. Thanks.