基于 GEE 利用插值方法填补缺失影像

server/2025/2/12 3:52:27/

目录

1 完整代码

2 运行结果



利用GEE合成NDVI时,如果研究区较大,一个月的影像覆盖不了整个研究区,就会有缺失的地方,还有就是去云之后,有云量的地区变成空值。

所以今天来用一种插值的方法来填补缺失的影像,以NDVI为例,主要实现原理其实就是用前后两个月的NDVI的均值进行填补。

1 完整代码

var roi = table;
Map.centerObject(roi,7)
var styling = {color:"red",fillColor:"00000000"};
Map.addLayer(roi.style(styling),{},"geometry")
var img_normalize = function(img){ var minMax = img.reduceRegion({ reducer:ee.Reducer.minMax(), geometry: roi, scale: 30, maxPixels: 10e13, tileScale: 16 }) 
var year = img.get('year') 
var normalize = ee.ImageCollection.fromImages( img.bandNames().map(function(name){ name = ee.String(name); var band = img.select(name); return band.unitScale(ee.Number(minMax.get(name.cat('_min'))), ee.Number(minMax.get(name.cat('_max')))); }) ).toBands().rename(img.bandNames()); return normalize;}
function maskL457sr(image) {//l57去云// Bit 0 - Fill// Bit 1 - Dilated Cloud// Bit 2 - Unused// Bit 3 - Cloud// Bit 4 - Cloud Shadowvar qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);var saturationMask = image.select('QA_RADSAT').eq(0);// Apply the scaling factors to the appropriate bands.var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);var thermalBand = image.select('ST_B6').multiply(0.00341802).add(149.0);// Replace the original bands with the scaled ones and apply the masks.return image.addBands(opticalBands, null, true).addBands(thermalBand, null, true).updateMask(qaMask).updateMask(saturationMask);
}
/*function maskL8sr(image) {// Bit 0 - Fill// Bit 1 - Dilated Cloud// Bit 2 - Cirrus// Bit 3 - Cloud// Bit 4 - Cloud Shadowvar qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);var saturationMask = image.select('QA_RADSAT').eq(0);// Apply the scaling factors to the appropriate bands.var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);// Replace the original bands with the scaled ones and apply the masks.return image.addBands(opticalBands, null, true).addBands(thermalBands, null, true).updateMask(qaMask).updateMask(saturationMask);
}*/
var imageCollection = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2').filterBounds(roi);//1111111
var monthCount = ee.List.sequence(0, 11);// 通过图像收集,生成每月NDVI中值图像
var composites = ee.ImageCollection.fromImages(monthCount.map(function(m) {var startMonth = 1; // 从1月开始var startYear = ee.Number(2000); // 1993-1var month = ee.Date.fromYMD(startYear, startMonth, 1).advance(m,'month').get('month');var year = ee.Date.fromYMD(startYear, startMonth, 1).advance(m,'month').get('year')// 按年筛选,然后按月筛选var filtered = imageCollection.filter(ee.Filter.calendarRange({start: year.subtract(1), // 过去两年的平均数end: year,field: 'year'})).filter(ee.Filter.calendarRange({start: month,field: 'month'}));// mask for clouds and then take the median///var composite = filtered.map(maskL457sr).median().clip(roi);return composite.normalizedDifference(['SR_B4', 'SR_B3']).rename('NDVI').set('month', ee.Date.fromYMD(startYear, startMonth, 1).advance(m,'month')).set('system:time_start', ee.Date.fromYMD(startYear, startMonth, 1).advance(m,'month').millis());
}));
print(composites);
var stackCollection = function(collection) {// 创建一个初始图像.var first = ee.Image(collection.first()).select([]);// Write a function that appends a band to an image.var appendBands = function(image, previous) {return ee.Image(previous).addBands(image);};return ee.Image(collection.iterate(appendBands, first));
};
var compos = stackCollection(composites);
print('插值前', compos);// 用上个月和下个月的平均值替换被遮挡的像素 
var replacedVals = composites.map(function(image){var currentDate = ee.Date(image.get('system:time_start'));var meanImage = composites.filterDate(currentDate.advance(-2,'month'), currentDate.advance(2, 'month')).mean();//33333333333333333333333max min median// 替换所有被屏蔽的值return meanImage.where(image, image);
});// 将ImageCollection堆叠成一个多波段的光栅,以便下载
var stackCollection = function(collection) {// 创建一个初始图像.var first = ee.Image(collection.first()).select([]);// Write a function that appends a band to an image.var appendBands = function(image, previous) {return ee.Image(previous).addBands(image);};return ee.Image(collection.iterate(appendBands, first));
};
var stacked = stackCollection(replacedVals);
print('stacked image', stacked);
var Vis = {min: -1,max: 1.0,palette: ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901','66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01','012E01', '011D01', '011301'],};
Map.addLayer(compos.select(6), Vis, '插值前');
// .0-11  分别代表1-12个月
Map.addLayer(stacked.select(6), Vis, 'NDVI');//555555555Export.image.toDrive({image: stacked.select(0),//选择导出影像的波段0-11  分别代表1-12个月description: 'NDVI',//选择导出云盘的文件夹名称crs: "EPSG:4326",//坐标系scale: 30,//空间分辨率region: roi,//研究区maxPixels: 1e13,//最大像元个数folder: 'NDVI'
});

