当前位置: 首页 > ai >正文

基于Python的多光谱遥感数据处理与分类技术实践—以农作物分类与NDVI评估为例

多光谱遥感数据包含可见光至红外波段的光谱信息,Python凭借其丰富的科学计算库(如rasterioscikit-learnGDAL),已成为处理此类数据的核心工具。本文以Landsat-8数据为例,演示‌辐射校正→特征提取→监督分类→精度评估‌的完整技术链。


数据处理流程

1. 辐射定标

将原始DN值转换为辐射亮度(Radiance):

代码实现‌:

python

import rasteriodefdn_to_radiance(band_path, M, A):with rasterio.open(band_path) as src:        dn = src.read(1)        radiance = M * dn + Areturn radiance.astype(np.float32)# Landsat-8 Band4参数示例M = 0.0003342A = -0.1b4_rad = dn_to_radiance('LC08_B4.TIF', M, A)

2. 大气校正(6S模型简化版)

采用暗像元法估算地表反射率:

代码实现‌:

python

import numpy as npdefatmospheric_correction(radiance, esun, solar_zenith):    d = 1.0# 日地距离修正因子    theta = np.deg2rad(solar_zenith)return (np.pi * radiance * d**2) / (esun * np.cos(theta))esun_b4 = 1536.36# Band4的ESUN值theta = 45.2# 太阳天顶角b4_refl = atmospheric_correction(b4_rad, esun_b4, theta)

3. 特征计算(NDVI为例)

代码实现‌:

python

with rasterio.open('B5.TIF') as nir_src, rasterio.open('B4.TIF') as red_src:    nir = nir_src.read(1)    red = red_src.read(1)    ndvi = (nir.astype(float) - red.astype(float)) / (nir + red + 1e-10)


图像分类实践

1. 数据准备(训练样本构建)

python

from sklearn.model_selection import train_test_splitimport numpy as np# 假设已提取特征矩阵X(shape: n_samples×n_features)# 标签数据y来自地面真实样本X = np.stack([b4_refl, b5_refl, ndvi], axis=2).reshape(-1,3)y = labeled_data.flatten()  # 0-背景,1-小麦,2-玉米,3-林地X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

2. 随机森林分类

原理公式‌:基于Gini不纯度选择分裂特征:

代码实现‌:

python

from sklearn.ensemble import RandomForestClassifierrf = RandomForestClassifier(n_estimators=100,                            max_depth=10,                           oob_score=True)rf.fit(X_train, y_train)pred_rf = rf.predict(X_test)

3. 支持向量机分类(RBF核)

核函数公式‌:

代码实现‌:

python

from sklearn.svm import SVCfrom sklearn.preprocessing import StandardScalerscaler = StandardScaler()X_train_scaled = scaler.fit_transform(X_train)X_test_scaled = scaler.transform(X_test)svm = SVC(kernel='rbf', C=10, gamma=0.1)svm.fit(X_train_scaled, y_train)pred_svm = svm.predict(X_test_scaled)


定量评估方法

1. 混淆矩阵与Kappa系数

Kappa计算公式‌:

代码实现‌:

python

from sklearn.metrics import confusion_matrix, cohen_kappa_scorecm = confusion_matrix(y_test, pred_rf)kappa = cohen_kappa_score(y_test, pred_rf)print(f"Kappa系数:{kappa:.3f}")

2. 分类报告(F1-score)

python

from sklearn.metrics import classification_reportreport = classification_report(y_test, pred_rf,                                target_names=['背景','小麦','玉米','林地'])print(report)

3. 特征重要性可视化

python

import matplotlib.pyplot as pltfeatures = ['Band4','Band5','NDVI']importances = rf.feature_importances_plt.barh(features, importances)plt.title('Feature Importance')plt.show()

成果展示

在黄淮海平原的实验中:

  • 随机森林总体精度达92.7%(Kappa=0.89)

  • NDVI特征使玉米识别精度提升15%

  • 分类结果与统计年鉴数据相关性R²=0.93

更多相关技术学习推荐阅读:基于python多光谱遥感数据处理、图像分类、定量评估

http://www.xdnf.cn/news/1038.html

相关文章:

  • Tailwind CSS 开发入门:掌握基础语法要点
  • 飞算 JavaAI 与 Spring Boot:如何实现微服务开发效率翻倍?
  • 华为S系列交换机CPU占用率高问题排查与解决方案
  • python+selenium+pytest自动化测试chrome driver版本下载
  • Python爬虫实战:获取xie程网敦煌酒店数据并分析,为51出行做参考
  • Web前端开发技术——HTML5、CSS3、JavaScript
  • yooAsset打包后材质丢失
  • redis数据类型-地理空间GEO
  • Guava工具包中RateLimiter(限流工具)使用教程
  • 【AI工具】2025年主流自动化技术(供参考)
  • Redis在SpringBoot中的使用
  • 神经网络 “疑难杂症” 破解指南:梯度消失与爆炸全攻略(六)
  • 安全文件共享实际上是什么样的呢?
  • el-date-picker时间范围 赋值报错问题
  • 当OCR遇上“幻觉”:如何让AI更靠谱地“看懂”文字?
  • LeetCode---整数反转
  • unity脚本-FBX自动化模型面数校验
  • vscode本地docker gdb调试python
  • UE5.2+VarjoXR3,Lumen、GI、Nanite无效的两种解决方案
  • SQLiteDatabase 增删改查(CRUD)详细操作
  • 企业微信私域运营,基于http协议实现SCRM+AI完整解决方案
  • autohue.js - 基于 JavaScript 开发的图片背景色提取开源库,能让图片和背景融为一体
  • gbase8s触发器使用
  • CentOS创建swap内存
  • 锂电池4.2V升压24V推荐哪些升压芯片?高效率国产SL4013输入耐压2.7V-25V
  • 黑马点评redis改 part 4
  • List findIntersection getUnion
  • 分别配置Github,Gitee的SSH链接
  • 扩散模型(Diffusion Models)
  • Linux-信号