前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >gee python:利用核函数对影像进行平滑处理和边缘提取分析

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

作者头像
此星光明
发布2024-02-02 10:20:05
1170
发布2024-02-02 10:20:05
举报

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

代码语言:javascript
复制
# Installs geemap package
import subprocess

try:
    import geemap
except ImportError:
    print('Installing geemap ...')
    subprocess.check_call(["python", '-m', 'pip', 'install', 'geemap'])
代码语言:javascript
复制
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

代码语言:javascript
复制
# 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')
影像平滑
影像平滑
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-02-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档