Problems with "-separate -combine" with non-RGB colorspace

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
beorn

Problems with "-separate -combine" with non-RGB colorspace

Post by beorn »

I am getting unexpected results using "-separate" then "-combine"
when the colorspace is HSB.

I have reduced the problem case down to the following:
convert -size 10x10 xc:green -colorspace HSB -separate -combine k.png
I would expect that "k.png" would be the same color as "xc:green", but instead it
comes out as a bright unsaturated green.

When I look at the separate results from "-separate" (on a real image), they
look like kind of what I expect (though in 8-bit mode they don't come close to
combining back right -- all sorts of noisey artifacts).

If I insert and extra "-colorspace HSB" just before the "-combine", the output is
different but still not what I would expect. (I also tried an explicit "-depth 32",
but with no change).

The output from "convert -version" is:
Version: ImageMagick 6.6.6-3 2010-12-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP OpenCL HDRI

(I was trying this earlier with a q16 (?or maybe a q8) version that
clearly had range problems so I tried the HDRI version -- that was
better but still not near what I expect).

So, what's going on? Is this a bug (kind of looks like it to me),
or is there some important little detail that I am missing here?

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

Re: Problems with "-separate -combine" with non-RGB colorspa

Post by fmw42 »

beorn

Re: Problems with "-separate -combine" with non-RGB colorspa

Post by beorn »

Sigh... OK, I just needed to read the next section. Sorry.

So now I use "-set colorspace HSB" (before "-combine) instead of "-colorspace HSB".
Works like a charm.

By the way, my original goal was a different way of making
black transparent by using just the B channel for the alpha; for
the simple image I am dealing with, I can set S to 100% and get a good
anti-aliased transparent image from the original multicolored image.
I don't know how this compares to "-level" or "-alpha shape" approaches.

Thanks for looking at this.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with "-separate -combine" with non-RGB colorspa

Post by fmw42 »

why don't you post an example of your approach
beorn

Re: Problems with "-separate -combine" with non-RGB colorspa

Post by beorn »

Sure, here is what I am now doing:

Code: Select all

convert logo.png -channel RGB -colorspace HSB -separate l%d.png         # separate into HSB components
convert l2.png -level-colors white,black -level 0,100% l3.png           # invert Brightness for the alpha
convert l0.png -level -1,-1 l2.png                                      # create a 100% brightness element of the right size.
convert -set colorspace HSB -channel RGBA l0.png l1.png l2.png l3.png -combine u.png    # magic "-set colorspace ...", recombine images
I don't know how to attach a sample image -- mine is well suited to the above,
with lots of small anti-aliased squares.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problems with "-separate -combine" with non-RGB colorspa

Post by anthony »

Basically the channel images -separate creates are simple gray scale images, and do not contain any information about what color space they will combine together to produce.

The -set colorspace sets the color space of the images without changing the data, so that when -combine merged the images together the result will ben in the right color space.

The -set can be done either before or after the -combine though for a four channel image such as CMYK the colorspace much be set before hand, otherwise -combine might thing you were generating a RGBA image rather than a CMYK image (which uses a different set of channels. As such doing the setting before is the accepted practice.

Regardless of the colorspace of the images given to -combine it will treat them as RGB greyscale channl images for purpose of the operation. If it didn't non-RGB colorspaces would be much more difficult to handle in this simple way.

WARNING: the channel handling example may move into "Color Basics" in the near future, as I try to organise the examples a little better.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply