public void ShouldThresholdImageWithTriangleMethod() { using (var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG)) { image.AutoThreshold(AutoThresholdMethod.Triangle); var colors = image.Histogram(); Assert.Equal(ColorType.Bilevel, image.DetermineColorType()); Assert.Equal(210553, colors[MagickColors.Black]); Assert.Equal(29447, colors[MagickColors.White]); } }
public void ShouldThresholdImageWithKapurMethod() { using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProPNG)) { image.AutoThreshold(AutoThresholdMethod.Kapur); Dictionary <MagickColor, int> colors = image.Histogram(); Assert.AreEqual(ColorType.Bilevel, image.DetermineColorType()); Assert.AreEqual(236359, colors[MagickColors.Black]); Assert.AreEqual(3641, colors[MagickColors.White]); } }
public void ShouldThresholdImageWithOTSUMethod() { using (var image = new MagickImage(Files.FujiFilmFinePixS1ProPNG)) { image.AutoThreshold(AutoThresholdMethod.OTSU); var colors = image.Histogram(); Assert.Equal(ColorType.Bilevel, image.DetermineColorType()); Assert.Equal(67844, colors[MagickColors.Black]); Assert.Equal(172156, colors[MagickColors.White]); } }
internal static MagickImage ProcessImage(Stream image, bool disposeStream = true) { var magickImage = new MagickImage(image); magickImage.Alpha(AlphaOption.Remove); magickImage.BackgroundColor = MagickColor.FromRgb(255, 255, 255); if (magickImage.DetermineColorType() == ColorType.Grayscale) { magickImage.Grayscale(); } if (disposeStream) { image.Dispose(); } return(magickImage); }