smaines wrote:IWhat I expected to work was something like,
Code: Select all
$ convert blue_type.png -fx "out.g = in.b;out.b = in.g" green_type.png
But there seem to be no such lvalue semantics in -fx.
That is definably not possible.
You see the FX expression is not run one per pixel as the above implies, but once per pixel value.
that is for each pixel it is run once for red, green, and blue channels, which is where the result is then saved. What channels TX will execute on (and thus assigns results to) is controled by -channel
As such to save Blue to Green, and then Green to Blue, will require two FX expressions.
and you will thus need to save the original 'source' image between the expressions so you can
re-use it.
Here is the standard example...
Code: Select all
convert rose: \( +clone -channel G -fx B \) \
+swap -channel B -fx v.G fx_rb_swap.gif
The first line makes a copy of the image and copies blue values into green channel
the second swaps the two images, so the G=B image is destination, and copies the green channel from the original image (now in image 'v') into the blue channel of the destination image.
NOW: if the -fx expression had a variable that held the current channel that is being processed, say as a number from 0 to 2 (or 4,5 for optional alpha and black channels) then FX could decide on the value to save basied on the channel being processed.
EG if 'channel' holds the current channel being processed then you could do this...
Code: Select all
-channel GB -fx 'channel==1 ? b : g'
That is if channel is 1 (green) save the blue value, otherwise save the green value.
I would like to see FX re-written at some point to provide a compiled, rather than parsed expression execution, and to provide the ability to use stored values and other things, but really FX is meant as a way of doing unusual things. A development tool for future operators and methods.
For example channel copying is actually a lot easier done by quite a few other methods!
Including:
- separate,swap,combine
- recolor matrix
- compose channel coping
- HALD color lookup tables
just to name a few I and think of from the top of my head.