diff --git a/src/Magick.NET.Core/IMagickImage.cs b/src/Magick.NET.Core/IMagickImage.cs
index a09be9362b..0fb2c7c024 100644
--- a/src/Magick.NET.Core/IMagickImage.cs
+++ b/src/Magick.NET.Core/IMagickImage.cs
@@ -738,6 +738,7 @@ Interlace Interlace
/// The number of bins for histogram ("dynamic range").
/// The contrast limit for localised changes in contrast. A limit less than 1
/// results in standard non-contrast limited AHE.
+ /// Thrown when an error is raised by ImageMagick.
void Clahe(Percentage xTiles, Percentage yTiles, int numberBins, double clipLimit);
///
@@ -749,6 +750,7 @@ Interlace Interlace
/// The number of bins for histogram ("dynamic range").
/// The contrast limit for localised changes in contrast. A limit less than 1
/// results in standard non-contrast limited AHE.
+ /// Thrown when an error is raised by ImageMagick.
void Clahe(int xTiles, int yTiles, int numberBins, double clipLimit);
///
diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs
index 12dd928319..55376f3cd6 100644
--- a/src/Magick.NET/MagickImage.cs
+++ b/src/Magick.NET/MagickImage.cs
@@ -1539,6 +1539,7 @@ public void ChopVertical(int offset, int height)
/// The number of bins for histogram ("dynamic range").
/// The contrast limit for localised changes in contrast. A limit less than 1
/// results in standard non-contrast limited AHE.
+ /// Thrown when an error is raised by ImageMagick.
public void Clahe(Percentage xTiles, Percentage yTiles, int numberBins, double clipLimit)
=> Clahe(Width * xTiles, Height * yTiles, numberBins, clipLimit);
@@ -1551,8 +1552,15 @@ public void Clahe(Percentage xTiles, Percentage yTiles, int numberBins, double c
/// The number of bins for histogram ("dynamic range").
/// The contrast limit for localised changes in contrast. A limit less than 1
/// results in standard non-contrast limited AHE.
+ /// Thrown when an error is raised by ImageMagick.
public void Clahe(int xTiles, int yTiles, int numberBins, double clipLimit)
- => _nativeInstance.Clahe(xTiles, yTiles, numberBins, clipLimit);
+ {
+ Throw.IfNegative(nameof(xTiles), xTiles);
+ Throw.IfNegative(nameof(yTiles), yTiles);
+ Throw.IfNegative(nameof(numberBins), numberBins);
+
+ _nativeInstance.Clahe(xTiles, yTiles, numberBins, clipLimit);
+ }
///
/// Set each pixel whose value is below zero to zero and any the pixel whose value is above
diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheClaheMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheClaheMethod.cs
index 1c6bb00120..442151c2d1 100644
--- a/tests/Magick.NET.Tests/MagickImageTests/TheClaheMethod.cs
+++ b/tests/Magick.NET.Tests/MagickImageTests/TheClaheMethod.cs
@@ -1,6 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.
+using System;
using ImageMagick;
using Xunit;
@@ -10,6 +11,27 @@ public partial class MagickImageTests
{
public class TheClaheMethod
{
+ [Fact]
+ public void ShouldThrowExceptionWhenXTilesIsNegative()
+ {
+ using var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG);
+ Assert.Throws("xTiles", () => image.Clahe(-10, 20, 30, 1.5));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenYTilesIsNegative()
+ {
+ using var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG);
+ Assert.Throws("yTiles", () => image.Clahe(10, -20, 30, 1.5));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenNumberBinsIsNegative()
+ {
+ using var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG);
+ Assert.Throws("numberBins", () => image.Clahe(10, 20, -30, 1.5));
+ }
+
[Fact]
public void ShouldChangeTheImage()
{