-separate lowers tones?

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

-separate lowers tones?

Post by snibgo »

"-separate" followed by "-combine" significantly lowers the middle tones of an image.

For example:

Code: Select all

convert logo: log.tiff

convert logo: -channel RGB -separate log_%d.tiff
convert log_0.tiff log_1.tiff log_2.tiff -channel RGB -combine logCopy.tiff
log.tiff and logCopy.tiff should be identical, but the copy is significantly darker. (Workaround: insert "-gamma 2.2" or "-set colorspace RGB" before the "-separate".)

Leaving off the "-channel RGB" makes no visible difference. From experiments with photographs, it seems the darkening is occurring during the "-separate".

6.7.9-6 2012-09-13 Q16 on Windows.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -separate lowers tones?

Post by magick »

Add -set colorspace sRGB to your command line. The channels are stored as linear grayscale. Once you combine them you must hint that the channels are non-linear sRGB rather than linear RGB.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -separate lowers tones?

Post by snibgo »

Add -set colorspace sRGB to your command line.
Which command line: the separate, combine or both? Adding it just before the "-separate" or after the "-combine" doesn't help. Adding it before the "-combine" makes it worse.

The documentation (http://www.imagemagick.org/script/comma ... hp#combine ) says the commands are inverse, but that seems to be untrue. "-separate" doesn't simply copy pixel values, but instead converts from (assumed sRGB) non-linear values to linear values. However, "-combine" then copies the pixel values with no conversion. "Identify" then says the resulting logCopy.tiff is sRGB, although it isn't.

As I mentioned in the OP, adding "-set colorspace RGB" before the "-separate" doesn't convert the pixel values.

This seems to be a bug in either the documentation or the behaviour of one of the "-separate" or "-combine" commands.
Last edited by snibgo on 2012-10-26T20:51:30-07:00, edited 1 time in total.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -separate lowers tones?

Post by fmw42 »

When you now (in current versions of IM as of about IM 6.7.8.3) separate channels of an sRGB color image, they become linear grayscale rather than in the old days as nonlinear (sRGB) grayscale. To fix this now do something like

convert image -set colorspace RGB -separate separateimages_%d.png

or with any other colorspace conversion as well

convert image -set colorspace RGB -colorspace HSL hslseparateimages_%d.png

When combining

convert separateimages_*.png -combine -colorspace sRGB combined.png

or

convert hslseparateimages_*.png -set colorspace HSL -combine -colorspace sRGB hslcombined.png


The issue is to trick IM to treat the input color image as if it was already linear, so that IM does not convert to linear.

See

viewtopic.php?f=4&t=21269
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -separate lowers tones?

Post by snibgo »

Agreed. But I think the "-combine" behaviour is wrong. It copies the pixel values from the separate greyscale files without conversion, but the resulting file (according to "identify") is sRGB.
snibgo's IM pages: im.snibgo.com
Post Reply