public override long GetDistance(Bitmap img, Bitmap selfImg, int type) { long result; byte[] pixels1; byte[] pixels2; var watch = System.Diagnostics.Stopwatch.StartNew(); if (type == 0) { pixels1 = ColorHistogram.Histogram(img); watch.Stop(); pixels2 = ColorHistogram.Histogram(selfImg); Console.WriteLine("Hpropio: " + watch.ElapsedMilliseconds); watch = System.Diagnostics.Stopwatch.StartNew(); result = DarwinDistance(pixels1, pixels2); watch.Stop(); Console.WriteLine("Casas" + watch.ElapsedMilliseconds); } else { pixels1 = Contrast.ContrastHistogram(img); watch.Stop(); pixels2 = Contrast.ContrastHistogram(selfImg); Console.WriteLine("Hpropio: " + watch.ElapsedMilliseconds); watch = System.Diagnostics.Stopwatch.StartNew(); result = DarwinDistance(pixels1, pixels2); Console.WriteLine("Darwin: " + watch.ElapsedMilliseconds); } return(result); }
public void ColorHistogramGetColors() { tlog.Debug(tag, $"ColorHistogramGetColors START"); int[] pixels = new int[3] { 16, 4, 20 }; var testingTarget = new ColorHistogram(pixels); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <ColorHistogram>(testingTarget, "Should be an Instance of ColorHistogram!"); try { testingTarget.GetColors(); tlog.Debug(tag, "colors :" + testingTarget.GetColors()); } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception: Failed!"); } tlog.Debug(tag, $"ColorHistogramGetColors END (OK)"); }
public void CorrectClosestHistogramTest() { var histogramService = new HistogramSorterService(); var histogram1 = new ColorHistogram( "randomId1", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); var histogram2 = new ColorHistogram( "randomId2", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.2 } ); var histogram3 = new ColorHistogram( "randomId3", new List <double> { 0.1 }, new List <double> { 0.1, 0.1 }, new List <double> { 0.1, 0.2, 0.4 } ); var selectedHistograms = new List <ColorHistogram> { histogram1, histogram2, histogram3 }; var comparisonMap = histogramService.CreateHistogramComparisonMap(selectedHistograms); selectedHistograms.RemoveAt(0); var closestIndex = histogramService.FindTheClosestHistogramIndex( "randomId1", selectedHistograms, comparisonMap ); Assert.True(closestIndex == 0); }
public void getRGBData(ColorHistogram colorHist, double[][] data) { int size = colorHist.getNumberOfColors(); for (int x = 0; x < size; x++) { data[x] = new double[3]; int rgb = colorHist.getColor(x); data[x][0] = ((rgb & 0xFF0000) >> 16); data[x][1] = ((rgb & 0xFF00) >> 8); data[x][2] = (rgb & 0xFF); } }
public void ColorHistogramConstructor() { tlog.Debug(tag, $"ColorHistogramConstructor START"); int[] pixels = new int[3] { 16, 4, 20 }; var testingTarget = new ColorHistogram(pixels); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <ColorHistogram>(testingTarget, "Should be an Instance of ColorHistogram!"); tlog.Debug(tag, $"ColorHistogramConstructor END (OK)"); }
public void CorrectDifferenceTest() { var histogramService = new HistogramSorterService(); var histogram1 = new ColorHistogram( "randomId1", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); var histogram2 = new ColorHistogram( "randomId2", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); var difference = histogramService.HistogramDifferenceSum(histogram1, histogram2); Assert.True(difference == 0); var histogram3 = new ColorHistogram( "randomId3", new List <double> { 0.1 }, new List <double> { 0.1, 0.1 }, new List <double> { 0.1, 0.2, 0.2 } ); difference = histogramService.HistogramDifferenceSum(histogram1, histogram3); Assert.True(difference - 2 * Math.Pow(0.1, 2) < 0.001); }
public void getYIQData(ColorHistogram colorHist, double[][] data) { int size = colorHist.getNumberOfColors(); for (int x = 0; x < size; x++) { data[x] = new double[3]; int rgb = colorHist.getColor(x); double[] yiq = RGB2YIQ(rgb); for (int y = 0; y < 3; y++) { data[x][y] = yiq[y]; } } }
/// <summary> /// Go through the differences in two color histograms, square them a sum all this. /// </summary> /// <returns>Sum of the histogram differences squared.</returns> public double HistogramDifferenceSum( ColorHistogram histogram1, ColorHistogram histogram2 ) { if (histogram1.BlueHistogram.Count != histogram2.BlueHistogram.Count || histogram1.GreenHistogram.Count != histogram2.GreenHistogram.Count || histogram1.RedHistogram.Count != histogram2.RedHistogram.Count) { throw new ArgumentException("Histograms do not have the same range of colors."); } double blueDifferenceSum = 0; for (var colorRangeIndex = 0; colorRangeIndex < histogram1.BlueHistogram.Count; colorRangeIndex++) { blueDifferenceSum += Math.Pow( histogram1.BlueHistogram[colorRangeIndex] - histogram2.BlueHistogram[colorRangeIndex], 2 ); } double greenDifferenceSum = 0; for (var colorRangeIndex = 0; colorRangeIndex < histogram1.GreenHistogram.Count; colorRangeIndex++) { greenDifferenceSum += Math.Pow( histogram1.GreenHistogram[colorRangeIndex] - histogram2.GreenHistogram[colorRangeIndex], 2 ); } double redDifferenceSum = 0; for (var colorRangeIndex = 0; colorRangeIndex < histogram1.RedHistogram.Count; colorRangeIndex++) { redDifferenceSum += Math.Pow( histogram1.RedHistogram[colorRangeIndex] - histogram2.RedHistogram[colorRangeIndex], 2 ); } return(blueDifferenceSum + greenDifferenceSum + redDifferenceSum); }
public void Apply(string intermediatePath) { //tergetURL = "http://secure.futureclimateinfo.com/api/wms?request=GetMap&BBOX=314100,543800,314600,544300&SRS=EPSG:27700&WIDTH=1056&HEIGHT=1056&LAYERS=nls-sixinch&STYLES=&FORMAT=image/png"; //tergetURL = "http://secure.futureclimateinfo.com/api/wms?SERVICE=WMS&VERSION=1.1.1&request=GetMap&BBOX=314100,543800,314600,544300&SRS=EPSG:27700&WIDTH=1056&HEIGHT=1056&LAYERS=nls-sixinch&STYLES=&FORMAT=image/pnG"; //tergetURL = "http://secure.futureclimateinfo.com/api/wms?request=GetMap&BBOX=589400,194000,589900,194500&SRS=EPSG:27700&WIDTH=1056&HEIGHT=1056&LAYERS=nls-sixinch&STYLES=&FORMAT=image/png"; //tergetURL = "http://secure.futureclimateinfo.com/api/wms?request=GetMap&BBOX=589400,194000,590400,195000&SRS=EPSG:27700&WIDTH=947&HEIGHT=947&LAYERS=nls-sixinch&STYLES=&FORMAT=image/pnG"; //MapServerParameters.targetURL = "http://secure.futureclimateinfo.com/api/wms?&&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=597528,209822,598528,210822&SRS=EPSG:27700&WIDTH=1500&HEIGHT=1500&LAYERS=nls-sixinch:&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSP... Bitmap SourceImage = ConnectToMapServer.ConnectToWMS(MapServerParameters.targetURL); SourceImage.Save(intermediatePath + StraboParameters.sourceMapFileName); ColorHistogram ch = new ColorHistogram(); if (!ch.CheckImageColors(SourceImage, 2)) { Exception e = new Exception("The returned image is invalid, it has less than two colors."); Log.WriteLine("The returned image is invalid, it has less than two colors."); throw e; } }
public void IncorrectRangeTest() { var histogramService = new HistogramSorterService(); var histogram1 = new ColorHistogram( "randomId1", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); var histogram2 = new ColorHistogram( "randomId2", new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); try { histogramService.HistogramDifferenceSum(histogram1, histogram2); } catch (ArgumentException) { Assert.True(true); } catch (Exception) { Assert.True(false); } }
public Tile Apply(string intermediatePath, string output_file_name) { double mapWestCorner = double.Parse(MapServerParameters.BBOXW); double mapNorthCorner = double.Parse(MapServerParameters.BBOXN); string wmsMapPath = intermediatePath + output_file_name; int layer = MapServerParameters.ZoomLevel; Bitmap SourceImage = GetImage(mapWestCorner, mapNorthCorner, intermediatePath); SourceImage.Save(wmsMapPath); ColorHistogram ch = new ColorHistogram(); if (!ch.CheckImageColors(SourceImage, 2)) { SourceImage.Dispose(); Exception e = new Exception("The returned image is invalid, it has less than two colors."); Log.WriteLine("The returned image is invalid, it has less than two colors."); throw e; } SourceImage.Dispose(); return(_tile); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); ColorHistogram histogram = target as ColorHistogram; tabSelected = GUILayout.Toolbar(tabSelected, new string[] { "Red Channel", "Green Channel", "Blue Channel", "Alpha Channel" }); if (histogram == null) { return; } Debug.Log("GilLog - ColorHistogramEditor::OnInspectorGUI - tabSelected " + tabSelected + " "); if (tabSelected >= 0 && tabSelected < histogram.alreadyCalculated.Length && histogram.alreadyCalculated[tabSelected]) { GUILayout.Label(histogram.histogram[tabSelected], GUILayout.Width(300f)); } if (GUILayout.Button("Calculate Histogram")) { histogram.alreadyCalculated = new bool[] { false, false, false, false }; histogram.histogram = new Texture2D[4]; for (int i = 0; i < 4; i++) { histogram.CalculateHistogramTexture(i); } } // AssetPreview.GetAssetPreview(histogram.GetHistogramTexture()); // GUI.Box(new Rect(0,0, 100, 100), "Colors"); // EditorGUI.DrawPreviewTexture(new Rect(0,0,100, 100), histogram.GetHistogramTexture()); }
public string Apply(int k, string fn, string outImagePath) { Bitmap srcimg = new Bitmap(fn); pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg); ColorHistogram colorHist = new ColorHistogram(pixels, false); int size = colorHist.getNumberOfColors(); if (size <= k) { srcimg.Save(outImagePath, ImageFormat.Png); } else { double[][] data = new double[size][]; getRGBData(colorHist, data); ClusterCollection clusters; KMeansParallel kMeans = new KMeansParallel(); clusters = kMeans.ClusterDataSet(k, data); PaintRGB(srcimg, kMeans, clusters).Save(outImagePath, ImageFormat.Png); } return(outImagePath); }
public AutoAdjustFilter(ColorHistogram colorHistogram, BrightnessHistogram brightnessHistogram) { ColorHistogram = colorHistogram; BrightnessHistogram = brightnessHistogram; }
public void CorrectComparisonMapTest() { var histogramService = new HistogramSorterService(); var histogram1 = new ColorHistogram( "randomId1", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); var histogram2 = new ColorHistogram( "randomId2", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.2 } ); var histogram3 = new ColorHistogram( "randomId3", new List <double> { 0.1 }, new List <double> { 0.1, 0.1 }, new List <double> { 0.1, 0.2, 0.4 } ); var selectedHistograms = new List <ColorHistogram> { histogram1, histogram2, histogram3 }; var comparisonMap = histogramService.CreateHistogramComparisonMap(selectedHistograms); Assert.True(comparisonMap.Count == 6); Assert.True( comparisonMap[new HistogramComparisonKeys("randomId1", "randomId2")] - Math.Pow(0.1, 2) < 0.001 ); Assert.True( comparisonMap[new HistogramComparisonKeys("randomId2", "randomId1")] - Math.Pow(0.1, 2) < 0.001 ); Assert.True( comparisonMap[new HistogramComparisonKeys("randomId1", "randomId3")] - 2 * Math.Pow(0.1, 2) < 0.001 ); Assert.True( comparisonMap[new HistogramComparisonKeys("randomId3", "randomId1")] - 2 * Math.Pow(0.1, 2) < 0.001 ); Assert.True( comparisonMap[new HistogramComparisonKeys("randomId2", "randomId3")] - (Math.Pow(0.1, 2) + Math.Pow(0.2, 2)) < 0.001 ); Assert.True( comparisonMap[new HistogramComparisonKeys("randomId3", "randomId2")] - (Math.Pow(0.1, 2) + Math.Pow(0.2, 2)) < 0.001 ); }
public void CorrectSortTest() { var histogramService = new HistogramSorterService(); var histogram1 = new ColorHistogram( "randomId1", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.3 } ); var histogram2 = new ColorHistogram( "randomId2", new List <double> { 0.1 }, new List <double> { 0.1, 0.2 }, new List <double> { 0.1, 0.2, 0.2 } ); var histogram3 = new ColorHistogram( "randomId3", new List <double> { 0.1 }, new List <double> { 0.1, 0.1 }, new List <double> { 0.1, 0.2, 0.4 } ); var histogram4 = new ColorHistogram( "randomId4", new List <double> { 0.2 }, new List <double> { 0.2, 0.1 }, new List <double> { 0.1, 0.2, 0.3 } ); var selectedHistograms = new List <ColorHistogram> { histogram1, histogram2, histogram3, histogram4 }; var comparisonMap = histogramService.CreateHistogramComparisonMap(selectedHistograms); var sortedHistograms = histogramService.SortSelectedHistograms( 2, 2, comparisonMap, selectedHistograms ); Assert.True(true); }