Page 1 of 1

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

Posted: 2010-12-21T17:22:57-07:00
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.

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

Posted: 2010-12-21T19:01:51-07:00
by fmw42

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

Posted: 2010-12-21T19:48:16-07:00
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.

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

Posted: 2010-12-21T20:54:22-07:00
by fmw42
why don't you post an example of your approach

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

Posted: 2010-12-22T00:14:08-07:00
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.

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

Posted: 2010-12-22T03:52:46-07:00
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.