private void SaveImageTileAeroFile(XmlSerializer xmlSerializer, ImageTile imageTile, string path) { using (TextWriter tw = new StreamWriter(path + imageTile.FileName + ".aero")) { xmlSerializer.Serialize(tw, imageTile); } }
private async Task LoadFilmData() { BaseStorageHelper bsh = new BaseStorageHelper(); List <Uri> posterUrls = await bsh.GetImageList(); ImageTile it = new ImageTile() { Width = 300, Height = 300, Rows = 2, Columns = 3, Margin = new Thickness(20, 20, 0, 0), AnimationType = ImageTileAnimationTypes.Fade, ItemsSource = posterUrls }; Grid g = new Grid() { Width = 280, Height = 280, Margin = new Thickness(10) }; TextBlock tb = new TextBlock() { Text = "All Films", VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom }; Grid.SetRow(tb, 0); Grid.SetColumn(tb, 0); g.Children.Add(tb); it.Content = g; it.Click += ImageTile_Click; this.wpHubTiles.Children.Add(it); }
private RingSequence?CreateGroupKey(ImageTile tile) { var averagedColor = tile.Average(); return(_sequences .Select(x => (Item: x, Distance: RgbComparer.CompareByAmplitude(x.Color, averagedColor))) .Where(x => x.Distance < 0.2) .OrderBy(x => x.Distance) .FirstOrDefault().Item); }
public void GetDataWithoutBorder() { var tileData = TestTileData; var tile = new ImageTile(0, tileData); var expected = TestTileDataNoBorder; var actual = string.Join("\n", tile.GetDataWithoutBorder()); Assert.Equal(expected, actual); }
public void FlipX() { var tileData = TestTileData; var tile = new ImageTile(0, tileData); tile.DoFlipX(); var expectedNorth = ".#..#.##.."; Assert.Equal(expectedNorth, tile.BorderNorth); }
public void FlipY() { var tileData = TestTileData; var tile = new ImageTile(0, tileData); tile.DoFlipY(); var expectedEast = "#..##.#..."; Assert.Equal(expectedEast, tile.BorderEast); }
public static void Output(BackgroundWorker sender, ImageGrid g, string id_, string path) { ImageTile it = imageTiles[id_]; DateTime time = DateTime.Now; MainWindow.Log("Saving Image (" + it.worldX + " " + it.worldY + ")"); time = DateTime.Now; { for (int i = 0; i < MainWindow.classesList.Count; i += 4) { Classes c0 = MainWindow.classesList[i]; Classes c1 = i + 1 < MainWindow.classesList.Count ? MainWindow.classesList[i + 1] : null; Classes c2 = i + 2 < MainWindow.classesList.Count ? MainWindow.classesList[i + 2] : null; Classes c3 = i + 3 < MainWindow.classesList.Count ? MainWindow.classesList[i + 3] : null; string classesNames = c0.className.Replace(' ', '_'); classesNames += c1 != null?c1.className.Replace(' ', '_') : ""; classesNames += c2 != null?c2.className.Replace(' ', '_') : ""; classesNames += c3 != null?c3.className.Replace(' ', '_') : ""; string filename = path + "\\" + (it.worldY) + "_" + (it.worldX) + "_" + classesNames + ".png"; MainWindow.dispatcher.Invoke(() => { ImageHelper.ExportClassification(it.id, c0, c1, c2, c3, filename, ref Stitch, i / 4, ref StichLock); }); } } MainWindow.dispatcher.Invoke(() => g.RemoveTile(it.tileX, it.tileY) ); float t = (float)(DateTime.Now - time).TotalSeconds; averageOutputTime = (averageOutputTime * outputDone + t) / (outputDone + 1); outputDone++; ReportProgress(sender); MainWindow.Log("Image (" + it.worldX + " " + it.worldY + ") saved in " + t + "s. Done"); GC.Collect(); }
private async Task LoadFilmData() { BaseStorageHelper bsh = new BaseStorageHelper(); List <Uri> posterUrls = await bsh.GetImageList(); ImageTile it = new ImageTile() { Width = 410, Height = 200, LargeTileColumns = 1, LargeTileRows = 1, Rows = 1, Columns = 3, Margin = new Thickness(0, 0, 10, 10), AnimationType = ImageTileAnimationTypes.Fade, ItemsSource = posterUrls }; Grid g = new Grid() { Width = 480, Height = 200, Margin = new Thickness(0) }; g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); TextBlock tb = new TextBlock() { Text = "All Films", VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom, Margin = new Thickness(10) }; Border b = new Border() { Background = new SolidColorBrush(Colors.Gray), Opacity = 0.9 }; b.Child = tb; Grid.SetRow(b, 0); Grid.SetColumn(b, 0); g.Children.Add(b); it.Content = g; ToolTipService.SetToolTip(it, "Click to view all films"); it.Click += ImageTile_Click; this.wpHubTiles.Children.Add(it); }
public void Rotate_4Times() { var tileData = TestTileData; var tile = new ImageTile(0, tileData); var(n, s, e, w) = (tile.BorderNorth, tile.BorderSouth, tile.BorderEast, tile.BorderWest); tile.DoRotateRight(); tile.DoRotateRight(); tile.DoRotateRight(); tile.DoRotateRight(); Assert.Equal(0, tile.Rotation); Assert.Equal(n, tile.BorderNorth); Assert.Equal(s, tile.BorderSouth); Assert.Equal(e, tile.BorderEast); Assert.Equal(w, tile.BorderWest); }
public void Rotate() { var tileData = TestTileData; var tile = new ImageTile(0, tileData); var expectedNorth = tile.BorderWest; var expectedEast = tile.BorderNorth; var expectedSouth = tile.BorderEast; var expectedWest = tile.BorderSouth; tile.DoRotateRight(); Assert.Equal(90, tile.Rotation); Assert.Equal(expectedNorth, tile.BorderNorth.Reverse()); Assert.Equal(expectedEast, tile.BorderEast); Assert.Equal(expectedSouth, tile.BorderSouth.Reverse()); Assert.Equal(expectedWest, tile.BorderWest); }
private static bool canOutput(ImageGrid g, ImageTile it) { if (!postProcessed[it.tileX, it.tileY]) { return(false); } for (int x = Math.Max(0, it.tileX - 1); x <= Math.Min(g.width - 1, it.tileX + 1); x++) { for (int y = Math.Max(0, it.tileY - 1); y <= Math.Min(g.height - 1, it.tileY + 1); y++) { if (!postProcessed[x, y]) { return(false); } } } return(true); }
public void Part1Test() { // Given var tiles = Input.GetGroups(20).Select(ImageTile.Parse).ToList(); // When var image = ImageTile.Arrange(tiles); Assert.NotNull(image); var width = image.GetLength(0); var height = image.GetLength(1); var topLeft = image[0, 0]; var topRight = image[width - 1, 0]; var bottomLeft = image[0, height - 1]; var bottomRight = image[width - 1, height - 1]; // Then Assert.Equal(20899048083289, (long)topLeft.Id * topRight.Id * bottomLeft.Id * bottomRight.Id); }
// Note: This will probably only work well with OBJ files generated by Pix4D // as I have only supported the subset of data types it outputs. static void Main(string[] args) { var opt = CliParser.Parse <Options>(args); foreach (string path in opt.Input) { // Check if we are processing an image or a mesh if (Path.GetExtension(path).ToUpper().EndsWith("JPG")) { ImageTile tiler = new ImageTile(path, opt.xSize, opt.ySize); tiler.GenerateTiles(opt.OutputPath); } else { CubeManager manager = new CubeManager(path, opt.xSize, opt.ySize, opt.zSize); manager.GenerateCubes(Path.Combine(opt.OutputPath, Path.GetFileNameWithoutExtension(path))); } } Console.WriteLine("Complete"); }
protected override void Initialize() { //var content = GetExample(); var content = ReadFile(); Tiles = new List <ImageTile>(); ImageTile imageTile = null; var imageLineIndex = 0; foreach (var line in content) { var imageSize = line.Length; if (line == string.Empty) { // End of tile imageLineIndex = 0; } else if (line.StartsWith("Tile")) { // Start of new tile var splitLine = line.TrimEnd(':').Split(' '); var tileNumber = int.Parse(splitLine[1]); imageTile = new ImageTile(tileNumber, imageSize); Tiles.Add(imageTile); } else { // Image imageTile.Image[imageLineIndex] = line; imageLineIndex++; } } // Set the edges for each tile foreach (var tile in Tiles) { tile.SetEdges(); } }
private void DownloadFile(HttpClient httpClient, CookieContainer cookieContainer, ImageTile imageTile, string path, OrthophotoSource orthophotoSource) { string fullFilePath = path + imageTile.FileName + "." + imageTile.ImageExtension; cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri(imageTile.URL), new Cookie("APISID", Guid.NewGuid().ToString())); cookieContainer.Add(new Uri(imageTile.URL), new Cookie("NID", "119=" + Guid.NewGuid().ToString())); cookieContainer.Add(new Uri(imageTile.URL), new Cookie("NID", "129=" + Guid.NewGuid().ToString())); httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(AeroSceneryManager.Instance.Settings.UserAgent); httpClient.DefaultRequestHeaders.Referrer = new Uri("http://google.com/"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.5"); httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate"); httpClient.DefaultRequestHeaders.Add("Accept", "application/json, text/javascript, */*; q=0.01"); try { var responseResult = httpClient.GetAsync(imageTile.URL); bool saveFile = true; // If we are Bing we might be served a valid image but there is really no tile available if (orthophotoSource == OrthophotoSource.Bing) { // Check the Bing tile info header if (responseResult.Result.Headers.Contains("X-VE-Tile-Info")) { var tileInfoHeaderValue = responseResult.Result.Headers.GetValues("X-VE-Tile-Info").FirstOrDefault(); // If there is really no file, the header value will be no-tile // In this case we shouldn't save the image if (tileInfoHeaderValue == "no-tile") { saveFile = false; } } } if (saveFile) { using (var memStream = responseResult.Result.Content.ReadAsStreamAsync().Result) { using (var fileStream = File.Create(fullFilePath)) { var fileSize = memStream.Length; if (fileSize == 1033) { var afd = "asdf"; } memStream.CopyTo(fileStream); } } } } catch (Exception ex) { log.Error("There was an error downloading " + imageTile.URL, ex); } finally { } }
// Note: This will probably only work well with OBJ files generated by Pix4D // as I have only supported the subset of data types it outputs. static void Main(string[] args) { Options opt; // Setup a timer for all operations Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { opt = CliParser.Parse <Options>(args); foreach (string path in opt.Input) { // Check if we are processing an image or a mesh if (Path.GetExtension(path).ToUpper().EndsWith("JPG")) { ImageTile tiler = new ImageTile(path, opt.XSize, opt.YSize); tiler.GenerateTiles(opt.OutputPath); } else if (Path.GetExtension(path).ToUpper().EndsWith("OBJ")) { // Generate subfolders named after input file // if multiple input files are provided string outputPath; if (opt.Input.Count == 1) { outputPath = opt.OutputPath; } else { outputPath = Path.Combine(opt.OutputPath, Path.GetFileNameWithoutExtension(path)); } if (opt.ForceCubical) { int longestGridSide = Math.Max(Math.Max(opt.XSize, opt.YSize), opt.ZSize); opt.XSize = opt.YSize = opt.ZSize = longestGridSide; Console.WriteLine("Due to -ForceCubical grid size is now {0},{0},{0}", longestGridSide); } var options = new SlicingOptions { OverrideMtl = opt.MtlOverride, GenerateEbo = opt.Ebo, GenerateOpenCtm = opt.OpenCtm, Debug = opt.Debug, GenerateObj = opt.Obj, Texture = opt.Texture, Obj = path, WriteMtl = opt.WriteMtl, TextureScale = opt.ScaleTexture, TextureSliceX = opt.TextureXSize, TextureSliceY = opt.TextureYSize, ForceCubicalCubes = opt.ForceCubical, CubeGrid = new Vector3 { X = opt.XSize, Y = opt.YSize, Z = opt.ZSize } }; CubeManager manager = new CubeManager(options); if (opt.MarkupUV) { Texture tex = new Texture(manager.ObjInstance); tex.MarkupTextureFaces(opt.Texture); } else { manager.GenerateCubes(outputPath, options); } } else { Console.WriteLine("PyriteCli only accepts .jpg and .obj files for input."); } } } catch (ParserExit) { return; } catch (ParseException ex) { Console.WriteLine("usage: PyriteCli --help\n" + ex.ToString()); } stopwatch.Stop(); Trace.TraceInformation(stopwatch.Elapsed.ToString()); }
public static void PostProcess(BackgroundWorker sender, ImageGrid g, string id_, int NStep, int blurRadius) { ImageTile it = imageTiles[id_]; DateTime time = DateTime.Now; MainWindow.Log("Postprocessing Image (" + it.worldX + " " + it.worldY + ")"); try { //First Erase the not more useful color image images.TryRemove(it.baseFileName, out PixelColor[,] r); it.Status(new PixelColor(255, 0, 120, 100)); for (int step = 0; step < NStep; step++) { for (int _x = 0; _x < 256; _x++) { for (int _y = 0; _y < 256; _y++) { int centralClass = -1; int maxClass = -1; int maxValue = -1; int[] counters = new int[MainWindow.classesList.Count]; for (int i = 0; i < counters.Length; i++) { if (MainWindow.classesList[i].classifiedPointsList[it.id][_y, _x] != null) { centralClass = i; break; } } int radius = MainWindow.classesList[centralClass].radius; for (int x = _x - radius; x <= _x + radius; x++) { for (int y = _y - radius; y <= _y + radius; y++) { bool found = false; int tileX = it.tileX; int tileY = it.tileY; int x_ = x; int y_ = y; if (x >= 0 && x < 256 && y > 0 && y < 256) { found = true; } else if (x < 0 && it.tileX > 0) { tileX -= 1; x_ += 256; if (y < 0 && it.tileY > 0) { tileY -= 1; y_ += 256; } else if (y >= 256 && it.tileY < g.height - 1) { tileY += 1; y_ -= 256; } else { continue; } } else if (x >= 256 && it.tileX < g.width - 1) { tileX += 1; x_ -= 256; if (y < 0 && it.tileY > 0) { tileY -= 1; y_ += 256; } else if (y >= 256 && it.tileY < g.height - 1) { tileY += 1; y_ -= 256; } else { continue; } } else if (x >= 0 && x < 256) { if (y < 0 && it.tileY > 0) { tileY -= 1; y_ += 256; } else if (y >= 255 && it.tileY < g.height - 1) { tileY += 1; y_ -= 256; } else { continue; } } else { continue; } for (int i = 0; i < counters.Length; i++) { string id; if (found) { id = it.id; } else { id = g.tiles[tileX, tileY].id; } if (MainWindow.classesList[i].classifiedPointsList.ContainsKey(id)) { if (MainWindow.classesList[i].classifiedPointsList[id][y_, x_] != null) { counters[i]++; if (maxValue < counters[i]) { maxValue = counters[i]; maxClass = i; } break; } } else { MainWindow.Log("ERROR with Image (" + it.worldX + " " + it.worldY + ") while postprocessing: Image with id " + id + " is not present in classified points. Trying to continue execution without it."); } } } } if (counters[centralClass] < MainWindow.classesList[centralClass].threshold) { MainWindow.classesList[centralClass].classifiedPointsList[it.id][_y, _x] = null; MainWindow.classesList[maxClass].classifiedPointsList[it.id][_y, _x] = (FeaturePoint.GetOrAddFeaturePoint(_x, _y, it.id)); } } } } MainWindow.dispatcher.Invoke(() => { foreach (Classes c in MainWindow.classesList) { for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { FeaturePoint fp = c.classifiedPointsList[it.id][i, j]; if (fp != null) { ImageHelper.DrawOverlayClass(it.id, fp.x, fp.y, c, c.classColor); } } } } // BluringEdges_4(MainWindow.Instance, it.id, blurRadius); }); postProcessed[it.tileX, it.tileY] = true; float t = (float)(DateTime.Now - time).TotalSeconds; averagePostprocessTime = (averagePostprocessTime * postprocessgDone + t) / (postprocessgDone + 1); postprocessgDone++; ReportProgress(sender); postprocessQueue--; MainWindow.Log("Image (" + it.worldX + " " + it.worldY + ") postprocessing done in " + t + "s. Now waiting for output and dispose"); postprocessDoneQueue.Enqueue(id_); it.Status(new PixelColor(0, 0, 0, 0)); GC.Collect(); } catch (Exception e) { MainWindow.Log("ERROR when postprocessing Image (" + it.worldX + " " + it.worldY + "): " + e.Message); it.Status(new PixelColor(0, 0, 255, 100)); if (postProcessed[it.tileX, it.tileY]) { postprocessQueue++; postprocessgDone--; } postProcessed[it.tileX, it.tileY] = false; it.Unlock(); ErrorPostProcessingQueue.Enqueue(id_); GC.Collect(); } }
public static void Classifiy(BackgroundWorker sender, ImageGrid g, ClassifyProcessParam p, int classifier, int NStep, string path, int blurRadius) { MainWindow.Log("Loading Image (" + p.WorldX + " " + p.WorldY + ")"); DateTime time = DateTime.Now; ImageTile it = null; int max = (int)Math.Pow(2, p.zoom); int TileX = p.TileX - 1; for (int x = p.WorldX - 1; x <= p.WorldX + 1; x++, TileX++) { int TileY = p.TileY - 1; for (int y = p.WorldY - 1; y <= p.WorldY + 1; y++, TileY++) { if (x >= 0 && x < max && y >= 0 && y < max && TileX >= 0 && TileX < g.width && TileY >= 0 && TileY < g.height) { string id = g.id + "_" + p.zoom + "_" + y + "_" + x; string filename = "tmp\\sat\\" + (p.zoom) + "_" + (y) + "_" + (x) + ".png"; if (x == p.WorldX && y == p.WorldY) { MainWindow.dispatcher.Invoke(() => { if (imageTiles.ContainsKey(id)) { it = imageTiles[id]; } else { it = new ImageTile(MainWindow.Instance, g, filename, id, p.zoom, TileX, TileY, false); } }); } else { MainWindow.dispatcher.Invoke(() => { if (!imageTiles.ContainsKey(id)) { ImageTile it_ = new ImageTile(MainWindow.Instance, g, filename, id, p.zoom, TileX, TileY, false); g.AddTile(it_); } }); } } } } if (it == null) { return; } g.AddTile(it); it.Status(new PixelColor(0, 255, 255, 100)); it.classified = false; it.Lock(); MainWindow.Log("Classifying Image (" + p.WorldX + " " + p.WorldY + ")"); try { MainWindow.dispatcher.Invoke(() => { foreach (Classes c in MainWindow.classesList) { g.AddOverlayClass(it, c, MainWindow.Instance); if (c.classifiedPointsList.ContainsKey(it.id)) { c.classifiedPointsList.Remove(it.id); } c.classifiedPointsList.Add(it.id, new FeaturePoint[256, 256]); } }); Parallel.For(0, 256, x => { for (int y = 0; y < 256; y++) { FeaturePoint fp = FeaturePoint.GetOrAddFeaturePoint(x, y, it.id); var output = Array.Empty <double>(); switch (classifier) { case 0: dfprocess(MainWindow.Instance.DecisionForest, fp.GetFeatures(), ref output); break; case 1: mlpprocess(MainWindow.Instance.NeuralNetwork, fp.GetFeatures(), ref output); break; case 2: mlpeprocess(MainWindow.Instance.NeuralNetworkEnsemble, fp.GetFeatures(), ref output); break; default: break; } int predictedClass = 0; for (int k = 1; k < output.Length; k++) { if (output[k] > output[predictedClass]) { predictedClass = k; } } MainWindow.GetClassByNum(predictedClass).classifiedPointsList[it.id][fp.y, fp.x] = fp; } }); it.Unlock(); it.classified = true; float t = (float)(DateTime.Now - time).TotalSeconds; averageClassificationTime = (averageClassificationTime * classificationDone + t) / (classificationDone + 1); classificationDone++; ReportProgress(sender); classificationQueue--; MainWindow.Log("Image (" + p.WorldX + " " + p.WorldY + ") Classification done in " + t + "s. Now waiting for postprocessing"); GC.Collect(); it.Status(new PixelColor(0, 255, 0, 100)); classificationDoneQueue.Enqueue(it.id); } catch (Exception e) { MainWindow.Log("ERROR when classifying Image (" + p.WorldX + " " + p.WorldY + "): " + e.Message); it.Status(new PixelColor(0, 0, 255, 100)); if (it.classified) { classificationQueue++; classificationDone--; } it.classified = false; it.Unlock(); errorClassificationRecoveryQueue.Enqueue(p); GC.Collect(); } }
/// <summary> /// Изучить способность хоть один раз /// </summary> public void UpSpell(Player player) { LevelCast += 1; ImageTile.UpSpell(); }
private void ALL_GLCM(int half_size, int[] disp0, int[] disp1, int[] disp2, int[] disp3, ref double[] ret) { int MATRIX_SIZE = 8; double[,] matrix0 = new double[MATRIX_SIZE, MATRIX_SIZE]; double[,] matrix1 = new double[MATRIX_SIZE, MATRIX_SIZE]; double[,] matrix2 = new double[MATRIX_SIZE, MATRIX_SIZE]; double[,] matrix3 = new double[MATRIX_SIZE, MATRIX_SIZE]; double total0 = 0; double total1 = 0; double total2 = 0; double total3 = 0; ImageTile it = ImageHelper.imageTiles[imageId]; for (int px = x - half_size; px < x + half_size; px++) { if (px < 0 && it.tileX == 0) { continue; } if (px > 255 && it.tileX > it.grid.width) { continue; } for (int py = y - half_size; py < y + half_size; py++) { if (py < 0 && it.tileY == 0) { continue; } if (py > 255 && it.tileY > it.grid.height) { continue; } int i = (int)Math.Round(Luminance(ImageHelper.Get(imageId, px, py)) * (MATRIX_SIZE - 1)); int px2 = px + disp0[0]; int py2 = py + disp0[1]; int j = (int)Math.Round(Luminance(ImageHelper.Get(imageId, px2, py2)) * (MATRIX_SIZE - 1)); matrix0[i, j]++; total0++; px2 = px + disp1[0]; py2 = py + disp1[1]; j = (int)Math.Round(Luminance(ImageHelper.Get(imageId, px2, py2)) * (MATRIX_SIZE - 1)); matrix1[i, j]++; total1++; px2 = px + disp2[0]; py2 = py + disp2[1]; j = (int)Math.Round(Luminance(ImageHelper.Get(imageId, px2, py2)) * (MATRIX_SIZE - 1)); matrix2[i, j]++; total2++; px2 = px + disp3[0]; py2 = py + disp3[1]; j = (int)Math.Round(Luminance(ImageHelper.Get(imageId, px2, py2)) * (MATRIX_SIZE - 1)); matrix3[i, j]++; total3++; } } double mu0x = 0; double sig0x = 0; double mu1x = 0; double sig1x = 0; double mu2x = 0; double sig2x = 0; double mu3x = 0; double sig3x = 0; double mu0y = 0; double sig0y = 0; double mu1y = 0; double sig1y = 0; double mu2y = 0; double sig2y = 0; double mu3y = 0; double sig3y = 0; for (int i = 0; i < MATRIX_SIZE; i++) { for (int j = 0; j < MATRIX_SIZE; j++) { if (total0 != 0) { matrix0[i, j] /= total0; } if (total1 != 0) { matrix1[i, j] /= total1; } if (total2 != 0) { matrix2[i, j] /= total2; } if (total3 != 0) { matrix3[i, j] /= total3; } mu0x += (i + 1) * matrix0[i, j]; mu1x += (i + 1) * matrix1[i, j]; mu2x += (i + 1) * matrix2[i, j]; mu3x += (i + 1) * matrix3[i, j]; mu0y += (j + 1) * matrix0[i, j]; mu1y += (j + 1) * matrix1[i, j]; mu2y += (j + 1) * matrix2[i, j]; mu3y += (j + 1) * matrix3[i, j]; } } for (int i = 0; i < MATRIX_SIZE; i++) { for (int j = 0; j < MATRIX_SIZE; j++) { sig0x += (i + 1 - mu0x) * (i + 1 - mu0x) * matrix0[i, j]; sig1x += (i + 1 - mu1x) * (i + 1 - mu1x) * matrix1[i, j]; sig2x += (i + 1 - mu2x) * (i + 1 - mu2x) * matrix2[i, j]; sig3x += (i + 1 - mu3x) * (i + 1 - mu3x) * matrix3[i, j]; sig0y += (j + 1 - mu0y) * (j + 1 - mu0y) * matrix0[i, j]; sig1y += (j + 1 - mu1y) * (j + 1 - mu1y) * matrix1[i, j]; sig2y += (j + 1 - mu2y) * (j + 1 - mu2y) * matrix2[i, j]; sig3y += (j + 1 - mu3y) * (j + 1 - mu3y) * matrix3[i, j]; } } double sig0 = Math.Sqrt(sig0x * sig0y); double sig1 = Math.Sqrt(sig1x * sig1y); double sig2 = Math.Sqrt(sig2x * sig2y); double sig3 = Math.Sqrt(sig3x * sig3y); for (int i = 0; i < MATRIX_SIZE; i++) { for (int j = 0; j < MATRIX_SIZE; j++) { double ij2 = Math.Pow(i - j, 2); double inv_abs = 1.0 / (1 + (i - j) * (i - j)); ret[0] += ij2 * matrix0[i, j]; //Contrast ret[1] -= matrix0[i, j] <= 0 ? 0 : matrix0[i, j] * Math.Log(matrix0[i, j]); //Entropy ret[2] += Math.Pow(matrix0[i, j], 2); //Uniformity; ret[3] += matrix0[i, j] * inv_abs; // Homogeneity ret[4] += sig0 == 0 ? 0 : matrix0[i, j] * (i + 1 - mu0x) * (j + 1 - mu0y) / sig0; //Correlation ret[6] += ij2 * matrix1[i, j]; //Contrast ret[7] -= matrix1[i, j] <= 0 ? 0 : matrix1[i, j] * Math.Log(matrix1[i, j]); //Entropy ret[8] += Math.Pow(matrix1[i, j], 2); //Uniformity; ret[9] += matrix1[i, j] * inv_abs; // Homogeneity ret[10] += sig1 == 0 ? 0 : matrix1[i, j] * (i + 1 - mu1x) * (j + 1 - mu1y) / sig1; //Correlation ret[12] += ij2 * matrix2[i, j]; //Contrast ret[13] -= matrix2[i, j] <= 0 ? 0 : matrix2[i, j] * Math.Log(matrix2[i, j]); //Entropy ret[14] += Math.Pow(matrix2[i, j], 2); //Uniformity; ret[15] += matrix2[i, j] * inv_abs; // Homogeneity ret[16] += sig2 == 0 ? 0 : matrix2[i, j] * (i + 1 - mu2x) * (j + 1 - mu2y) / sig2; //Correlation ret[18] += ij2 * matrix3[i, j]; //Contrast ret[19] -= matrix3[i, j] <= 0 ? 0 : matrix3[i, j] * Math.Log(matrix3[i, j]); //Entropy ret[20] += Math.Pow(matrix3[i, j], 2); //Uniformity; ret[21] += matrix3[i, j] * inv_abs; // Homogeneity ret[22] += sig3 == 0 ? 0 : matrix3[i, j] * (i + 1 - mu3x) * (j + 1 - mu3y) / sig3; //Correlation } } for (int i = 0; i < MATRIX_SIZE; i++) { for (int j = 0; j < MATRIX_SIZE; j++) { ret[5] += sig0 == 0 ? 0 : Math.Pow(i + 1 + j + 1 - 2 * mu0x, 3) * matrix0[i, j] / (Math.Pow(sig0 * 2 * (1 + ret[4]), 1.5)); ret[11] += sig1 == 0 ? 0 : Math.Pow(i + 1 + j + 1 - 2 * mu1x, 3) * matrix0[i, j] / (Math.Pow(sig1 * 2 * (1 + ret[10]), 1.5)); ret[17] += sig2 == 0 ? 0 : Math.Pow(i + 1 + j + 1 - 2 * mu2x, 3) * matrix0[i, j] / (Math.Pow(sig2 * 2 * (1 + ret[16]), 1.5)); ret[23] += sig3 == 0 ? 0 : Math.Pow(i + 1 + j + 1 - 2 * mu3x, 3) * matrix0[i, j] / (Math.Pow(sig3 * 2 * (1 + ret[22]), 1.5)); } } try { ret[5] = Math.Sign(ret[5]) * Math.Pow(Math.Abs(ret[5]), 1.0 / 3.0); ret[11] = Math.Sign(ret[11]) * Math.Pow(Math.Abs(ret[11]), 1.0 / 3.0); ret[17] = Math.Sign(ret[17]) * Math.Pow(Math.Abs(ret[17]), 1.0 / 3.0); ret[23] = Math.Sign(ret[23]) * Math.Pow(Math.Abs(ret[23]), 1.0 / 3.0); } catch { ret[5] = 0; ret[11] = 0; ret[17] = 0; ret[23] = 0; } }
public List <ImageTile> ImageTilesForGridSquares(AFS2GridSquare afs2GridSquare, int zoomLevel) { List <ImageTile> imageTiles = new List <ImageTile>(); // Just to make the code more readable var northWestCorner = afs2GridSquare.Coordinates[0]; var northEastCorner = afs2GridSquare.Coordinates[1]; var southEastCorner = afs2GridSquare.Coordinates[2]; var southWestCorner = afs2GridSquare.Coordinates[3]; // Get the pixel X & Y of the first tile int pixelX = 0; int pixelY = 0; BingHelper.LatLongToPixelXY(northWestCorner.Lat, northWestCorner.Lng, zoomLevel, out pixelX, out pixelY); // Get the tile X & Y of the frst tile int tileX = 0; int tileY = 0; BingHelper.PixelXYToTileXY(pixelX, pixelY, out tileX, out tileY); double currentTileNorthLatitude = 0; double currentTileSouthLatitude = 0; double currentTileWestLongitude = 0; double currentTileEastLongitude = 0; int currentTileX = tileX; int currentTileY = tileY; int currentRow = 1; int currentColumn = 1; // Work through the tiles East to West, then top North to South do { do { int currentPixelX; int currentPixelY; BingHelper.TileXYToPixelXY(currentTileX, currentTileY, out currentPixelX, out currentPixelY); BingHelper.PixelXYToLatLong(currentPixelX, currentPixelY, zoomLevel, out currentTileNorthLatitude, out currentTileWestLongitude); // Get the lat long of the tile "to the left and down", which will give us the south and east edge of the previous tile int currentTileXPlusOnePixelX; int currentTileYPlusOnePixelY; BingHelper.TileXYToPixelXY(currentTileX + 1, currentTileY + 1, out currentTileXPlusOnePixelX, out currentTileYPlusOnePixelY); BingHelper.PixelXYToLatLong(currentTileXPlusOnePixelX, currentTileYPlusOnePixelY, zoomLevel, out currentTileSouthLatitude, out currentTileEastLongitude); var quadKey1 = BingHelper.TileXYToQuadKey(currentTileX, currentTileY, zoomLevel); ImageTile tile = new ImageTile(); tile.Width = 256; tile.Height = 256; tile.NorthLatitude = currentTileNorthLatitude; tile.SouthLatitude = currentTileSouthLatitude; tile.WestLongitude = currentTileWestLongitude; tile.EastLongitude = currentTileEastLongitude; tile.ImageExtension = "jpg"; tile.TileX = currentTileX; tile.TileY = currentTileY; tile.LocalTileX = currentColumn; tile.LocalTileY = currentRow; tile.Source = "b"; tile.ZoomLevel = zoomLevel; tile.URL = String.Format(this.urlTemplate, quadKey1); imageTiles.Add(tile); currentTileX++; currentColumn++; }while (currentTileWestLongitude < southEastCorner.Lng); // Go back to the original tileX currentTileX = tileX; // Start at column 1 again currentColumn = 1; // Do the next row currentTileY++; currentRow++; }while (currentTileNorthLatitude > southEastCorner.Lat); return(imageTiles); }
private void DownloadFile(HttpClient httpClient, CookieContainer cookieContainer, ImageTile imageTile, string path) { string fullFilePath = path + imageTile.FileName + "." + imageTile.ImageExtension; cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri(imageTile.URL), new Cookie("APISID", Guid.NewGuid().ToString())); cookieContainer.Add(new Uri(imageTile.URL), new Cookie("NID", "119=" + Guid.NewGuid().ToString())); cookieContainer.Add(new Uri(imageTile.URL), new Cookie("NID", "129=" + Guid.NewGuid().ToString())); httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(AeroSceneryManager.Instance.Settings.UserAgent); httpClient.DefaultRequestHeaders.Referrer = new Uri("http://google.com/"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.5"); httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate"); httpClient.DefaultRequestHeaders.Add("Accept", "application/json, text/javascript, */*; q=0.01"); try { var responseResult = httpClient.GetAsync(imageTile.URL); using (var memStream = responseResult.Result.Content.ReadAsStreamAsync().Result) { using (var fileStream = File.Create(fullFilePath)) { memStream.CopyTo(fileStream); } } } catch (Exception ex) { log.Error("There was an error downloading " + imageTile.URL, ex); } finally { } }