private void DrawDynamicResult(byte[] bytes, int width, int height) { var currentFolder = _dataFolders.Last(); //ДО того, что было var oldImageFolder = _dataFolders.First(); var oldDescription = new LandsatDataDescription(oldImageFolder); CuttedImageInfo oldCuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygon(oldDescription.Channel4.Raw, _polygon); DrawLib.DrawNaturalColor(oldDescription.Channel4.Normalized , oldDescription.Channel3.Normalized , oldDescription.Channel2.Normalized, oldCuttedImageInfo, _pathToVisibleImage + "-old.png"); var landsatDescription = new LandsatDataDescription(currentFolder); CuttedImageInfo cuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygon(landsatDescription.Channel4.Raw, _polygon); DrawLib.DrawMask(bytes, width, height, _pathToDynamicFile); DrawLib.DrawEdges(_pathToDynamicFile, _pathToEdgedDynamicFile); DrawChannelsAccordingToPhenomenonType(_phenomenon, landsatDescription, cuttedImageInfo); DrawLib.DrawMask(_pathToEdgedDynamicFile, _pathToVisibleImage + "4-3-2.png", _pathToVisibleDynamicFile); }
public static bool ValidateBuffers(IEnumerable <LandsatCuttedBuffers> temporaryBuffers) { var imagesSizes = new List <CuttedImageInfo>(); foreach (var temporaryDataBuffer in temporaryBuffers.SelectMany(b => b.Channels.Select(ch => ch.Value))) { var cuttedImageInfos = new CuttedImageInfo { Height = temporaryDataBuffer.GetLength(0), Width = temporaryDataBuffer.GetLength(1) }; imagesSizes.Add(cuttedImageInfos); } var currentImageInfo = imagesSizes.First(); foreach (var imageInfo in imagesSizes.Skip(1)) { if (currentImageInfo.Width == imageInfo.Width && currentImageInfo.Height == imageInfo.Height) { continue; } return(false); } return(true); }
public static CuttedImageInfo GetCuttedImageInfoByPolygonData(UtmPolygon utmPolygon, double[] geoTransform) { //utm-easting upperleft point var xinit = geoTransform[0]; //utm-northing upperleft point var yinit = geoTransform[3]; //размер пикселя var xsize = geoTransform[1]; var ysize = geoTransform[5]; var row1 = Convert.ToInt32((utmPolygon.UpperLeft.Northing - yinit) / ysize); var col1 = Convert.ToInt32((utmPolygon.UpperLeft.Easting - xinit) / xsize); var row2 = Convert.ToInt32((utmPolygon.LowerRight.Northing - yinit) / ysize); var col2 = Convert.ToInt32((utmPolygon.LowerRight.Easting - xinit) / xsize); var colSize = col2 - col1 + 1; var rowSize = row2 - row1 + 1; var cuttedImageInfo = new CuttedImageInfo { Col = col1, Row = row1, Width = colSize, Height = rowSize }; return(cuttedImageInfo); }
public override string[] Process(IGeographicPoint leftUpper, IGeographicPoint rigthLower, string dataFolder, string resultFolder) { LandsatDataDescription landsatDescription = new LandsatDataDescription(dataFolder); CuttedImageInfo cuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygon(landsatDescription.Channel4.Raw, new GeographicPolygon { UpperLeft = leftUpper, LowerRight = rigthLower }); string resultFileName; string redChannelFileName; string blueChannelFileName; string greenChannelFileName; switch (_characteristicType) { case CharacteristicType.Channels543: { redChannelFileName = landsatDescription.Channel5.Normalized; greenChannelFileName = landsatDescription.Channel4.Normalized; blueChannelFileName = landsatDescription.Channel3.Normalized; resultFileName = resultFolder + "5-4-3.jpg"; break; } case CharacteristicType.Channels753: { redChannelFileName = landsatDescription.Channel7.Normalized; greenChannelFileName = landsatDescription.Channel5.Normalized; blueChannelFileName = landsatDescription.Channel3.Normalized; resultFileName = resultFolder + "7-5-3.jpg"; break; } case CharacteristicType.Channels432: case CharacteristicType.Unknown: default: { redChannelFileName = landsatDescription.Channel4.Normalized; greenChannelFileName = landsatDescription.Channel3.Normalized; blueChannelFileName = landsatDescription.Channel2.Normalized; resultFileName = resultFolder + "4-3-2.jpg"; break; } } DrawLib.DrawNaturalColor(redChannelFileName , greenChannelFileName , blueChannelFileName, cuttedImageInfo, resultFileName); return(new string[] { resultFileName }); }
private static byte[] GetCloudMaskByBandAndCoordinates(Band qaBand, CuttedImageInfo imageInfo, byte[] cloudMask) { var buffer = new short[imageInfo.Width * imageInfo.Height]; qaBand.ReadRaster(imageInfo.Col, imageInfo.Row, imageInfo.Width, imageInfo.Height, buffer, imageInfo.Width, imageInfo.Height, 0, 0); byte[] currentCloudMask = buffer.Select(x => (byte)(IsCloud(x) ? 1 : 0)).ToArray(); for (int i = 0; i < cloudMask.Length; i++) { cloudMask[i] += currentCloudMask[i]; } return(cloudMask); }
/// <summary> /// Отрисовать картинку в видимом диапозоне /// </summary> /// <param name="redChannelFileName"></param> /// <param name="greenChannelFileName"></param> /// <param name="blueChannelFileName"></param> /// <param name="imageInfo"></param> /// <param name="resultFileName"></param> public static void DrawNaturalColor(string redChannelFileName, string greenChannelFileName, string blueChannelFileName, CuttedImageInfo imageInfo, string resultFileName) { var redChannel = new LandsatNormilizedSnapshotReader(redChannelFileName); var greenChannel = new LandsatNormilizedSnapshotReader(greenChannelFileName); var blueChannel = new LandsatNormilizedSnapshotReader(blueChannelFileName); //Коэф. для увеличения яркости var factor = 3.0f; int x = 0, y = 0; using (var bitmap = new Bitmap(imageInfo.Width, imageInfo.Height)) { for (var row = imageInfo.Row; row < imageInfo.Row + imageInfo.Height; row++) { double[] redBuffer = redChannel.ReadScanline(row); double[] greenBuffer = greenChannel.ReadScanline(row); double[] blueBuffer = blueChannel.ReadScanline(row); for (var col = imageInfo.Col; col < imageInfo.Col + imageInfo.Width; col++) { var redValue = CalculateValue(redBuffer[col], factor); var greenValue = CalculateValue(greenBuffer[col], factor); var blueValue = CalculateValue(blueBuffer[col], factor); var color = Color.FromArgb(redValue, greenValue, blueValue); //отображение зеленой картинки //var color = Color.FromArgb((byte) Math.Ceiling(redValue * 0.3f) // , (byte)Math.Ceiling(greenValue * 0.59f) // , (byte)Math.Ceiling(blueValue * 0.11f)); bitmap.SetPixel(y, x, color); y++; } y = 0; x++; } bitmap.Save(resultFileName, ImageFormat.Png); } redChannel.Dispose(); greenChannel.Dispose(); blueChannel.Dispose(); }
public static double[,] ReadBufferByIndexes(CuttedImageInfo cuttedImageInfo, LandsatNormilizedSnapshotReader reader) { var buffer = new double[cuttedImageInfo.Height, cuttedImageInfo.Width]; int i = 0, j = 0; for (var x = cuttedImageInfo.Row; x < cuttedImageInfo.Row + cuttedImageInfo.Height; x++) { foreach (var data in reader.ReadCuttedline(x, cuttedImageInfo.Col, cuttedImageInfo.Width)) { buffer[i, j] = data; j++; } j = 0; i++; } reader.Dispose(); return(buffer); }
public void CalculateNDWI(string channel5, string channel6, CuttedImageInfo cuttedImageInfo, string resultFolder) { var nirChannel = new LandsatNormilizedSnapshotReader(channel5); var swirChannel = new LandsatNormilizedSnapshotReader(channel6); var ndwiRanges = new List <Legend.Range> { new Legend.Range(-1.0, -0.8, Color.FromArgb(153, 92, 0)), new Legend.Range(-0.8, -0.6, Color.FromArgb(171, 122, 44)), new Legend.Range(-0.6, -0.4, Color.FromArgb(184, 146, 81)), new Legend.Range(-0.4, -0.2, Color.FromArgb(194, 158, 101)), new Legend.Range(-0.2, 0, Color.FromArgb(222, 206, 175)), new Legend.Range(0, 0.2, Color.FromArgb(141, 221, 252)), new Legend.Range(0.2, 0.4, Color.FromArgb(77, 161, 250)), new Legend.Range(0.4, 0.6, Color.FromArgb(41, 111, 217)), new Legend.Range(0.6, 0.8, Color.FromArgb(13, 66, 158)), new Legend.Range(0.8, 1.0, Color.FromArgb(4, 19, 89)), }; var legend = new Legend(ndwiRanges.ToArray()); var nirBuffer = ClipImageHelper.ReadBufferByIndexes(cuttedImageInfo, nirChannel); var swirBuffer = ClipImageHelper.ReadBufferByIndexes(cuttedImageInfo, swirChannel); // using (var bmp = DrawLib.CreateImageWithLegend(cuttedImageInfo.Width, cuttedImageInfo.Height, @"..\..\Content\NDWI.png")) using (var bmp = new Bitmap(cuttedImageInfo.Width, cuttedImageInfo.Height)) { for (var row = 0; row < cuttedImageInfo.Height; row++) { for (int col = 0; col < cuttedImageInfo.Width; col++) { var operator1 = nirBuffer[row, col] - swirBuffer[row, col]; var operator2 = nirBuffer[row, col] + swirBuffer[row, col]; var ndwi = operator1 / operator2; bmp.SetPixel(col, row, legend.GetColor(ndwi)); } } bmp.Save(resultFolder + "\\ndwi.png"); } }
private void DrawChannelsAccordingToPhenomenonType(PhenomenonType phenomenonType , LandsatDataDescription landsatDescription , CuttedImageInfo cuttedImageInfo) { switch (phenomenonType) { case PhenomenonType.ForestPlantationsDeseases: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); DrawLib.DrawNaturalColor(landsatDescription.Channel5.Normalized , landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized, cuttedImageInfo, _pathToVisibleImage + "5-4-3.png"); DrawLib.DrawNaturalColor(landsatDescription.Channel7.Normalized , landsatDescription.Channel5.Normalized , landsatDescription.Channel3.Normalized, cuttedImageInfo, _pathToVisibleImage + "7-5-3.png"); } break; case PhenomenonType.SoilErosion: { DrawLib.DrawNaturalColor(landsatDescription.Channel7.Normalized , landsatDescription.Channel5.Normalized , landsatDescription.Channel3.Normalized, cuttedImageInfo, _pathToVisibleImage + "7-5-3.png"); DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; case PhenomenonType.SoilPollutionByOilProducts: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; case PhenomenonType.SurfaceDumps: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; case PhenomenonType.Unknown: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; } }
public static void CalculateTemperature(Band band, double ml, double al, double K1, double K2, string resultFolder, CuttedImageInfo cuttedImageInfo) { var resultFilename = resultFolder + "\\temperature.png"; try { string[] filePaths = Directory.GetFiles(@"C:\diplom\EMS.net\EMS\Services\CharacterizationService\CharacterizationService\Content"); File.Copy(filePaths.Where(x => x.Contains("temperature_legend.png")).First(), resultFolder + "\\temperature_legend.png"); } catch (Exception e) { Console.WriteLine("Файл уже существует"); } var temperatureRanges = new List <Legend.Range> { //new Legend.Range(-30, -25, Color.FromArgb(60, 0, 255)), //new Legend.Range(-25, -20, Color.FromArgb(0, 0, 255)), //new Legend.Range(-20, -15, Color.FromArgb(0, 80, 255)), //new Legend.Range(-15, -10, Color.FromArgb(0, 150, 255)), //new Legend.Range(-10, -5, Color.FromArgb(150, 255, 255)), //new Legend.Range(-5, 0, Color.FromArgb(255, 255, 255)), //new Legend.Range(0, 5, Color.FromArgb(255, 255, 150)), //new Legend.Range(5, 10, Color.FromArgb(255, 250, 50)), //new Legend.Range(10, 15, Color.FromArgb(255, 180, 50)), //new Legend.Range(15, 20, Color.FromArgb(255, 100, 30)), //new Legend.Range(20, 25, Color.FromArgb(255, 80, 0)), //new Legend.Range(25, 30, Color.FromArgb(255, 55, 0)), //new Legend.Range(30, 35, Color.FromArgb(255, 45, 0)), //new Legend.Range(35, 40, Color.FromArgb(255, 35, 0)), //new Legend.Range(40, 45, Color.FromArgb(255, 0, 0)), //new Legend.Range(20, 25, Color.FromArgb(255, 80, 0)), //new Legend.Range(25, 30, Color.FromArgb(255, 55, 0)), //new Legend.Range(30, 35, Color.FromArgb(255, 45, 0)), //new Legend.Range(35, 40, Color.FromArgb(255, 35, 0)), //new Legend.Range(40, 45, Color.FromArgb(255, 0, 0)) }; using (band) { var width = cuttedImageInfo.Width; var heigth = cuttedImageInfo.Height; var legend = new Legend(5, 45, 5, Color.Yellow, Color.Red); double max = -100000; double min = 100000; //using (var bmp = DrawLib.CreateImageWithLegend(cuttedImageInfo.Width, cuttedImageInfo.Height, @"..\..\Content\temperature.png")) using (var bmp = new Bitmap(cuttedImageInfo.Width, cuttedImageInfo.Height)) { for (var row = 0; row < heigth; row++) { var buffer = new int[width]; band.ReadRaster(cuttedImageInfo.Col, cuttedImageInfo.Row + row, cuttedImageInfo.Width, 1, buffer, width, 1, 0, 0); for (var col = 0; col < width; col++) { if (buffer[col] != 0) { var rad = buffer[col] * ml + al; var temp = (K2 / Math.Log((K1 / rad) + 1)) - 273.15; max = temp > max ? temp : max; min = temp < min ? temp : min; bmp.SetPixel(col, row, legend.GetColor(temp)); } else { bmp.SetPixel(col, row, Color.Black); } } } bmp.Save(resultFilename); } } }