1 获取无云影像
选取某段时期内云量最小的影像,同时也根据兴趣点(区)来筛选影像。
var image = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(roi)
.filterDate('2019-01-01', '2019-12-31')
.sort('CLOUD_COVER')
.first());
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'],min:0, max: 3000}, 'True colour image');
调节亮度 Gamma从1到1.4 增加影像亮度
影像过暗调节
2 收集训练数据
对每种地物类型收集具有代表性的样本,来训练分类器
样本筛选的结果:
主要分为:urban, water, forest, agriculture 把这些点合并到一个集合(FeatureCollection)
var classNames = urban.merge(water).merge(forest).merge(agriculture).merge(cloud);
print(classNames)
3 创建训练数据
使用之前的样本点来提取遥感影像不同波段再这些点处的反射率值,并添加到训练样本FeatureCollection中,每个点都新增对应的波段属性。
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
var training = image.select(bands).sampleRegions({
collection: classNames,
properties: ['landcover'],
scale: 30
});
print(training);
4 训练分类器并进行分类
使用训练样本的光谱特征来训练分类器
var classifier = ee.Classifier.cart().train({
features: training,
classProperty: 'landcover',
inputProperties: bands
});
对影像进行分类
//Run the classification
var classified = image.select(bands).classify(classifier);
结果制图展示
//Display classification
Map.centerObject(classNames, 11);
Map.addLayer(classified,
{min: 0, max: 3, palette: ['red', 'blue', 'green','yellow']},
'classification');
所有代码(注意兴趣区和样本点需要自己点选生成导入):
var image = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(roi)
.filterDate('2019-01-01', '2019-12-31')
.sort('CLOUD_COVER')
.first());
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'],min:0, max: 3000}, 'True colour image');
var classNames = urban.merge(water).merge(forest).merge(agriculture);
print(classNames)
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
var training = image.select(bands).sampleRegions({
collection: classNames,
properties: ['landcover'],
scale: 30
});
print(training);
var classifier = ee.Classifier.cart().train({
features: training,
classProperty: 'landcover',
inputProperties: bands
});
//Run the classification
var classified = image.select(bands).classify(classifier);
//Display classification
Map.centerObject(classNames, 11);
Map.addLayer(classified,
{min: 0, max: 3, palette: ['red', 'blue', 'green','yellow']},
'classification');
【参考】
https://zhuanlan.zhihu.com/p/148616852 (附有参考)
点滴分享,福泽你我!Add oil!
转载本文请联系原作者获取授权,同时请注明本文来自张伟科学网博客。
链接地址:https://wap.sciencenet.cn/blog-3428464-1241431.html?mobile=1
收藏