0

I'm trying to autolevel an image. My code looks like this:

MagickImage image = new MagickImage(stream);
image.AutoLevel(Channels.RGB);

Later in the code I'm sending the image to a web response. For some reason, this code has no effect on the image. It looks exactly the same as the original. If I change to:

MagickImage image = new MagickImage(stream);
image.Posterize(2);

Then I clearly see the filter applied.

What am I missing with AutoLevel?

Update:

I tried this code:

var image1 = Image.Clone();
Image.AutoLevel(Channels.RGB);
var diff = Image.Compare(image1, ErrorMetric.RootMeanSquared);

and the value of diff is 0.0, while with this code (and using the same image):

var image1 = Image.Clone();
Image.Equalize();
var diff = Image.Compare(image1, ErrorMetric.RootMeanSquared);

the value of diff is 0.315

Juvaly
  • 252
  • 1
  • 17

1 Answers1

0

The effect of AutoLevel might not be noticeable depending on your input image. I did a quick test with the following code:

using (MagickImage imageA = new MagickImage("logo:"))
{
  imageA.Write(@"c:\imageA.jpg")

  imageA.AutoLevel(Channels.Default);

  using (MagickImage imageB = new MagickImage("logo:"))
  {
    double difference = imageA.Compare(imageB, ErrorMetric.RootMeanSquared);
    Assert.AreNotEqual(0.0, difference);

    imageB.Write(@"c:\imageB.jpg")
  }
}

This tests passed but the value of difference is very small. This means that when you compare the images with your eyes you will probably not be able to find a big difference.

And below is an example that will show you that the AutoLevel method does something when you use another input image.

using (MagickImage imageA = new MagickImage("gradient:gray70-gray30", 150, 100))
{
  imageA.Write(@"c:\imageA.jpg")

  imageA.AutoLevel(Channels.Default);

  using (MagickImage imageB = new MagickImage("gradient:gray70-gray30", 150, 100))
  {
    double difference = imageA.Compare(imageB, ErrorMetric.RootMeanSquared);
    Assert.AreNotEqual(0.0, difference);

    imageB.Write(@"c:\imageB.jpg")
  }
}
dlemstra
  • 7,813
  • 2
  • 27
  • 43