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

简介: 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')

相关文章
|
6天前
|
Python
Python sorted() 函数和sort()函数对比分析
Python sorted() 函数和sort()函数对比分析
|
8天前
|
数据采集 网络协议 调度
Python爬虫策略分析4
Python爬虫策略分析4
20 1
|
8天前
|
数据采集 前端开发 Python
Python爬虫策略分析3
Python爬虫策略分析3
11 1
|
8天前
|
数据采集 Python
Python爬虫策略分析1
Python爬虫策略分析1
10 1
|
7天前
|
数据可视化 数据处理 Python
Python操作Excel:轻松实现数据处理与分析
Python操作Excel:轻松实现数据处理与分析
11 0
|
8天前
|
数据采集 JSON 前端开发
Python爬虫策略分析2
Python爬虫策略分析2
10 0
|
10天前
|
数据挖掘 Python
用python的tushare模块分析股票案例(python3经典编程案例)
该文章提供了使用Python的tushare模块分析股票数据的案例,展示了如何获取股票数据以及进行基本的数据分析。
12 0
|
1天前
|
机器学习/深度学习 Linux Python
Python编程教学
Python教学
24 13
|
1天前
|
机器学习/深度学习 数据挖掘 开发者
探索Python编程:从基础到实战
【9月更文挑战第34天】在这篇文章中,我们将一起踏上Python编程的旅程。无论你是初学者还是有一定经验的开发者,这篇文章都将为你提供有价值的信息。我们将从Python的基础语法开始,逐步深入到更复杂的主题,如面向对象编程和网络应用开发。我们还将探讨如何在实际项目中应用这些知识,以及如何通过持续学习和实践来提高你的编程技能。让我们一起探索Python的世界,发现它的无限可能!
|
2天前
|
机器学习/深度学习 人工智能 数据可视化
Python比较适合哪些场景的编程?
Python比较适合哪些场景的编程?
14 7
下一篇
无影云桌面