Watchout for Greyscale Jpeg!

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Watchout for Greyscale Jpeg!

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Watchout for Greyscale Jpeg!

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Watchout for Greyscale Jpeg!

Post 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.
Post Reply