/// <summary> /// Returns true if this color is less than or equal to reference color on all channels. /// </summary> /// <param name="reference">The reference color to evaluate against.</param> /// <returns>True if this color is less than or equal to reference on all channels.</returns> internal bool MeetsTolerance(ColorDifference reference) { return((this.A <= reference.A) && (this.R <= reference.R) && (this.G <= reference.G) && (this.B <= reference.B)); }
private (Bitmap, ColorDifference) ImagesDifference(Image firstImage, Image secondImage, IColorDifferences colorDifferences, int multiplier = 25) { int width = Math.Min(firstImage.Width, secondImage.Width); int height = Math.Min(firstImage.Height, secondImage.Height); Bitmap first = (Bitmap)firstImage; Bitmap second = (Bitmap)secondImage; Bitmap diff = new Bitmap(width, height); ColorDifference totalDifference = new ColorDifference(); for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { Color firstImagePx = first.GetPixel(i, j); Color secondImagePx = second.GetPixel(i, j); Color differencePx = colorDifferences.GetDifference(firstImagePx, secondImagePx, multiplier); totalDifference.Accumulate(differencePx); diff.SetPixel(i, j, differencePx); } } totalDifference.Reduce(multiplier); return(diff, totalDifference); }
public static double Difference(RGB rgb1, RGB rgb2, ColorDifference type) { switch (type) { case ColorDifference.RGB_std_deviation: return(RGB_std_deviation(rgb1, rgb2)); case ColorDifference.CIE76: return(CIE76(rgb1, rgb2)); case ColorDifference.CIE94: return(CIE94(rgb1, rgb2)); case ColorDifference.CIE2000: return(CIE2000(rgb1, rgb2)); case ColorDifference.dRed: return(Math.Abs(rgb1.Red - rgb2.Red)); case ColorDifference.dGreen: return(Math.Abs(rgb1.Green - rgb2.Green)); case ColorDifference.dBlue: return(Math.Abs(rgb1.Blue - rgb2.Blue)); case ColorDifference.Grey: return(Math.Abs(ColorModelConverter.RGBtoGray(rgb1) - ColorModelConverter.RGBtoGray(rgb2))); default: return(0); } }
public void ParameterizedConstructor(byte alpha, byte red, byte green, byte blue) { ColorDifference cd = new ColorDifference(alpha, red, green, blue); Assert.Equal <byte>(alpha, cd.A); Assert.Equal <byte>(red, cd.R); Assert.Equal <byte>(green, cd.G); Assert.Equal <byte>(blue, cd.B); }
public void DefaultConstructor() { ColorDifference cd = new ColorDifference(); Assert.Equal <byte>(0, cd.A); Assert.Equal <byte>(0, cd.R); Assert.Equal <byte>(0, cd.G); Assert.Equal <byte>(0, cd.B); }
private void CompareButton_Click(object sender, EventArgs e) { Color FromColor = GetFromColor(); Color ToColor = GetToColor(); if (FromColor.IsICCcolor && !FromColor.IsPCScolor) { FromColor = Converter.ToICC(FromColor); } if (ToColor.IsICCcolor && !ToColor.IsPCScolor) { ToColor = Converter.ToICC(ToColor); } ColorLCH DIN99From = Converter.ToLCH99(FromColor); ColorLCH DIN99To = Converter.ToLCH99(ToColor); DIN99_E.Text = ColorDifference.GetDeltaE_DIN99((ColorLCH99)DIN99From, (ColorLCH99)DIN99To).ToString("n5", cInfo); DIN99_H.Text = ColorDifference.GetDeltaH_DIN99((ColorLCH99)DIN99From, (ColorLCH99)DIN99To).ToString("n5", cInfo); DIN99_C.Text = ColorDifference.GetDeltaC_DIN99((ColorLCH99)DIN99From, (ColorLCH99)DIN99To).ToString("n5", cInfo); DIN99From = Converter.ToLCH99b(FromColor); DIN99To = Converter.ToLCH99b(ToColor); DIN99b_E.Text = ColorDifference.GetDeltaE_DIN99((ColorLCH99b)DIN99From, (ColorLCH99b)DIN99To).ToString("n5", cInfo); DIN99b_H.Text = ColorDifference.GetDeltaH_DIN99((ColorLCH99b)DIN99From, (ColorLCH99b)DIN99To).ToString("n5", cInfo); DIN99b_C.Text = ColorDifference.GetDeltaC_DIN99((ColorLCH99b)DIN99From, (ColorLCH99b)DIN99To).ToString("n5", cInfo); DIN99From = Converter.ToLCH99c(FromColor); DIN99To = Converter.ToLCH99c(ToColor); DIN99c_E.Text = ColorDifference.GetDeltaE_DIN99((ColorLCH99c)DIN99From, (ColorLCH99c)DIN99To).ToString("n5", cInfo); DIN99c_H.Text = ColorDifference.GetDeltaH_DIN99((ColorLCH99c)DIN99From, (ColorLCH99c)DIN99To).ToString("n5", cInfo); DIN99c_C.Text = ColorDifference.GetDeltaC_DIN99((ColorLCH99c)DIN99From, (ColorLCH99c)DIN99To).ToString("n5", cInfo); DIN99From = Converter.ToLCH99d(FromColor); DIN99To = Converter.ToLCH99d(ToColor); DIN99d_E.Text = ColorDifference.GetDeltaE_DIN99((ColorLCH99d)DIN99From, (ColorLCH99d)DIN99To).ToString("n5", cInfo); DIN99d_H.Text = ColorDifference.GetDeltaH_DIN99((ColorLCH99d)DIN99From, (ColorLCH99d)DIN99To).ToString("n5", cInfo); DIN99d_C.Text = ColorDifference.GetDeltaC_DIN99((ColorLCH99d)DIN99From, (ColorLCH99d)DIN99To).ToString("n5", cInfo); ColorLab LabFrom = Converter.ToLab(FromColor); ColorLab LabTo = Converter.ToLab(ToColor); CIE76_E.Text = ColorDifference.GetDeltaE_CIE76(LabFrom, LabTo).ToString("n5", cInfo); CIE76_H.Text = "N/A"; //CIE76_H.Text = ColorDifference.GetDeltaH_CIE76(LabFrom, LabTo).ToString("n5", cInfo); CIE76_C.Text = "N/A"; //CIE76_C.Text = ColorDifference.GetDeltaC_CIE76(LabFrom, LabTo).ToString("n5", cInfo); CIE94g_E.Text = ColorDifference.GetDeltaE_CIE94(LabFrom, LabTo, CIE94DifferenceMethod.GraphicArts).ToString("n5", cInfo); CIE94t_E.Text = ColorDifference.GetDeltaE_CIE94(LabFrom, LabTo, CIE94DifferenceMethod.Textiles).ToString("n5", cInfo); CIE94g_H.Text = CIE94t_H.Text = ColorDifference.GetDeltaH_CIE94(LabFrom, LabTo).ToString("n5", cInfo); CIE94g_C.Text = CIE94t_C.Text = ColorDifference.GetDeltaC_CIE94(LabFrom, LabTo).ToString("n5", cInfo); CIEDE2000_E.Text = ColorDifference.GetDeltaE_CIEDE2000(LabFrom, LabTo).ToString("n5", cInfo); CIEDE2000_H.Text = "N/A"; //CIEDE2000_H.Text = ColorDifference.GetDeltaH_CIEDE2000(LabFrom, LabTo).ToString("n5", cInfo); CIEDE2000_C.Text = "N/A"; //CIEDE2000_C.Text = ColorDifference.GetDeltaC_CIEDE2000(LabFrom, LabTo).ToString("n5", cInfo); CMC11_E.Text = ColorDifference.GetDeltaE_CMC(LabFrom, LabTo, CMCDifferenceMethod.Perceptibility).ToString("n5", cInfo); CMC21_E.Text = ColorDifference.GetDeltaE_CMC(LabFrom, LabTo, CMCDifferenceMethod.Acceptability).ToString("n5", cInfo); CMC11_H.Text = CMC21_H.Text = ColorDifference.GetDeltaH_CMC(LabFrom, LabTo).ToString("n5", cInfo); CMC11_C.Text = CMC21_C.Text = ColorDifference.GetDeltaC_CMC(LabFrom, LabTo).ToString("n5", cInfo); }
public void SimilarImage_MediumTolerance_Positive() { Image expectedImage = Image.FromFile(testImagesPath + "Actual.jpg"); Image actualImage = Image.FromFile(testImagesPath + "Actual_Edited.jpg"); ColorDifference diff = new ColorDifference(225); bool compare = ImageComparer.Compare(expectedImage, actualImage, diff); Assert.IsTrue(compare, "Compared Edited Images With Medium Tolerance"); }
public void SimilarImage_ZeroTolerance() { Image expectedImage = Image.FromFile(testImagesPath + "Actual.jpg"); Image actualImage = Image.FromFile(testImagesPath + "Actual_Edited.jpg"); ColorDifference diff = new ColorDifference(0); bool compare = ImageComparer.Compare(expectedImage, actualImage, diff); Assert.IsFalse(compare, "Compared Edited Images With Zero Tolerance"); }
public void ShouldCorrectlyComputeColorDifference(string hex1, string hex2, double diff, bool acceptable) { var color1 = ColorTranslator.FromHtml(hex1); var color2 = ColorTranslator.FromHtml(hex2); var colorDifference = new ColorDifference(color1, color2); Assert.AreEqual(diff, colorDifference.Diff); Assert.AreEqual(acceptable, colorDifference.Acceptable); }
public void MirrorImageComparision_LowTolerance() { Image expectedImage = Image.FromFile(testImagesPath + "Actual.jpg"); Image actualImage = Image.FromFile(testImagesPath + "Actual_Mirror.jpg"); ColorDifference diff = new ColorDifference(0); bool compare = ImageComparer.Compare(expectedImage, actualImage, diff, out var outPutFile); outPutFile.Save(testImagesPath + "Output\\" + System.Reflection.MethodBase.GetCurrentMethod().Name + ".jpg"); Assert.IsFalse(compare, "Compared Edited Images With Medium Tolerance"); }
public void IdenticalImage_ZeroTolerance() { Image expectedImage = Image.FromFile(testImagesPath + "Actual.jpg"); Image actualImage = Image.FromFile(testImagesPath + "Actual_Copy.jpg"); ColorDifference diff = new ColorDifference(0); bool compare = ImageComparer.Compare(expectedImage, actualImage, diff, out var outPutFile); outPutFile.Save(testImagesPath + "Output\\" + System.Reflection.MethodBase.GetCurrentMethod().Name + ".jpg"); Assert.IsTrue(compare, "Comparision should return 'TRUE'"); }
public void Properties() { ColorDifference cd = new ColorDifference(1, 2, 3, 4); cd.A = 15; cd.R = 45; cd.G = 230; cd.B = 112; Assert.Equal <byte>(15, cd.A); Assert.Equal <byte>(45, cd.R); Assert.Equal <byte>(230, cd.G); Assert.Equal <byte>(112, cd.B); }
public void VerifyHistogram() { // // Load up a pair of high-information content images and compare them // Snapshot master = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Mandelbrot01.png")); Snapshot compare = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Mandelbrot02.png")); Snapshot difference = compare.CompareTo(master); // // Generate a histogram from the diff image // Histogram h = Histogram.FromSnapshot(difference); // // Save out the line graph of the histogram as a lossless png // h.ToGraph(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Histogram-Graph-Actual.png"), ImageFormat.Png); // // Load the graph image into memory so that we can compare it to a known good version // Snapshot graphImage = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Histogram-Graph-Actual.png")); // // Compare the rendered graph to a known good render // Snapshot expectedGraph = Snapshot.FromFile(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Histogram-Graph-Expected.png")); Snapshot graphDifference = expectedGraph.CompareTo(graphImage); // // There should be absolutely no differences between the graph and the expected graph // Microsoft.Test.VisualVerification.ColorDifference colorDiff = new ColorDifference(0, 0, 0, 0); SnapshotColorVerifier verifier = new SnapshotColorVerifier(System.Drawing.Color.Black, colorDiff); VerificationResult result = verifier.Verify(graphDifference); Assert.Equal <VerificationResult>(VerificationResult.Pass, result); }
public void ParameterizedConstructor(string expectedColorString, string toleranceString) { int expectedColor = Int32.Parse(expectedColorString, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); int tolerance = Int32.Parse(toleranceString, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); Color c = Color.FromArgb((int)expectedColor); byte ta = (byte)(tolerance & 0xFF000000 >> 128); byte tr = (byte)(tolerance & 0x00FF0000 >> 32); byte tg = (byte)(tolerance & 0x0000FF00 >> 16); byte tb = (byte)(tolerance & 0x000000FF >> 0); ColorDifference t = new ColorDifference(ta, tr, tg, tb); SnapshotColorVerifier v = new SnapshotColorVerifier(c, t); Assert.Equal <byte>(c.A, v.ExpectedColor.A); Assert.Equal <byte>(c.R, v.ExpectedColor.R); Assert.Equal <byte>(c.G, v.ExpectedColor.G); Assert.Equal <byte>(c.B, v.ExpectedColor.B); Assert.Equal <byte>(t.A, v.Tolerance.A); Assert.Equal <byte>(t.R, v.Tolerance.R); Assert.Equal <byte>(t.G, v.Tolerance.G); Assert.Equal <byte>(t.B, v.Tolerance.B); }
private static bool CompareInternal(Image actualImage, Image expectedImage, ColorDifference argbTolerance, out Image?diffImage, bool createOutImage) { if (actualImage is null) { throw new ArgumentNullException(nameof(actualImage)); } if (expectedImage is null) { throw new ArgumentNullException(nameof(expectedImage)); } if (argbTolerance is null) { throw new ArgumentNullException(nameof(argbTolerance)); } if (actualImage.Width != expectedImage.Width || actualImage.Height != expectedImage.Height || actualImage.PixelType != expectedImage.PixelType) { diffImage = default; return(false); } var snapshot = Snapshot.FromImage(actualImage); var snapshot2 = Snapshot.FromImage(expectedImage); if (snapshot.Width != snapshot2.Width || snapshot.Height != snapshot2.Height) { throw new InvalidOperationException(Properties.Resources.ImageSizesNotEqual); } var toleranceMap = new SingleValueToleranceMap(Color.FromRgba(argbTolerance.Red, argbTolerance.Green, argbTolerance.Blue, argbTolerance.Alpha)); return(CompareInternal(snapshot, snapshot2, toleranceMap, out diffImage, createOutImage)); }
public void TransformStepByStepAndCompare() { /*Open original image, transform image and save * open original image again, apply partial transformation again, save * Compare two images, the compare should result false*/ /*Complete the transformation on second image * Compare two images with different threshold levels * Test case should pass*/ #region TestData Image image1, image2, image3; ColorDifference diff = new ColorDifference(0); string imagesPath = FileUtilities.CheckAndCreateDirectory(testImagesPath + System.Reflection.MethodBase.GetCurrentMethod().Name + @"\"); bool compare; string originalImage = imagesPath + "Actual.jpg"; string runTimeImage1 = imagesPath + "First.jpg"; string runTimeImage2 = imagesPath + "Second.jpg"; string runTimeImage3 = imagesPath + "Third.jpg"; #endregion #region OpenImageAndEdit1 FileUtilities.OpenFile(originalImage); wndImagePro.ClickTabAdjust(); wndImagePro.ClickBtnRotate(); wndImagePro.ClickTabMeasure(); wndImagePro.ClickBtnCreate(); System.Threading.Thread.Sleep(1000); wndImagePro.ClickTabCapture(); wndImagePro.ClickBtnSaturation(); //Select Saturation wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage1); #endregion wndImagePro.CloseAllToolsAndViews(true); #region OpenImageAndEdit Partial //System.Threading.Thread.Sleep(2000); FileUtilities.OpenFile(originalImage); FileUtilities.OpenFile(originalImage); wndImagePro.ClickTabAdjust(); wndImagePro.ClickBtnRotate(); wndImagePro.ClickTabMeasure(); wndImagePro.ClickBtnCreate(); wndImagePro.ClickTabCapture(); wndImagePro.ClickBtnSaturation(); //Unselect Saturation wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage2); #endregion image1 = Image.FromFile(runTimeImage1); image2 = Image.FromFile(runTimeImage2); compare = ImageComparer.Compare(image1, image2, diff, out Image outPutFile); outPutFile.Save(imagesPath + "Output1.jpg"); Assert.IsFalse(compare, "Images should not match"); #region Continue transform wndImagePro.ClickTabCapture(); wndImagePro.ClickBtnSaturation(); //Select Saturation wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage3); image3 = Image.FromFile(runTimeImage3); diff = new ColorDifference(0); compare = ImageComparer.Compare(image1, image3, diff, out outPutFile); outPutFile.Save(imagesPath + "Output2.jpg"); Assert.IsTrue(compare, "Images should match"); #endregion }
protected override void BuildGraph(int width, int height, RGB[,] pixels, ConnectingMethod connectingMethod, ColorDifference difType, int[,] superPixels = null) { segments = new Segment[width * height]; for (var id = 0; id < width * height; id++) { segments[id] = new Segment(); } nodes = new Node[width, height]; for (var j = 0; j < height; j++) { for (var i = 0; i < width; i++) { var c = j * width + i; nodes[i, j] = new Node(); // initialize node nodes[i, j].Segment = segments[c]; // initialize component segments[c].Id = -1; segments[c].Count = 1; segments[c].SegmentWeight = 0; segments[c].First = segments[c].Last = nodes[i, j]; segments[c].SumR = pixels[i, j].Red; segments[c].SumG = pixels[i, j].Green; segments[c].SumB = pixels[i, j].Blue; } } edges = new List <Edge>(); for (var j = 0; j < height; j++) { for (var i = 0; i < width; i++) { if (i < (width - 1)) { var diff = PixelComparator.Difference(nodes[i, j].Segment.RGB, nodes[i + 1, j].Segment.RGB, difType); if (superPixels[i, j] != superPixels[i + 1, j]) { edges.Add(new Edge(nodes[i, j], nodes[i + 1, j], diff)); // Right } else if (nodes[i, j].Segment != nodes[i + 1, j].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i + 1, j].Segment, 0); } } if (j < (height - 1)) { var diff = PixelComparator.Difference(nodes[i, j].Segment.RGB, nodes[i, j + 1].Segment.RGB, difType); if (superPixels[i, j] != superPixels[i, j + 1]) { edges.Add(new Edge(nodes[i, j], nodes[i, j + 1], diff)); // Down } else if (nodes[i, j].Segment != nodes[i, j + 1].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i, j + 1].Segment, 0); } } if (connectingMethod == ConnectingMethod.Connected_8) { if (j > 0 && i < (width - 1)) { var diff = PixelComparator.Difference(nodes[i, j].Segment.RGB, nodes[i + 1, j - 1].Segment.RGB, difType); if (superPixels[i, j] != superPixels[i + 1, j - 1]) { edges.Add(new Edge(nodes[i, j], nodes[i + 1, j - 1], diff)); // Up-Right } else if (nodes[i, j].Segment != nodes[i + 1, j - 1].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i + 1, j - 1].Segment, 0); } } if (j < (height - 1) && i < (width - 1)) { var diff = PixelComparator.Difference(nodes[i, j].Segment.RGB, nodes[i + 1, j + 1].Segment.RGB, difType); if (superPixels[i, j] != superPixels[i + 1, j + 1]) { edges.Add(new Edge(nodes[i, j], nodes[i + 1, j + 1], diff)); // Down-Right } else if (nodes[i, j].Segment != nodes[i + 1, j + 1].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i + 1, j + 1].Segment, 0); } } } } } }
public void TransformPartiallyAndCompare_ExpectedFail() { #region TestData bool compare = false; Image image1; Image image2; string imagesPath = FileUtilities.CheckAndCreateDirectory(testImagesPath + System.Reflection.MethodBase.GetCurrentMethod().Name + @"\"); ColorDifference diff = new ColorDifference(0); string originalImage = imagesPath + "Actual.jpg"; string runTimeImage1 = imagesPath + "First.jpg"; string runTimeImage2 = imagesPath + "Second.jpg"; #endregion #region OpenImageAndEdit1 FileUtilities.OpenFile(originalImage); wndImagePro.ClickTabAdjust(); wndImagePro.ClickBtnRotate(); wndImagePro.ClickTabMeasure(); wndImagePro.ClickBtnCreate(); System.Threading.Thread.Sleep(1000); wndImagePro.ClickTabCapture(); wndImagePro.ClickBtnSaturation(); //Select Saturation wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage1); #endregion wndImagePro.CloseAllToolsAndViews(true); #region OpenImageAndEdit Partial //System.Threading.Thread.Sleep(2000); FileUtilities.OpenFile(originalImage); FileUtilities.OpenFile(originalImage); wndImagePro.ClickTabAdjust(); wndImagePro.ClickBtnRotate(); wndImagePro.ClickTabMeasure(); wndImagePro.ClickBtnCreate(); wndImagePro.ClickTabCapture(); wndImagePro.ClickBtnSaturation(); //Unselect Saturation wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage2); #endregion image1 = Image.FromFile(runTimeImage1); image2 = Image.FromFile(runTimeImage2); compare = ImageComparer.Compare(image1, image2, diff, out Image outPutFile); outPutFile.Save(imagesPath + "Output1.jpg"); Assert.IsTrue(compare, "Falsy expecting: Images should not match"); }
protected override void BuildGraph(int width, int height, RGB[,] pixels, ConnectingMethod connectingMethod, ColorDifference difType, int[,] superPixels = null) { int edgesPerNode = 0; if (connectingMethod == ConnectingMethod.Connected_4) { edgesPerNode = 2; } else if (connectingMethod == ConnectingMethod.Connected_8) { edgesPerNode = 4; } segments = new Segment[width * height]; for (int i = 0; i < segments.Length; i++) { segments[i] = new Segment(); } nodes = new Node[width, height]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { nodes[i, j] = new Node(); int c = j * width + i; // initialize node nodes[i, j].Segment = segments[c]; // initialize component segments[c].Id = -1; segments[c].Count = 1; segments[c].SegmentWeight = 0; segments[c].First = segments[c].Last = nodes[i, j]; } } edges = new Edge[edgesPerNode * width * height]; for (int i = 0; i < edges.Length; i++) { edges[i] = new Edge(); } edgePockets = new Edge[2560]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int c = j * width + i; // initialize edge if ((i + 1) < width) { if (superPixels[i, j] != superPixels[i + 1, j]) { var diff = PixelComparator.Difference(pixels[i, j], pixels[i + 1, j], difType) * 100; CreateEdge(edgesPerNode * c, nodes[i, j], nodes[i + 1, j], (int)diff); } else if (nodes[i, j].Segment != nodes[i + 1, j].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i + 1, j].Segment, 0); } } if ((j + 1) < height) { if (superPixels[i, j] != superPixels[i, j + 1]) { var diff = PixelComparator.Difference(pixels[i, j], pixels[i, j + 1], difType) * 100; CreateEdge(edgesPerNode * c + 1, nodes[i, j], nodes[i, j + 1], (int)diff); } else if (nodes[i, j].Segment != nodes[i, j + 1].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i, j + 1].Segment, 0); } } if (connectingMethod == ConnectingMethod.Connected_8) { if ((i + 1 < width) && (j - 1 >= 0)) { if (superPixels[i, j] != superPixels[i + 1, j - 1]) { var diff = PixelComparator.Difference(pixels[i, j], pixels[i + 1, j - 1], difType) * 100; CreateEdge(edgesPerNode * c + 2, nodes[i, j], nodes[i + 1, j - 1], (int)diff); } else if (nodes[i, j].Segment != nodes[i + 1, j - 1].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i + 1, j - 1].Segment, 0); } } if (((i + 1) < width) && ((j + 1) < height)) { if (superPixels[i, j] != superPixels[i + 1, j + 1]) { var diff = PixelComparator.Difference(pixels[i, j], pixels[i + 1, j + 1], difType) * 100; CreateEdge(edgesPerNode * c + 3, nodes[i, j], nodes[i + 1, j + 1], (int)diff); } else if (nodes[i, j].Segment != nodes[i + 1, j + 1].Segment) { MergeSegment(nodes[i, j].Segment, nodes[i + 1, j + 1].Segment, 0); } } } } } }
public int[,] BuildSegments(int width, int height, RGB[,] pixels, int k, int minSize, ConnectingMethod connectingMethod, ColorDifference difType, ref PerfomanceInfo perfomanceInfo, int[,] superPixels) { var watch = Stopwatch.StartNew(); BuildGraph(width, height, pixels, connectingMethod, difType, superPixels); watch.Stop(); perfomanceInfo.BuildingPerfomance = watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); SortEdges(); watch.Stop(); perfomanceInfo.SortingPerfomance = watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); DoAlgorithm(k); watch.Stop(); perfomanceInfo.AlgorithmPerfomance = watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); if (minSize > 0) { MargeSmall(minSize); } watch.Stop(); perfomanceInfo.SmallSegmentMargingPerfomance = watch.ElapsedMilliseconds; return(ReindexSegments(width, height)); }
protected abstract void BuildGraph(int width, int height, RGB[,] pixels, ConnectingMethod connectingMethod, ColorDifference difType, int[,] superPixels = null);
public void TransformTwoImagesAndCompare() { //Saturation button should be in unselected state #region TestData Image image1, image2; bool compareWithZeroTolerance, compareWith100Tolerance; ColorDifference diff = new ColorDifference(0); string originalImage = testImagesPath + "Actual.jpg"; string imagesPath = FileUtilities.CheckAndCreateDirectory(testImagesPath + System.Reflection.MethodBase.GetCurrentMethod().Name + @"\"); string runTimeImage1 = imagesPath + "First.jpg"; string runTimeImage2 = imagesPath + "Second.jpg"; #endregion #region OpenImageAndEdit1 FileUtilities.OpenFile(originalImage); wndImagePro.ClickTabAdjust(); wndImagePro.ClickBtnRotate(); wndImagePro.ClickTabMeasure(); wndImagePro.ClickBtnCreate(); wndImagePro.ClickTabCapture(); wndImagePro.ClickBtnSaturation(); //wndImagePro.TabCountOrSize().ClickPoint(); //wndImagePro.BtnCount().ClickPoint(-40); wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage1); #endregion #region setup wndImagePro.CloseAllToolsAndViews(true); #endregion #region OpenImageAndEdit2 System.Threading.Thread.Sleep(2000); FileUtilities.OpenFile(originalImage); FileUtilities.OpenFile(originalImage); wndImagePro.ClickTabAdjust(); wndImagePro.ClickBtnRotate(); wndImagePro.ClickTabMeasure(); wndImagePro.ClickBtnCreate(); System.Threading.Thread.Sleep(1000); //Observation: Saturation is selected by default //wndImagePro.TabCapture.ClickPoint(); //wndImagePro.BtnSaturation.Click(); wndImagePro.ImageViewer.ClickPoint(); wndImagePro.ImageViewer.CaptureImage(runTimeImage2); #endregion image1 = Image.FromFile(runTimeImage1); image2 = Image.FromFile(runTimeImage2); compareWithZeroTolerance = ImageComparer.Compare(image1, image2, diff, out Image outPutFile); outPutFile.Save(imagesPath + "Output1.jpg"); Assert.IsTrue(compareWithZeroTolerance, "Images should be same compareWithZeroTolerance"); diff = new ColorDifference(100); compareWith100Tolerance = ImageComparer.Compare(image1, image2, diff, out outPutFile); outPutFile.Save(imagesPath + "Output2.jpg"); Assert.IsTrue(compareWith100Tolerance, "Images should be same compareWith100Tolerance"); }
/// <summary> /// Compares two images. /// </summary> /// <param name="actualImage">The actual image.</param> /// <param name="expectedImage">The expected image.</param> /// <param name="argbTolerance">The ARGB tolerance.</param> /// <param name="diffImage">The output difference image.</param> /// <returns><see langword="true"/> if images are the same; otherwise <see langword="false"/>.</returns> public static bool Compare(Image actualImage, Image expectedImage, ColorDifference argbTolerance, out Image?diffImage) => CompareInternal(actualImage, expectedImage, argbTolerance, out diffImage, createOutImage: true);