如何在Magic.NET中更改图像背景噪声并影响图像质量

时间:2019-01-24 05:48:44

标签: c#-4.0 magick.net

我正在使用magick.net清除图像背景噪音,请检查我的代码是什么。但是我的代码不适用于所有图像,请检查使用的图像我是否已附加图像。帮助我更改背景颜色而不影响图像质量。

私有无效BackgroundColor(IMagickImage图像)         {

        using (var CopyImage = image.Clone())
        {
            CopyImage.ColorSpace = ColorSpace.Gray;
            CopyImage.Negate();
            CopyImage.AdaptiveThreshold(10, 10, FilterOffset);
            CopyImage.ContrastStretch((Percentage)0);

            if (SmoothingThreshold != null)
            {
                CopyImage.Blur(SmoothingThreshold.Value.ToDouble() / 100, Quantum.Max);
                CopyImage.Level(SmoothingThreshold.Value, new Percentage(100));
            }

            CopyImage.Quality=100;
            image.Composite(CopyImage, CompositeOperator.CopyAlpha);

        }
        image.Opaque(MagickColors.Transparent, BackgroundColor);//i'm using white background colour
        image.Alpha(AlphaOption.Remove);
    }

我在下面使用的图像。

a busy cat

我的背景清洁的图像,请在下面检查。

a busy cat

0 个答案:

没有答案