public void TestApplyThresholdValue(string sourceResourcePath) { // Load source image using Image sourceImage = TestImage.FromResource(sourceResourcePath); Assert.IsNotNull(sourceImage); // Apply threshold using Image thresholdImage = ImageThreshold.Apply(sourceImage, 0x40); Assert.IsNotNull(thresholdImage); byte[] withoutAlphaBytes = RemoveAlphaLayerBytes(ImageBytes.FromImage(thresholdImage), sourceImage.PixelFormat); // Check bytes thresholded Assert.IsTrue(withoutAlphaBytes.Take(sourceImage.Width).All(b => b == byte.MinValue || b == byte.MaxValue)); }
public void TestApplyMin(string sourceResourcePath) { // Load source image using Image sourceImage = TestImage.FromResource(sourceResourcePath); Assert.IsNotNull(sourceImage); // Apply min value using Image minImage = ImageThreshold.ApplyMin(sourceImage, 0x20); Assert.IsNotNull(minImage); byte[] withoutAlphaBytes = RemoveAlphaLayerBytes(ImageBytes.FromImage(minImage), sourceImage.PixelFormat); // Check all greater than value Assert.IsTrue(withoutAlphaBytes.All(b => b >= 0x20)); }
public void TestApplyMinMax(string sourceResourcePath) { // Load source image using Image sourceImage = TestImage.FromResource(sourceResourcePath); Assert.IsNotNull(sourceImage); // Apply min/max value using Image minMaxImage = ImageThreshold.ApplyMinMax(sourceImage, 0x25, 0xc3); Assert.IsNotNull(minMaxImage); byte[] withoutAlphaBytes = RemoveAlphaLayerBytes(ImageBytes.FromImage(minMaxImage), sourceImage.PixelFormat); // Check all within range Assert.IsTrue(withoutAlphaBytes.All(b => b >= 0x25 && b <= 0xc3)); }
public void TestOtsuThreshold(string sourceResourcePath, string resultResourcePath) { // Load source image using Image sourceImage = TestImage.FromResource(sourceResourcePath); Assert.IsNotNull(sourceImage); // Apply Thresholding using Image thresholdImage = ImageThreshold.ApplyOtsuMethod(sourceImage); Assert.IsNotNull(thresholdImage); // Load correct result image using Image resultImage = TestImage.FromResource(resultResourcePath); Assert.IsNotNull(resultImage); // Compare images Assert.IsTrue(TestImage.Compare(thresholdImage, resultImage)); }