GEE代码学习 day6

6、Classification

6.1 监督分类

分类步骤:1. Get a scene.

                  2. Collect training data.

                 3. Select and train a classifier using the training data.

                 4. Classify the image using the selected classifie(分类器).

.filterBounds() 是 Earth Engine 中用于过滤图像或特征集合的方法之一。它允许你根据空间范围来筛选数据,保留落在指定区域内的图像或特征。

// Create an Earth Engine Point object over Milan. 
var pt = ee.Geometry.Point([9.453, 45.424]);  
// Filter the Landsat 8 collection and select the least cloudy image. 
var landsat = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')  
                .filterBounds(pt) 
                .filterDate('2019-01-01', '2020-01-01') 
                .sort('CLOUD_COVER') 
                .first();  
// Center the map on that image. 
Map.centerObject(landsat, 8);  
// Add Landsat image to the map. 
var visParams = {  
                   bands: ['SR_B4', 'SR_B3', 'SR_B2'], 
                   min: 7000, 
                   max: 12000 }; 
Map.addLayer(landsat, visParams, 'Landsat 8 image');

在整个数字世界中,使用十六进制值来表示计算机和操作系统中的特定颜色。它们由六个值指定,这些值排列成三对,每对值分别用于红色、绿色和蓝色亮度值。如果您不熟悉十六进制值,请想象一下颜色是以 10 为基数对而不是以 16 为基数对指定的。在这种情况下,亮红色的纯红色值将为 “990000”;亮绿色值为 “009900”;亮蓝色值为 “000099”。像 “501263” 这样的值是三种颜色的混合,不是特别亮,蓝色和红色的数量大致相等,绿色的数量要少得多

下一步是将所有训练特征集合合并为一个。复制并粘贴下面的代码,将它们合并到一个名为 trainingFeatures 的 FeatureCollection 中。在这里,我们使用 flatten 方法来避免拥有特征集合 - 我们希望在 FeatureCollection 中拥有单个特征。

// Combine training feature collections. 
var trainingFeatures = ee.FeatureCollection([  
                      forest, developed, water, herbaceous ]).flatten();

下面的代码以提取每个点位置每个类的波段信息。首先,我们定义预测波段,以从每个类别的不同波段中提取不同的光谱和热信息。然后,我们使用 sampleRegions 方法从每个点位置的 Landsat 图像中采样信息。此方法需要有关 FeatureCollection (我们的参考点)、要提取的属性 (“class”) 和像素比例 (以米为单位) 的信息。

// Define prediction bands. 
var predictionBands = [  'SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7','ST_B10'  ];  
// Sample training points. 
var classifierTraining = landsat.select(predictionBands)  
                                .sampleRegions({ collection: trainingFeatures,
                                                 properties: ['class'], 
                                                 scale: 30 });

现在我们可以选择一个分类器。分类器的选择并不总是显而易见的,并且有许多选项可供选择 - 您可以快速扩展 ee.Classifier 对象来了解我们有多少个图像分类选项。因此,我们将测试不同的分类器并比较它们的结果。我们将从分类与回归树 (CART) 分类器开始,这是一种已经存在了几十年的著名分类算法 。

 CART Classifier ///  
// Train a CART Classifier. 
var classifier = ee.Classifier.smileCart().train({  features: classifierTraining, classProperty: 'class', inputProperties: predictionBands });

对 Landsat 图像进行分类并将其添加到 Map。

// Classify the Landsat image. 
var classified =  landsat.select(predictionBands).classify(classifier);  
// Define classification image visualization parameters. 
var classificationVis = {  
                         min: 0, 
                         max: 3, 
                         palette: ['589400', 'ff0000', '1a11ff', 'd0741e'] };  
// Add the classified image to the map. 
Map.addLayer(classified, classificationVis, 'CART classified');

最后图并不理想,可以从一下进行改进:

• Collect more training data

• Tune the mode

• Expand the collection location

• Add more predictors: We can try adding spectral indices to the input variables; this way, we are feeding the classifier new, unique information about each class. For example, there is a good chance that a vegetation index specialized for detecting vegetation health (e.g., NDVI) would improve the developed versus herbaceous classification.

现在,我们将尝试另一个广泛使用的监督学习分类器:随机森林 (RF)。

请注意,在 ee.Classifier.smileRandomForest 文档(文档选项卡)中,有一个种子(随机数)参数。设置种子允许您在每次运行模型时精确复制模型。任何数字都可以作为种子。

/// Random Forest Classifier /  
// Train RF classifier. 
var RFclassifier =  ee.Classifier.smileRandomForest(50).train({ features: classifierTraining, classProperty: 'class', inputProperties: predictionBands });  
// Classify Landsat image. 
var RFclassified =  landsat.select(predictionBands).classify( RFclassifier);  
// Add classified image to the map. 
Map.addLayer(RFclassified, classificationVis, 'RF classified');

gee代码是指Google Earth Engine的编程语言,用于在Google Earth Engine平台上进行遥感影像合成。影像合成是指将多个遥感影像融合或组合起来,以生成新的影像产品或提取特定的信息。 三年影像合成是指基于三年时间范围内的遥感影像数据,利用gee代码进行合成处理。在合成过程中,可以使用一系列的遥感处理算法和技术,例如表面反射率校正、背景去除、云和阴影去除、归一化差异植被指数计算等,以提高合成影像的质量和可用性。 其中,gee代码的应用可以通过以下步骤来实现三年影像合成。首先,需要从Google Earth Engine平台的遥感影像数据库中获取三年内的多个影像数据。其次,通过gee代码进行数据预处理,包括校正、去噪、修补等操作,以提高影像的质量和一致性。然后,根据需要的合成目标,选择适当的合成算法和处理方法,如被动微波支持向量机算法、线性混合模型、多光谱融合算法等,对影像数据进行融合处理。最后,对合成结果进行评估和后处理,如边缘增强、色调调整、尺度转换等,以获得最终的三年影像合成产品。 通过gee代码实现三年影像合成可以广泛应用于各个领域,例如土地利用/覆盖分类、环境监测、资源管理等。这种方法可以提供更全面、一致性较好的遥感影像数据,为研究者和决策者提供更准确、全面的信息。同时,利用gee代码进行影像合成也能够实现对大规模遥感影像数据的快速处理和分析,提高工作效率和效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值