Skip to content

Commit

Permalink
Added InverseContrast to MagickImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jun 12, 2022
1 parent 91a9bb6 commit ac10e22
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/Magick.NET.Core/IMagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,12 @@ public partial interface IMagickImage : IDisposable
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void InterpolativeResize(Percentage percentageWidth, Percentage percentageHeight, PixelInterpolateMethod method);

/// <summary>
/// Inverse contrast image (diminish intensity differences in image).
/// </summary>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void InverseContrast();

/// <summary>
/// Applies the reversed level operation to just the specific channels specified. It compresses
/// the full range of color values, so that they lie between the given black and white points.
Expand Down
7 changes: 7 additions & 0 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3568,6 +3568,13 @@ public void InterpolativeResize(Percentage percentageWidth, Percentage percentag
InterpolativeResize(geometry, method);
}

/// <summary>
/// Inverse contrast image (diminish intensity differences in image).
/// </summary>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void InverseContrast()
=> _nativeInstance.Contrast(false);

/// <summary>
/// Floodfill pixels not matching color (within fuzz factor) of target pixel(x,y) with
/// replacement alpha value using method.
Expand Down
15 changes: 0 additions & 15 deletions tests/Magick.NET.Tests/MagickImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,6 @@ public void Test_Constructor()
Assert.Contains("error/blob.c/OpenBlob", exception.Message);
}

[Fact]
public void Test_Contrast()
{
using (var first = new MagickImage(Files.Builtin.Wizard))
{
first.Contrast(true);
first.Contrast(false);

using (var second = new MagickImage(Files.Builtin.Wizard))
{
Assert.InRange(first.Compare(second, ErrorMetric.RootMeanSquared), 0.0031, 0.0034);
}
}
}

[Fact]
public void Test_ContrastStretch()
{
Expand Down
28 changes: 28 additions & 0 deletions tests/Magick.NET.Tests/MagickImageTests/TheContrastMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using ImageMagick;
using Xunit;

namespace Magick.NET.Tests
{
public partial class MagickImageTests
{
public class TheContrastMethod
{
[Fact]
public void ShouldEnhanceTheImage()
{
using (var first = new MagickImage(Files.Builtin.Wizard))
{
first.Contrast();

using (var second = new MagickImage(Files.Builtin.Wizard))
{
Assert.InRange(first.Compare(second, ErrorMetric.RootMeanSquared), 0.0174, 0.0175);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using ImageMagick;
using Xunit;

namespace Magick.NET.Tests
{
public partial class MagickImageTests
{
public class TheInverseContrastMethod
{
[Fact]
public void ShouldInvertContrast()
{
using (var first = new MagickImage(Files.Builtin.Wizard))
{
first.Contrast();
first.InverseContrast();

using (var second = new MagickImage(Files.Builtin.Wizard))
{
Assert.InRange(first.Compare(second, ErrorMetric.RootMeanSquared), 0.0031, 0.0034);
}
}
}
}
}
}

0 comments on commit ac10e22

Please sign in to comment.