Page 1 of 1

Exchanging channels with a single command?

Posted: 2010-07-15T04:55:14-07:00
by rnbc
Hi!

I feel this is a stupid question, but since I'm stuck in it... let's ask anyway :D

How can I exchange channels in a single convert command?

Code: Select all

convert SDIMa_19045_16bit_master.ppm -channel Red -fx b -channel Green -fx r -channel Blue -fx g +channel SDIMa_19045brg_16bit_master.ppm
This won't work, because operations are done in sequence...

Code: Select all

convert SDIMa_19045_16bit_master.ppm -channel Red -fx 'u ; b' -channel Green -fx 'u ; r' -channel Blue -fx 'u ; g' +channel SDIMa_19045brg_16bit_master.ppm
This will also not work... I'm obviously doing something damn wrong... :(

Suggestions?

Re: Exchanging channels with a single command?

Posted: 2010-07-15T05:26:35-07:00
by Drarakel
Hi,

"-insert" should be ok here. You want the channels to be in order BRG - right? Then try this:
convert input -separate -insert 0 -combine output

Re: Exchanging channels with a single command?

Posted: 2010-07-15T06:28:07-07:00
by rnbc
Hum... it works, but I don't understand how :(

What if I want other orders, like rbg, grb, etc...? :?

Re: Exchanging channels with a single command?

Posted: 2010-07-15T06:41:26-07:00
by rnbc
Found it!

Code: Select all

convert SDIMa_19045_16bit_master.ppm -color-matrix '0 0 1, 1 0 0, 0 1 0' SDIMa_19045brg_16bit_master.ppm
Etc...

Re: Exchanging channels with a single command?

Posted: 2010-07-15T09:46:52-07:00
by fmw42
see -swap and -insert and -reverse at http://www.imagemagick.org/Usage/basics

For BRG
convert image -separate -insert 0 -combine image_brg

For BGR

convert image -separate -reverse -combine image_bgr

For BRG

convert image -separate +swap -combine image_brg


For GRB
convert image -separate -swap 0,1 -combine image_grb

You can do multiply -swaps as well if you want, but each new swap takes the last ordering as 0,1,2 rather than it original ordering.


-color-matrix is also a anther way as you found

Re: Exchanging channels with a single command?

Posted: 2010-07-18T18:21:27-07:00
by anthony
rnbc wrote:Hi!

I feel this is a stupid question, but since I'm stuck in it... let's ask anyway :D

How can I exchange channels in a single convert command?
I would not call this stupid. It is a very difficult question that re-appears every so often.

In fact it was this very question that was part of the reason for the command line change that caused IM v6 development!
see the opening remarks in http://www.imagemagick.org/Usage/basics/