Ejemplo n.º 1
0
        public void RenderPseudoColor(ref WriteableBitmap bmp, short max = -1)
        {
            var redBand   = 11 - 1;
            var greenBand = 17 - 1;
            var blueBand  = 38 - 1;

            double[] minMax = new double[2];
            _dataset.GetRasterBand(redBand).ComputeRasterMinMax(minMax, 0);
            short redMax = (short)(minMax[1]);

            _dataset.GetRasterBand(greenBand).ComputeRasterMinMax(minMax, 0);
            short greenMax = (short)(minMax[1]);

            _dataset.GetRasterBand(blueBand).ComputeRasterMinMax(minMax, 0);
            short blueMax = (short)(minMax[1]);

            if (max == -1)
            {
                max = XMath.Max(blueMax, Math.Max(redMax, greenMax));
            }

            uint[] data = CalculationWrappers.CalculatePseudoColor(_datasetV.View, redBand, greenBand, blueBand, max);

            bmp = new WriteableBitmap(new PixelSize(width, height), new Vector(1, 1), Avalonia.Platform.PixelFormat.Rgba8888);

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy((int[])(object)data, 0, ptr, data.Length);
            }
        }
Ejemplo n.º 2
0
        public void ConvertToByteRepresentation(ref WriteableBitmap bmp, short maxValue)
        {
            if (maxValue == 0)
            {
                return;
            }

            var d = _datasetVByte;

            d?.Dispose();
            _datasetVByte = null;
            uint[] data;
            (_datasetVByte, data) = CalculationWrappers.ConvertToByteRepresentation(_datasetV.View, maxValue);

            bmp = new WriteableBitmap(new PixelSize(_datasetVByte.Width, _datasetVByte.Height), new Vector(1, 1), Avalonia.Platform.PixelFormat.Rgba8888);

            if (data != null)
            {
                using (var buf = bmp.Lock())
                {
                    IntPtr ptr = buf.Address;
                    Marshal.Copy((int[])(object)data, 0, ptr, data.Length);
                }
            }
        }
Ejemplo n.º 3
0
        public void RenderScanline(ref WriteableBitmap bmp, int band, int row, int column)
        {
            var data = CalculationWrappers.CalcScanlineImage(_datasetV.View, band, row, column);

            bmp = new WriteableBitmap(new Avalonia.PixelSize(width + depth, height + depth), new Vector(1, 1), Avalonia.Platform.PixelFormat.Rgba8888);

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy((int[])(object)data, 0, ptr, data.Length);
            }
        }
Ejemplo n.º 4
0
        public void RenderCorrelation(ref WriteableBitmap bmp)
        {
            int w = width, h = height;
            var index = new Index2(w, h);

            uint[] data = CalculationWrappers.GetCorrelationMap(index, _datasetV.View);

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy((int[])(object)data, 0, ptr, data.Length);
            }
        }
Ejemplo n.º 5
0
        public void RenderBand(ref WriteableBitmap bmp, int band)
        {
            // todo: MinMax should be calculated on GPU
            double[] minMax = new double[2];
            _dataset.GetRasterBand(band).ComputeRasterMinMax(minMax, 0);
            short  min  = (short)(minMax[0]);
            double mult = 255 / (minMax[1] - minMax[0]);

            uint[] data = CalculationWrappers.PictureConvertion(_datasetV.View, band, mult, min);

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy((int[])(object)data, 0, ptr, data.Length);
            }
        }
Ejemplo n.º 6
0
        public BrightnessCalculationData GetBrightnessCalculationData(ref WriteableBitmap bmp)
        {
            var result = new BrightnessCalculationData();

            result = CalculationWrappers.CalculateBrightnessStats(_datasetV.View, result);

            bmp = new WriteableBitmap(new PixelSize(result.imageSize.X, result.imageSize.Y), new Vector(1, 1), Avalonia.Platform.PixelFormat.Rgba8888);

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy(result.arrImage, 0, ptr, result.arrImage.Length);
            }

            return(result);
        }
Ejemplo n.º 7
0
        public HistogramData RenderHistogram(ref WriteableBitmap bmp)
        {
            var histData = new HistogramData();
            int w = width, h = height, d = depth;
            var index = new Index3(w, h, d);

            var histIndex = new Index2(1000, 1000);

            var data = CalculationWrappers.GetHistogram(index, _datasetV.View, histIndex, histData);

            bmp = new WriteableBitmap(new Avalonia.PixelSize(histIndex.X, histIndex.Y), new Vector(1, 1), Avalonia.Platform.PixelFormat.Rgba8888);

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy((int[])(object)data, 0, ptr, data.Length);
            }
            return(histData);
        }
Ejemplo n.º 8
0
        public void RenderPearsonCorrelation(ref WriteableBitmap bmp, byte lowThreshold = 0, byte highThreshold = 0)
        {
            var data = CalculationWrappers.CalculatePearsonCorrelation(_datasetVByte, lowThreshold, highThreshold);

            using (var img = new WriteableBitmap(new PixelSize(_datasetVByte.Width, _datasetVByte.Height), new Vector(1, 1), Avalonia.Platform.PixelFormat.Rgba8888))
            {
                string time = DateTime.Now.ToFileTime().ToString();
                using (var buf = img.Lock())
                {
                    IntPtr ptr = buf.Address;
                    Marshal.Copy((int[])(object)data.xyCorrelation, 0, ptr, data.xyCorrelation.Length);
                }
                img.Save($"{Program.PathToTemp}/PearsonCorrelation_{_datasetVByte.Depth}Bands_{(highThreshold == 0 ? "No" : highThreshold.ToString())}Threshold_{time}.png");

                OpenCvSharp.Mat mt = new OpenCvSharp.Mat(height, width, OpenCvSharp.MatType.CV_8U, data.rawPicture);
                mt.SaveImage($"{Program.PathToTemp}/PearsonCorrelation_{_datasetVByte.Depth}Bands_{(highThreshold == 0 ? "No" : highThreshold.ToString())}Threshold_{time}.bmp");
            }

            using (var buf = bmp.Lock())
            {
                IntPtr ptr = buf.Address;
                Marshal.Copy((int[])(object)data.xyCorrelation, 0, ptr, data.xyCorrelation.Length);
            }
        }