From d0a134dbf66e8b0248317ebffda476a8dd945478 Mon Sep 17 00:00:00 2001 From: Vort Date: Sat, 7 Jan 2017 13:03:42 +0200 Subject: [PATCH] Move color difference function to Color.cs --- Color.cs | 19 ++++++++++++++++++- Config.cs | 4 ++-- Properties/AssemblyInfo.cs | 4 ++-- Tracer.cs | 17 +++-------------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Color.cs b/Color.cs index 57070b6..b058113 100644 --- a/Color.cs +++ b/Color.cs @@ -1,7 +1,17 @@ -namespace RiverTrace +using ColorMine.ColorSpaces; +using ColorMine.ColorSpaces.Comparisons; + +namespace RiverTrace { struct Color { + private static Cie1976Comparison cie; + + static Color() + { + cie = new Cie1976Comparison(); + } + public Color(byte r, byte g, byte b) { R = r; @@ -9,6 +19,13 @@ public Color(byte r, byte g, byte b) B = b; } + public double DifferenceTo(Color c) + { + Rgb rgb1 = new Rgb { R = R, G = G, B = B }; + Rgb rgb2 = new Rgb { R = c.R, G = c.G, B = c.B }; + return rgb1.Compare(rgb2, cie); + } + public byte R; public byte G; public byte B; diff --git a/Config.cs b/Config.cs index 59f40c9..8d11b2e 100644 --- a/Config.cs +++ b/Config.cs @@ -49,11 +49,11 @@ static Config() lon1 = 52.2209239, lat2 = 64.9032122, lon2 = 52.2213061, - iterationCount = 800, + iterationCount = 500, sampleWidthScale = 1.7, sampleLengthScale = 0.6, shoreContrast = 10.0, - maxDifference = 12.0, + maxDifference = 14.0, debug = false }; if (File.Exists(fileName)) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index fcc1396..2dc6e70 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.0.2.0")] -[assembly: AssemblyFileVersion("0.0.2.0")] +[assembly: AssemblyVersion("0.0.3.0")] +[assembly: AssemblyFileVersion("0.0.3.0")] diff --git a/Tracer.cs b/Tracer.cs index 58fd1ef..a76aa11 100644 --- a/Tracer.cs +++ b/Tracer.cs @@ -1,6 +1,4 @@ -using ColorMine.ColorSpaces; -using ColorMine.ColorSpaces.Comparisons; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; @@ -9,7 +7,6 @@ namespace RiverTrace { class Tracer { - private Cie1976Comparison cie; private int sampleWidth; private int sampleLength; private double riverWidthM; @@ -47,13 +44,6 @@ void WriteOsm(List result) Console.WriteLine(""); } - double GetColorDifference(Color c1, Color c2) - { - Rgb rgb1 = new Rgb { R = c1.R, G = c1.G, B = c1.B }; - Rgb rgb2 = new Rgb { R = c2.R, G = c2.G, B = c2.B }; - return rgb1.Compare(rgb2, cie); - } - void CalcSampleDimensions(Vector startPoint, Vector direction) { int pickCount = 5; @@ -70,7 +60,7 @@ void CalcSampleDimensions(Vector startPoint, Vector direction) { pickPoint2 += sideDirs[j]; Color checkColor = tileMap.GetPixel(pickPoint2.X, pickPoint2.Y); - double diff = GetColorDifference(refColor, checkColor); + double diff = refColor.DifferenceTo(checkColor); if (diff > Config.Data.shoreContrast) break; riverHalfWidth[j] += 1.0; @@ -115,7 +105,7 @@ double GetSampleDifference(SimpleBitmap s1, SimpleBitmap s2) { Color c1 = s1.GetPixel(i, j); Color c2 = s2.GetPixel(i, j); - double pixelDelta = GetColorDifference(c1, c2); + double pixelDelta = c1.DifferenceTo(c2); totalDelta += pixelDelta; } return totalDelta / (sampleWidth * sampleLength); @@ -176,7 +166,6 @@ public Tracer() Stopwatch sw = new Stopwatch(); sw.Start(); - cie = new Cie1976Comparison(); tileMap = new TileMap(Config.Data.zoom); var way = new List();