Google Earth Engine(GEE)——单景S2(sentinel2)影像去云分析
很多时候我们多是对影像集合进行去云分析,所以当我们面对单景影像应该如何进行去云分析,这里我们分别对三种sentinel2影像进行去云分析,因为影像分辨率高的缘故,所以这里并不展示去云后的影像,而是通过导出到assets中,然后再进行加载是最好的结果:
这里函数:
ee.Algorithms.Sentinel2.CDI(source)
从Sentinel-2级1C图像计算云位移索引(CDI)。 CDI是由于传感器视差引起的高架物体中光学分离的度量。 返回一个名为“ CDI”的浮点乐队。
Computes the Cloud Displacement Index (CDI) from a Sentinel-2 Level 1C image. CDI is a measure of the optical separation in elevated objects due to sensor parallax. Returns a floating point band named "cdi".
See Frantz, D., Hass, E., Uhl, A., Stoffels, J., & Hill, J. (2018). Improvement of the Fmask algorithm for Sentinel-2 images: Separating clouds from bright surfaces based on parallax effects. Remote sensing of environment, 215, 471-481.
Arguments:
source (Image):
The source image.
Returns: Image
directionalDistanceTransform(angle, maxDistance, labelBand)
对于源中的每个零价值像素,在给定方向上获取到与最接近的非零像素的距离。
返回一个称为“距离”的浮点距离。
For each zero-valued pixel in the source, get the distance to the nearest non-zero pixels in the given direction.
Returns a band of floating point distances called "distance".
Arguments:
this:source (Image):
The source image.
angle (Float):
The angle, in degrees, at which to search for non-zero pixels.
maxDistance (Integer):
The maximum distance, in pixels, over which to search.
labelBand (String, default: null):
If provided, multi-band inputs are permitted and only this band is used for searching. All other bands are returned and populated with the per-band values found at the searched non-zero pixels in the label band.
Returns: Image
focalMin(radius, kernelType, units, iterations, kernel)
Applies a morphological reducer() filter to each band of an image using a named or custom kernel.
Arguments:
this:image (Image):
The image to which to apply the operations.
radius (Float, default: 1.5):
The radius of the kernel to use.
kernelType (String, default: "circle"):
The type of kernel to use. Options include: 'circle', 'square', 'cross', 'plus', octagon' and 'diamond'.
units (String, default: "pixels"):
If a kernel is not specified, this determines whether the kernel is in meters or pixels.
iterations (Integer, default: 1):
The number of times to apply the given kernel.
kernel (Kernel, default: null):
A custom kernel. If used, kernelType and radius are ignored.
Returns: Image
代码:
//脚本显示如何使用S2无云算法来掩盖云
//此脚本显示如何在单个图像上运行此脚本并导出结果
//如果您想在集合上运行此内容,请参阅完整的示例
// https://code.earthengine.google.com/?scriptPath=Examples%3ACloud%20Masking%2FSentinel2%20Cloud%20And%20Shadow
var imageId = '20190703T050701_20190703T052312_T43PGP';
// S2 Cloudless Algorithm
// This algorithm requires different bands from 3 different datasets
var s2Bands = ee.Image('COPERNICUS/S2/'+ imageId)
.select(['B7', 'B8', 'B8A', 'B10']);
var s2SrBands = ee.Image('COPERNICUS/S2_SR/' + imageId)
.select(['B2', 'B3', 'B4', 'B5']);
var s2CloudBands = ee.Image('COPERNICUS/S2_CLOUD_PROBABILITY/'+ imageId)
.select(['probability'])
var image = s2Bands.addBands(s2SrBands).addBands(s2CloudBands)
var rgbVis = {min: 0.0, max: 3000, bands: ['B4', 'B3', 'B2']};
Map.centerObject(image)
Map.addLayer(image, rgbVis, 'SR Image', false);
// 脚本末尾定义的S2cloudless功能
var imageCloudless = ee.Image(s2Cloudless(image));
//S2无云算法的reproject()调用需要
//分辨率为10m的计算,因此无法交互观看结果
//代替结果。
Export.image.toAsset({
image: imageCloudless,
description: 'Cloud_Probability_Masked_Image_Asset',
assetId: 'users/ujavalgandhi/e2e/s2_cloudless_masked_image',
region: image.geometry(),
scale: 10});
//一旦导出完成,您就可以导入资产。
//导入和显示
var maskedImage = ee.Image('users/ujavalgandhi/e2e/s2_cloudless_masked_image');
Map.addLayer(maskedImage, rgbVis, 'Masked Image');
// s2Cloudless function
function s2Cloudless(image) {
//从L1C频段计算云位移索引。
var cdi = ee.Algorithms.Sentinel2.CDI(image);
var s2c = image.select('probability');
var cirrus = image.select('B10').multiply(0.0001);
//假设低到中间的大气云是概率的像素
//大于65%,CDI小于-0.5。 对于更高的气氛
// cirrus云,假设卷心带大于0.01。
//最终的云蒙版是其中一个或两个条件。
var isCloud = s2c.gt(65).and(cdi.lt(-0.5)).or(cirrus.gt(0.01));
//重新投影以20m的比例进行空间操作。
// 20m比例是为了速度,并假设云不需要10m精度。
isCloud = isCloud.focal_min(3).focal_max(16);
isCloud = isCloud.reproject({crs: cdi.projection(), scale: 20});
//我们在最后一步中发现的云的项目阴影。 这是假设我们正在UTM投影中工作。
var shadowAzimuth = ee.Number(90)
.subtract(ee.Number(image.get('MEAN_SOLAR_AZIMUTH_ANGLE')));
//随着以下重新投影,阴影预计为5公里。
isCloud = isCloud.directionalDistanceTransform(shadowAzimuth, 50);
isCloud = isCloud.reproject({crs: cdi.projection(), scale: 100});
isCloud = isCloud.select('distance').mask();
return image.select('B2', 'B3', 'B4').updateMask(isCloud.not());
}

更多推荐
所有评论(0)