Пример #1
0
        public void AplyWhiteBalance(string imagePath, string outImagePath)
        {
            using (Dataset image = Gdal.Open(imagePath, Access.GA_ReadOnly)) {
                Band redBand   = GdalUtilities.GetBand(image, ColorInterp.GCI_RedBand);
                Band greenBand = GdalUtilities.GetBand(image, ColorInterp.GCI_GreenBand);
                Band blueBand  = GdalUtilities.GetBand(image, ColorInterp.GCI_BlueBand);

                if (redBand == null || greenBand == null || blueBand == null)
                {
                    throw new NullReferenceException("One or more bands are not available.");
                }

                int width  = redBand.XSize;
                int height = redBand.YSize;

                using (Dataset outImage = Gdal.GetDriverByName("GTiff").Create(outImagePath, width, height, 3, DataType.GDT_Byte, null)) {
                    double[] geoTransformerData = new double[6];
                    image.GetGeoTransform(geoTransformerData);
                    outImage.SetGeoTransform(geoTransformerData);
                    outImage.SetProjection(image.GetProjection());

                    Band outRedBand   = GdalUtilities.GetBand(outImage, ColorInterp.GCI_RedBand);
                    Band outGreenBand = GdalUtilities.GetBand(outImage, ColorInterp.GCI_GreenBand);
                    Band outBlueBand  = GdalUtilities.GetBand(outImage, ColorInterp.GCI_BlueBand);

                    int[] red   = new int[width * height];
                    int[] green = new int[width * height];
                    int[] blue  = new int[width * height];
                    redBand.ReadRaster(0, 0, width, height, red, width, height, 0, 0);
                    greenBand.ReadRaster(0, 0, width, height, green, width, height, 0, 0);
                    blueBand.ReadRaster(0, 0, width, height, blue, width, height, 0, 0);

                    int[] outRed   = WhiteBalanceBand(red);
                    int[] outGreen = WhiteBalanceBand(green);
                    int[] outBlue  = WhiteBalanceBand(blue);
                    outRedBand.WriteRaster(0, 0, width, height, outRed, width, height, 0, 0);
                    outGreenBand.WriteRaster(0, 0, width, height, outGreen, width, height, 0, 0);
                    outBlueBand.WriteRaster(0, 0, width, height, outBlue, width, height, 0, 0);

                    outImage.FlushCache();
                }
            }
        }
Пример #2
0
        private List <double[]> readImageCoordinatesBoundsInLonLat(Dataset imageDataset)
        {
            var band = imageDataset.GetRasterBand(1);

            if (band == null)
            {
                return(null);
            }

            var width  = band.XSize;
            var height = band.YSize;

            double[] geoTransformerData = new double[6];
            imageDataset.GetGeoTransform(geoTransformerData);


            SpatialReference         currentReference = new SpatialReference(imageDataset.GetProjectionRef());
            SpatialReference         newReference     = GdalUtilities.getWgs84Reference();
            CoordinateTransformation ct = new CoordinateTransformation(currentReference, newReference);

            double[] northWestPoint = new double[2] {
                geoTransformerData[0], geoTransformerData[3]
            };
            ct.TransformPoint(northWestPoint);

            double[] southEastPoint = new double[2] {
                geoTransformerData[0] + geoTransformerData[1] * width,
                geoTransformerData[3] + geoTransformerData[5] * height
            };
            ct.TransformPoint(southEastPoint);


            return(new List <double[]> {
                northWestPoint, southEastPoint
            });
        }