Beispiel #1
0
        /// <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);
        }