Question

I am trying to do some colour transformation with Fx function, but it 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 help me?

Was it helpful?

Solution

Using rgb(...) in fx is only for specifying a unique color and not for doing computations. You would have to do something like this:

using (MagickImage image = new MagickImage("Input.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("Output.png");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top