-fx and -channel

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
Ariel
Posts: 4
Joined: 2017-09-30T09:52:45-07:00
Authentication code: 1151

-fx and -channel

Post by Ariel »

Hello.
Why result of:

Code: Select all

convert 1.png 2.png -channel r -fx "v.r" -channel g -fx "v.g" -channel b -fx "v.b" 3.png
is not looks like 2.png?
In "3.png" red channel - red channel of "2.png", but
In "3.png" green and blue channel - green and blue channel channel of "1.png"!
Please help.Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -fx and -channel

Post by snibgo »

Each "-fx" is an operator that replaces all the images in the current list with a result.

So the first "-fx" replaces both your inputs with a single image. The other "-fx" operators have only one input.
snibgo's IM pages: im.snibgo.com
Ariel
Posts: 4
Joined: 2017-09-30T09:52:45-07:00
Authentication code: 1151

Re: -fx and -channel

Post by Ariel »

Thank you.
I will use:

Code: Select all

convert 1.png 2.png -channel r -fx "v.r" 2.png -channel g -fx "v.g" 2.png -channel b -fx "v.b" 3.png
Or there is a more correct solution for separate processing channels for two images?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -fx and -channel

Post by snibgo »

You command reads the 2.png file three times. There are many ways to read it only once. For example:

Code: Select all

convert 1.png 2.png +write mpr:NUM2 -channel r -fx "v.r" mpr:NUM2 -channel g -fx "v.g" mpr:NUM2 -channel b -fx "v.b" 3.png
snibgo's IM pages: im.snibgo.com
Ariel
Posts: 4
Joined: 2017-09-30T09:52:45-07:00
Authentication code: 1151

Re: -fx and -channel

Post by Ariel »

Thank you. Unfortunately the last option works incorrectly - it sees only red channel from second image too.
Ariel
Posts: 4
Joined: 2017-09-30T09:52:45-07:00
Authentication code: 1151

Re: -fx and -channel

Post by Ariel »

Code: Select all

convert 2.png +write mpr:N2 +delete 1.png mpr:N2 -channel r -fx "v.r" mpr:N2 -channel g -fx "v.g" mpr:N2 -channel b -fx "v.b" 3.png
Now works! tnx.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx and -channel

Post by fmw42 »

I am not sure -fx is channel sensitive (-channel). Operations on the channels is done with the suffix .r, .g, .b on u or v. So I suspect that -channel can be removed.
Post Reply