Exchanging channels with a single command?

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
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Exchanging channels with a single command?

Post 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?
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Exchanging channels with a single command?

Post 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
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Exchanging channels with a single command?

Post by rnbc »

Hum... it works, but I don't understand how :(

What if I want other orders, like rbg, grb, etc...? :?
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Exchanging channels with a single command?

Post 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...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Exchanging channels with a single command?

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Exchanging channels with a single command?

Post 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/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply