Color transformation with Fx

Mar 14, 2014 at 8:18 AM
Edited Mar 14, 2014 at 8: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
"rgb((1-u.r)*255,128,128)"
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
"rgb(0,128,128)"
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?
Coordinator
Mar 14, 2014 at 11:14 AM
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 7: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.
Coordinator
Mar 17, 2014 at 9: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);
  image.Write("PageHeatmap.new.png");
}
Mar 18, 2014 at 11:00 AM
Thanks, it works great.

Is there a similar "trick" for hsl(...)?
Coordinator
Mar 18, 2014 at 11:09 AM
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.