Question about "-combine" with IM 7.0.5-5

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
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Question about "-combine" with IM 7.0.5-5

Post by GeeMack »

Running IM 7.0.5-5 HDRI on Windows 10 64. I've been using the "-combine" operation almost daily for years. The example found at THIS link has always worked for me until this most recent release 7.0.5-5. If I start with this image as input...

Image

Then I run it through these two commands from the example page...

Code: Select all

magick input.png -channel RGB -separate input-%d.png

magick input-0.png input-1.png input-2.png -channel RGB -combine output.png
The output should be an exact reproduction of the original input. Instead what I get is this semi-transparent grayscale image...

Image

I've found that I can make the separated images reassemble properly by adding a "-colorspace sRGB" before "-combine" like this...

Code: Select all

magick input-0.png input-1.png input-2.png -channel RGB -colorspace sRGB -combine output.png
And that is even mentioned in the usage discussion at THIS link. But I've generated literally tens of thousands of images using "-combine" without ever needing a colorspace specifier, and suddenly the behavior has changed. Does anyone know if this is a recent bug, or if it's going to be what we should expect from the default use of "-combine"?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about "-combine" with IM 7.0.5-5

Post by fmw42 »

This works fine for me on IM 7.0.5.5 Q16 Mac OSX, if you add -set colorspace sRGB

Code: Select all

magick input.png -channel rgb -separate tmp.png
magick tmp-0.png tmp-1.png tmp-2.png -set colorspace sRGB -combine new.png
Without it, I get your same results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about "-combine" with IM 7.0.5-5

Post by fmw42 »

I believe the reason for the difference is that in IM 6, each grayscale image actually has 3 channels. IM takes the information for the output from the first image in the input sequence, therefore the result in a 3 channel (by default sRGB) image.

In IM 7, each image from the separate is a single channel grayscale image. Therefore without setting the colorspace, it assumes the output should also be a single channel grayscale image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Question about "-combine" with IM 7.0.5-5

Post by snibgo »

I haven't got 7.0.5-5 so can't test but I suspect Fred is correct, that in this version greyscale images have only one channel.

As another implication, I expect this sentence in Porting to ImageMagick version 7 is now true:
Reading gray-scale images generate an image with only one channel. If that image is to then accept color the "-colorspace" setting needs to be applied to expand the one channel into separate RGB (or other) channels.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Question about "-combine" with IM 7.0.5-5

Post by GeeMack »

snibgo wrote: 2017-04-28T04:54:01-07:00As another implication, I expect this sentence in Porting to ImageMagick version 7 is now true:
Reading gray-scale images generate an image with only one channel. If that image is to then accept color the "-colorspace" setting needs to be applied to expand the one channel into separate RGB (or other) channels.
Also on that page it mentions that the "+combine" option requires an argument. I'm not familiar with "+combine", and I haven't found anything describing what it is supposed to do. An experiment shows me that using "+combine sRGB" will properly combine the three grayscale images into the colored output I would expect from "-combine" in previous versions, even without setting or specifying channels or colorspace. I don't know if it's the correct use of "+combine", but this does seem to work...

Code: Select all

magick input.png -separate input-%d.png

magick input-0.png input-1.png input-2.png +combine sRGB output.png
Until version IM7.0.5-4 the "-combine" operator took whatever I would give it, and apparently assumed the output should be a RGB combination of the input images in the order given. Adjusting the command to accommodate these changes isn't difficult, but I have a handful of scripts that work with previous versions but don't work now. If I have to change them all I'd like to know where we're headed so I don't have to change them too often.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about "-combine" with IM 7.0.5-5

Post by fmw42 »

I think that -combine should be smart enough to have a default colorspace of sRGB. The whole purpose of it is to convert multiple grayscale images into a color image. If it sees 3 inputs, then it should default to sRGB. If it sees 4 inputs, it should default to CMYK. I suggest you repost this to the Bugs forum.

+combine is different, but I do not recall what it does.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Question about "-combine" with IM 7.0.5-5

Post by snibgo »

I agree with Fred. When "-combine" has 3 inputs, it should assume sRGB. When 4, it should assume CMYK. (I suppose with 5 it might assume CMYKA, and I don't care what it assumes for other numbers of inputs.)
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Question about "-combine" with IM 7.0.5-5

Post by snibgo »

EDIT to my comment above. That comment applies when the 3 or 4 inputs are grayscale (eg the outputs from "-separate").

Perhaps "-combine" is intended for the general case, when inputs might have any number of channels, eg there are two inputs, one with 2 channels and the other with 7, so the intention is to create an image with 9 channels. If this is the intention, then the default situation might need further refinement.
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: Question about "-combine" with IM 7.0.5-5

Post by fmw42 »

I think -combine is limited to 4 non-alpha (grayscale) channels. To create more than 4 channels, I believe the intent was to use -channel-fx. See the porting docs http://imagemagick.org/script/porting.php#cli. But currently, it only works to make multichannel images in MPC format. The next step is to get it to work to import/export to TIFF
Post Reply