GEE使用哨兵2号影像无监督分类(待补充)

发布时间:2024年01月12日

在这里插入图片描述

var classes = 5;
var scale = 10;
var numpixels = 5000;
var start = '2020-11-01'
var end = '2021-03-31'
var roi = ee.FeatureCollection('projects/a-flyllf0313/assets/dachang');

function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}


// select images
var s2 = ee.ImageCollection('COPERNICUS/S2_SR');

var img = ee.Image(s2.filterBounds(roi)
                       .filterDate(start, end)
                       .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
                       .map(maskS2clouds)
                       .mean()
                       .clip(roi));

var image = img.select('B2');
var image = image.addBands([img.select('B3'), img.select('B4'), img.select('B5'),
                            img.select('B6'), img.select('B7'), img.select('B8'),
                            img.select('B9')
                            ]);                          
                            
// sampling
var training = image.sample({
  region: roi,
  scale: scale,
  numPixels: numpixels
});



// select method
var clusterer = ee.Clusterer.wekaKMeans(classes).train(training);

var result = image.cluster(clusterer);



Map.centerObject(roi, 11);
Map.addLayer(image.clip(roi), {bands: ["B4", "B3", "B2"], min:0, max:0.25}, "raw_img");
Map.addLayer(result.randomVisualizer(), {}, 'clusters')

参考博文

【Earth Engine】基于GEE进行非监督学习

文章来源:https://blog.csdn.net/qq_43920838/article/details/135561848
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。