public void Drawer_NullReadonlyVoronoi_IOException() { ReadonlyBitmap.Set(null); using (var writer = new Drawer(new Bitmap(10, 10))) { writer.DrawVoronoi(Fortunes.Run(9, 9, new Point2D[] {})); } }
public void Drawer_HappyPath_IsHappy() { ReadonlyBitmap.Set(new Bitmap(10, 10)); using (var writer = new Drawer(ReadonlyBitmap.Get())) { writer.DrawVoronoi(Fortunes.Run(9, 9, new[] { new Point2D(0, 0), new Point2D(5, 5) })); writer.SaveToNewImageFile("a.png", Directory.GetCurrentDirectory()); writer.SaveToNewImageFile("a.png", Directory.GetCurrentDirectory()); } }
public void CalculateRegionsDeltaEList_SameImage_ExpectZero() { var originalBitmap = new Bitmap(TestImageDirectory + "WhitePicture_test.png"); ReadonlyBitmap.Set(originalBitmap); var squareRegionofPoints = GetIntPoint2DListOfRegion(); var site = new IntPoint2D(25, 25); var imageComparer = new ImageComparer(); var allDeltaEList = imageComparer.CalculateRegionsDeltaEList(ReadonlyBitmap.Get(), squareRegionofPoints, site); Assert.AreEqual(0.0, allDeltaEList.Average()); }
private static void Run(int iterations, Bitmap newImage, string fileName, string fileDirectory, int numberOfPointsToPlot) { ReadonlyBitmap.Set(newImage); var nums = Enumerable.Range(0, iterations).ToArray(); var result = new ConcurrentDictionary <VoronoiOutput, double>(); Parallel.ForEach(nums, _ => { var voronoiOutput = Fortunes.Run(ReadonlyBitmap.Get().Width, ReadonlyBitmap.Get().Height, numberOfPointsToPlot); var averageDeltaE = voronoiOutput.CalculateAccuracy(); result.TryAdd(voronoiOutput, averageDeltaE); }); var bestVoronoi = result.Aggregate((l, r) => l.Value < r.Value ? l : r).Key; using (var writer = new Drawer(newImage)) { writer.DrawVoronoi(bestVoronoi); writer.SaveToNewImageFile(fileName, fileDirectory); } }