Black and White.. different with new version of IM

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
dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Black and White.. different with new version of IM

Post by dognose »

So, I'm converting an image to black and white..
I'm getting a much darker image now with IM 6.8.2-10
command I'm using: mogrify -colorspace gray image.jpg

Any idea on what's going on here? Has the colorspaces changed?

Image

Version: ImageMagick 6.7.0-0 2011-05-24 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

Image

Version: ImageMagick 6.8.2-10 2013-03-15 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP Modules
Delegates: bzlib djvu mpeg fontconfig freetype gslib jng jp2 jpeg lcms lqr openexr pango png ps rsvg tiff wmf x xml zlib

Image

snibgo
Posts: 12648
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Black and White.. different with new version of IM

Post by snibgo »

I don't use mogrify, but the cure is probably "-set colorspace RGB" to prevent a conversion from sRGB to RGB.
snibgo's IM pages: im.snibgo.com

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: Black and White.. different with new version of IM

Post by dognose »

yeah, that works. I have lots of scripts, is there an easy way to set RBG as the default instead of sRBG gobally?

snibgo
Posts: 12648
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Black and White.. different with new version of IM

Post by snibgo »

No. The issue is that IM thinks that colour images are sRGB, unless told otherwise, but that monochrome images should be RGB.

The problem arises because most image file formats don't have a flag that says whether they are sRGB or RGB, so all software has to guess. Apparently there is a standard somewhere that says monochrome images should be regarded as RGB. As far as I know, IM is the only software that complies with this "standard", which means it is de facto non-standard.

If you compile your own IM, perhaps you can change your local copy.
snibgo's IM pages: im.snibgo.com

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: Black and White.. different with new version of IM

Post by dognose »

Yeah, I do build my own version. So, I guess I'm wondering how to go back to the old behavior. Is there a compile flag?

snibgo
Posts: 12648
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Black and White.. different with new version of IM

Post by snibgo »

Sorry, I don't know.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26050
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black and White.. different with new version of IM

Post by fmw42 »

The issue is that since about IM 6.7.8.3 grayscale images have been linear rather than non-linear. So use -set colorspace RGB -colorspace gray to convert to gray.

See
http://www.imagemagick.org/script/forma ... colorspace
viewtopic.php?f=4&t=21269

dognose
Posts: 267
Joined: 2005-03-08T22:16:37-07:00

Re: Black and White.. different with new version of IM

Post by dognose »

I understand the change, I'm just wondering how to go back to the previous default with out having to downgrade.
This seems like a pretty big change, and I'm seeing a lot of downstream problems caused by this.. It just seems
there should be an easier way to set the default colorspace... than having to set this in hundreds of scripts.

snibgo
Posts: 12648
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Black and White.. different with new version of IM

Post by snibgo »

I see your point.

"-set colorspace RGB" is a kludge, because we use it merely to prevent the conversion from sRGB to RGB. Most colour images are sRGB, and should be processed as such. (Remember that there are other colorspaces such as CIELab and HLS, and conversions to/from these must work correctly.) It seems to me that most monochrome images are also sRGB, and should be processed as such.

If there was some kind of global switch for ImageMagick, I'd like it to mean: "Treat monochrome as sRGB".
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26050
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black and White.. different with new version of IM

Post by fmw42 »

My understanding is that the change was made to follow certain standards that dictate that grayscale images should be linear rather than non-linear. IM is trying to honor such color and grayscale standards that are dictated by those industries.

I had to modify many of my scripts to add a version trap to use -set colorspace RGB before converting to grayscale or other colorspaces and separating channels. So I understand your comments.

The only suggestion I could make might be to have an IM compile time option or IM Environment Variable (see http://www.imagemagick.org/script/resou ... nvironment) that could be used to set conversion to grayscale to non-linear. But this would have to be decided by the IM developer and I do not know how much effort that would involve.

I believe that there is a new setting coming out in the next release, -intensity, that would allow you to convert to linear or nonlinear grayscale (or use before some operator such as -threshold). See http://www.imagemagick.org/script/comma ... #intensity.
But I am not sure that helps your situation. The compile time or Environment Variable seems to me to be the best way to go.

Perhaps you might repost in the Developers forum.

Post Reply