GEE问题:image集合中median和first的区别

目录

问题

函数

median()

Arguments:

Returns: Image

first()

Arguments:

Returns: Image

代码

结果 

解答 

copyProperties(source, properties, exclude)

Arguments:

Returns: Element


问题

我是GEE的新手。我正在试图理解两个图像之间的位移。 我正在尝试以下例子: - 加载图像 - 手动替换(将图像移动40米) - 使用位移函数计算图像移动了多少。 - 如果一切顺利,我应该后退40米 如果我将代码应用于“原始”图像 image 1 = collection.First()一切正常 如果我将代码应用于“中位数”图像 image 1 = collection.median()它不是!

函数

median()

Reduces an image collection by calculating the median of all values at each pixel across the stack of all matching bands. Bands are matched by name.

通过计算所有匹配波段堆栈中每个像素处所有值的中位数来聚合图像集合。乐队按名称匹配。

Arguments:

this:collection (ImageCollection):

The image collection to reduce.

Returns: Image

first()

Returns the first entry from a given collection.

Arguments:

this:imagecollection (ImageCollection):

The ImageCollection instance.

Returns: Image

代码

// area of interest

var geoJSON = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          [
            [
              12.411401665803425,
              41.68238436943494
            ],
            [
              12.411401665803425,
              41.64142345909477
            ],
            [
              12.463637299444343,
              41.64142345909477
            ],
            [
              12.463637299444343,
              41.68238436943494
            ],
            [
              12.411401665803425,
              41.68238436943494
            ]
          ]
        ],
        "type": "Polygon"
      }
    }
  ]
}
var coords = geoJSON['features'][0]['geometry']['coordinates']
var aoi = ee.Geometry.Polygon(coords)

// load original image

var start_date = ee.Date('2022-01-01')
var end_date = ee.Date('2024-07-31')
var image1 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
var image = image1.filter(ee.Filter.bounds(aoi)).select(['B4', 'B3','B2'])

image1 = image1.filter(ee.Filter.date(start_date,end_date)).median() 
print(image1)

image1 = image.filter(ee.Filter.date(start_date,end_date)).first()
print(image1)
// <== if I use first(), then it works!!?
image1 = image1.rename('R', 'G', 'B').clip(aoi)

// create a displacement image, to shift image of 40 m
// this is probably a stupid way of creating such a displacement...

var x = image1.gt(0)
x = x.addBands({srcImg:x.select('R').multiply(40), overwrite:true})
x = x.addBands({srcImg:x.select('G').multiply(0), overwrite:true})

// create a displaced (shifted) image

var image2 = image1.displace(x)
var center = aoi.centroid()
print(center)

//var s2Vis = {
//  min: 0.0,
//  max: 3000,
//  bands: ['R', 'G', 'B'],
//}
//Map.setCenter(12.44,41.66, 9)
//Map.addLayer(image1,s2Vis);
//Map.addLayer(image2,s2Vis);


// compute displacement

var image1RedBand = image1.select('R')
var image2RedBand = image2.select('R')
var displacement = image2RedBand.displacement({
  referenceImage: image1RedBand,
  maxOffset: 50.0,
  patchWidth: 100.0
});

var offset = displacement.select('dx').hypot(displacement.select('dy'))
var theMax = offset.reduceRegion({reducer:ee.Reducer.max(), geometry:aoi, scale:10, bestEffort:true})
var theMin = offset.reduceRegion({reducer:ee.Reducer.min(), geometry:aoi, scale:10, bestEffort:true})
print('max displacement =',theMax.values())
print('min displacement =',theMin.values())

结果 

解答 

这里我们需要进行明白的就是,first函数在默认状态下进行了影像属性的copy但是我们这里如果用median的话就不没有办法自动copy,如果我们想要实现上面的功能,就需要用下面的函数:

copyProperties(sourcepropertiesexclude)

Copies metadata properties from one element to another.

Arguments:

this:destination (Element, default: null):

The object whose properties to override.

source (Element, default: null):

The object from which to copy the properties.

properties (List, default: null):

The properties to copy. If omitted, all ordinary (i.e. non-system) properties are copied.

exclude (List, default: null):

The list of properties to exclude when copying all properties. Must not be specified if properties is.

Returns: Element

至于需要什么属性,我们要根据自己的情况去分析,利用这个函数来实现属性的分析。这样后续就可以进行相关的操作。

  • 16
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
项目:使用AngularJs编写的简单 益智游戏(附源代码)  这是一个简单的 javascript 项目。这是一个拼图游戏,也包含一个填字游戏。这个游戏玩起来很棒。有两个不同的版本可以玩这个游戏。你也可以玩填字游戏。 关于游戏 这款游戏的玩法很简单。如上所述,它包含拼图和填字游戏。您可以通过移动图像来玩滑动拼图。您还可以选择要在滑动面板拥有的列数和网格数。 另一个是填字游戏。在这里你只需要找到浏览器左侧提到的那些单词。 要运行此游戏,您需要在系统上安装浏览器。下载并在代码编辑器打开此项目。然后有一个 index.html 文件可供您修改。在命令提示符运行该文件,或者您可以直接运行索引文件。使用 Google Chrome 或 FireFox 可获得更好的用户体验。此外,这是一款多人游戏,双方玩家都是人类。 这个游戏包含很多 JavaScript 验证。这个游戏很有趣,如果你能用一点 CSS 修改它,那就更好了。 总的来说,这个项目使用了很多 javascript 和 javascript 库。如果你可以添加一些具有不同颜色选项的级别,那么你一定可以利用其库来提高你的 javascript 技能。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

此星光明

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

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

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

打赏作者

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

抵扣说明:

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

余额充值