public void GetClusters_SameFiles_ReturnsZero() { using var leftImgCopy1 = new Bitmap(leftImg1); using var leftImgCopy2 = new Bitmap(leftImg1); var leftBits = leftImgCopy1.LockBits( new Rectangle(0, 0, leftImgCopy1.Width, leftImgCopy1.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); var leftBits2 = leftImgCopy2.LockBits( new Rectangle(0, 0, leftImgCopy2.Width, leftImgCopy2.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); diff.ImagePreprocessor.Process(leftBits); diff.ImagePreprocessor.Process(leftBits2); var pixels = diff.GetDifferentPixels(25, leftBits, leftBits2); var clusters = _testClass.GetClusters(pixels, int.MaxValue).ToList(); Assert.AreEqual(0, clusters.Count); leftImgCopy1.UnlockBits(leftBits); leftImgCopy2.UnlockBits(leftBits2); }
/// <summary> /// Calculate difference between provided images /// </summary> /// <param name="errorTolerance">Maximum allowed pixel delta</param> /// <param name="maxDifferences">Maximum differences to recognize</param> /// <returns>Image with highlighted differences</returns> public Image Calculate(double errorTolerance, int maxDifferences = int.MaxValue) { using var leftCopy = new Bitmap(_left); using var rightCopy = new Bitmap(_right); var leftBits = leftCopy.LockBits( new Rectangle(0, 0, leftCopy.Width, leftCopy.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); var rightBits = rightCopy.LockBits( new Rectangle(0, 0, rightCopy.Width, rightCopy.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); if (Preprocess(leftBits, rightBits) && _progressObserver != null) { _progressObserver.Report(leftCopy, "leftPreprocess"); _progressObserver.Report(rightCopy, "rightPreprocess"); } using var pixels = _diffAlgorithm.GetDifferentPixels(errorTolerance, leftBits, rightBits, _progressObserver); leftCopy.UnlockBits(leftBits); rightCopy.UnlockBits(rightBits); var result = new Bitmap(_left); _diffHighlighter?.Highlight(result, pixels, maxDifferences, _progressObserver); return(result); }