gee python:利用核函数对影像进行平滑处理和边缘提取分析

安装地球引擎API和geemap
安装地球引擎的Python API和geemap。geemap Python包是建立在ipyleaflet和folium包之上的,它实现了几个与地球引擎数据层交互的方法,比如Map.addLayer()、Map.setCenter()和Map.centerObject()。下面的脚本检查geemap包是否已经安装。如果没有,它将安装geemap,它会自动安装其依赖项,包括earthengine-api、folium和ipyleaflet。

# Installs geemap package
import subprocess

try:
    import geemap
except ImportError:
    print('Installing geemap ...')
    subprocess.check_call(["python", '-m', 'pip', 'install', 'geemap'])
import ee
import geemap

使用的函数:
**ee.Kernel.square(*args, kwargs)
Generates a square-shaped boolean kernel.这里使用这个核函数创建一个布尔类型的内核。
参数类型的设定中我们可以使用半径和单位进行设定。
Args:
radius: The radius of the kernel to generate.
units: The system of measurement for the kernel (‘pixels’ or
‘meters’). If the kernel is specified in meters, it will
resize when the zoom-level is changed.
normalize: Normalize the kernel values to sum to 1.
magnitude: Scale each value by this amount.

**image.convolve(*args, kwargs)
Convolves each band of an image with the given kernel.
将每一个指定的影像波段转化为给定的核函数,通过与 Boxcar 内核卷积来平滑图像。

Args:
image: The image to convolve.
kernel: The kernel to convolve with.

**ee.Kernel.laplacian8(*args, kwargs)
Generates a 3x3 Laplacian-8 edge-detection kernel.

Args:
magnitude: Scale each value by this amount.
normalize: Normalize the kernel values to sum to 1

生成 3x3 Laplacian-8 边缘检测内核。
参数:
大小:按此量缩放每个值。
标准化:将核值标准化为总和为 1

# Add Earth Engine dataset
# Load and display an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
Map.setCenter(-121.9785, 37.8694, 11)
Map.addLayer(image, {'bands': ['B5', 'B4', 'B3'], 'max': 0.5}, 'input image')

# Define a boxcar or low-pass kernel.
# boxcar = ee.Kernel.square({
#   'radius': 7, 'units': 'pixels', 'normalize': True
# })

boxcar = ee.Kernel.square(7, 'pixels', True)

# Smooth the image by convolving with the boxcar kernel.
smooth = image.convolve(boxcar)
Map.addLayer(smooth, {'bands': ['B5', 'B4', 'B3'], 'max': 0.5}, 'smoothed')

# Define a Laplacian, or edge-detection kernel.
laplacian = ee.Kernel.laplacian8(1, False)

# Apply the edge-detection kernel.
edgy = image.convolve(laplacian)
Map.addLayer(edgy,
             {'bands': ['B5', 'B4', 'B3'], 'max': 0.5},
             'edges')

影像平滑

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

此星光明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值