diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs
index 6451a11b7d..e262688f60 100644
--- a/src/Magick.NET/MagickImage.cs
+++ b/src/Magick.NET/MagickImage.cs
@@ -4035,7 +4035,12 @@ public void MeanShift(int width, int height)
/// The height of the pixels neighborhood.
/// The color distance.
public void MeanShift(int width, int height, Percentage colorDistance)
- => _nativeInstance.MeanShift(width, height, PercentageHelper.ToQuantum(colorDistance));
+ {
+ Throw.IfNegative(nameof(width), width);
+ Throw.IfNegative(nameof(height), height);
+
+ _nativeInstance.MeanShift(width, height, PercentageHelper.ToQuantum(colorDistance));
+ }
///
/// Filter image by replacing each pixel component with the median color in a circular neighborhood.
diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheMeanShiftMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheMeanShiftMethod.cs
index a44edad591..c21f7fd443 100644
--- a/tests/Magick.NET.Tests/MagickImageTests/TheMeanShiftMethod.cs
+++ b/tests/Magick.NET.Tests/MagickImageTests/TheMeanShiftMethod.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,22 @@ public partial class MagickImageTests
{
public class TheMeanShiftMethod
{
+ [Fact]
+ public void ShouldThrowExceptionWhenWidthIsNegative()
+ {
+ using var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG);
+
+ Assert.Throws("width", () => image.MeanShift(-1, 1));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenHeightIsNegative()
+ {
+ using var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG);
+
+ Assert.Throws("height", () => image.MeanShift(1, -1));
+ }
+
[Fact]
public void ShouldNotChangeImageWhenSizeIsOne()
{