This project has moved and is read-only. For the latest updates, please go here.

Color transformation with Fx

Mar 14, 2014 at 9:18 AM
Edited Mar 14, 2014 at 9:24 AM
I am trying to do some colour transformation with Fx function, but is doesn't work.

If I use this expression inside Fx function
the result is black image. The actual transformation is more complicated, but I can't get even this simple one to work.

If I use
the result is plain colour image as expected.

There is probably some fundamental mistake in my expression, but I can't see it. Can anybody give me an advice?
Mar 14, 2014 at 12:14 PM
Can you post a link to your image so I can also do some testing with it? I have no experience with fx but I will try to help you.
Mar 17, 2014 at 8:20 AM
There is the image, but I doubt, that my problem is related to the image, I suppose there is something wrong with the Fx expression.
Mar 17, 2014 at 10:02 PM
You are right the problem is the expression you are using. Using rgb(...) in fx is only for specifying a unique color and not for doing computations. You would have to rewrite your code to the following:
using (MagickImage image = new MagickImage("PageHeatmap.png"))
  // Evaluate is faster if you just want to set a pixel to a value
  image.Evaluate(Channels.Green | Channels.Blue, EvaluateOperator.Set, 128);
  image.Fx("(1-u.r)*255", Channels.Red);
Mar 18, 2014 at 12:00 PM
Thanks, it works great.

Is there a similar "trick" for hsl(...)?
Mar 18, 2014 at 12:09 PM
The "trick" is identical for hsl and rgb. The Channels enum does not define the hue/saturation/lightness channels so you have to use the rgb names: h = r, s = g, l = b.