2 运行结果

填补空值之前的效果
填补空值之后的效果

可以看出,填补的效果还是非常明显的。


http://www.ppmy.cn/server/166939.html

相关文章

Cartesi 生态系统动态 #1 (2025年)

技术 新版 Cartesi Machine 即将发布,带来一些激动人心的新功能。通过最新优化,原生运行变得更简单且速度提升两倍。节点方面,稳定版 V2 已正式推出。在 Espresso 的支持下,它将为即将推出的测试网中的 Drawing Canvas 提供支持。…

深度学习之神经网络框架搭建及模型优化

神经网络框架搭建及模型优化 目录 神经网络框架搭建及模型优化1 数据及配置1.1 配置1.2 数据1.3 函数导入1.4 数据函数1.5 数据打包 2 神经网络框架搭建2.1 框架确认2.2 函数搭建2.3 框架上传 3 模型优化3.1 函数理解3.2 训练模型和测试模型代码 4 最终代码测试4.1 SGD优化算法…

Vue与Konva:解锁Canvas绘图的无限可能

前言 在现代Web开发中,动态、交互式的图形界面已成为提升用户体验的关键要素。Vue.js,作为一款轻量级且高效的前端框架,凭借其响应式数据绑定和组件化开发模式,赢得了众多开发者的青睐。而当Vue.js邂逅Konva.js,两者结…

MybatisPlusCRUD接口使用

1. MybatisPlus的CRUD接口 MybatisPlus提供了很多CRUD接口&#xff0c;可以直接使用这些接口来操作数据库。而不用像Mybatis那样写大量的XML文件及SQL语句。 Mapper CRUD接口 主要关键是继承BaseMapper<T>&#xff0c;其中T是实体类。 使用案例 Mapper层继承BaseMapper接…

AWS Savings Plans 监控与分析工具使用指南

一、背景介绍 1.1 什么是 Savings Plans? AWS Savings Plans 是一种灵活的定价模式,通过承诺持续使用一定金额的 AWS 服务来获得折扣价格。它可以帮助用户降低 AWS 使用成本,适用于 EC2、Fargate 和 Lambda 等服务。 1.2 为什么需要监控? 优化成本支出跟踪使用情况评估投…

Go语言构建微服务:从入门到实战

引言 在云原生时代&#xff0c;微服务架构已成为构建复杂分布式系统的首选方案。Go语言凭借其卓越的并发支持、简洁的语法和高效的运行时&#xff0c;成为微服务开发的利器。本文将深入探讨如何用Go构建健壮的微服务系统&#xff0c;并通过完整案例演示关键实现细节。 一、微…

Qt简单使用正则表达式

正则表达式 用于数据处理&#xff0c;数据查询&#xff0c;数据格式验证&#xff0c;替换文本&#xff0c;提取字串&#xff0c;相比str函数正则技术&#xff0c;开销小 在Qt简单使用正则表达式 在qt中使用类QRegExp类使用正则表达式 需要使用头文件 #include <QRegExp>…

Android Knowledge

1、安卓采用Log工具打印日志&#xff0c;将日志分为5个等级 Log.e:表示错误信息 Log.w:表示警告信息 Log.i:表示一般信息 Log.d:表示调试信息。可把程序运行时的变量值打印出来&#xff0c;方便跟踪调试 Log.v:表示冗余信息 2、pc如何与Android os之间进行连接&#xff1a;通过…