画像近傍の統計情報

減算を行うリージョンを指定する代わりに、減算を適用する近傍を指定することもできます。画像の近傍を減らすには、image.reduceNeighborhood() を使用します。この場合、入力画像上のスライディング ウィンドウで縮小が行われ、ウィンドウのサイズと形状は ee.Kernel で指定されます。reduceNeighborhood() の出力は別の画像で、各ピクセル値は入力画像のそのピクセル周辺の近傍での減算の出力を表します。図 1 に、このタイプの削減を示します。

reduceNeighborhood 図
図 1. reduceNeighborhood() のイラスト。カーネルでレジューサーが適用されています。

たとえば、National Agriculture Imagery Program(NAIP)の画像を使用して、カリフォルニア州のレッドウッド フォレストでの伐採による景観の違いを定量化できます。具体的には、近傍の標準偏差(SD)を使用して、記録された領域(図 2 の画像の SW)と保護された領域(図 2 の画像の NE)のテクスチャの違いを表します。たとえば、NAIP 正規化植生指標(NDVI)画像のテクスチャを取得するには、reduceNeighborhood() を使用して、カーネルで定義された近傍の SD を計算します。

コードエディタ(JavaScript)

// Define a region in the redwood forest.
var redwoods = ee.Geometry.Rectangle(-124.0665, 41.0739, -123.934, 41.2029);

// Load input NAIP imagery and build a mosaic.
var naipCollection = ee.ImageCollection('USDA/NAIP/DOQQ')
  .filterBounds(redwoods)
  .filterDate('2012-01-01', '2012-12-31');
var naip = naipCollection.mosaic();

// Compute NDVI from the NAIP imagery.
var naipNDVI = naip.normalizedDifference(['N', 'R']);

// Compute standard deviation (SD) as texture of the NDVI.
var texture = naipNDVI.reduceNeighborhood({
  reducer: ee.Reducer.stdDev(),
  kernel: ee.Kernel.circle(7),
});

// Display the results.
Map.centerObject(redwoods, 12);
Map.addLayer(naip, {}, 'NAIP input imagery');
Map.addLayer(naipNDVI, {min: -1, max: 1, palette: ['FF0000', '00FF00']}, 'NDVI');
Map.addLayer(texture, {min: 0, max: 0.3}, 'SD of NDVI');

Python の設定

Python API とインタラクティブな開発で geemap を使用する方法については、 Python 環境のページをご覧ください。

import ee
import geemap.core as geemap

Colab(Python)

# Define a region in the redwood forest.
redwoods = ee.Geometry.Rectangle(-124.0665, 41.0739, -123.934, 41.2029)

# Load input NAIP imagery and build a mosaic.
naip_collection = (
    ee.ImageCollection('USDA/NAIP/DOQQ')
    .filterBounds(redwoods)
    .filterDate('2012-01-01', '2012-12-31')
)
naip = naip_collection.mosaic()

# Compute NDVI from the NAIP imagery.
naip_ndvi = naip.normalizedDifference(['N', 'R'])

# Compute standard deviation (SD) as texture of the NDVI.
texture = naip_ndvi.reduceNeighborhood(
    reducer=ee.Reducer.stdDev(), kernel=ee.Kernel.circle(7)
)

# Display the results.
m = geemap.Map()
m.center_object(redwoods, 12)
m.add_layer(naip, {}, 'NAIP input imagery')
m.add_layer(
    naip_ndvi, {'min': -1, 'max': 1, 'palette': ['FF0000', '00FF00']}, 'NDVI'
)
m.add_layer(texture, {'min': 0, 'max': 0.3}, 'SD of NDVI')
m

カーネル値がゼロ以外のピクセルは計算に含まれます。デフォルトではカーネル重みが使用されますが、inputWeight 引数を使用してこの動作を変更できます。図 2 に、入力画像と reduceNeighborhood() 出力を比較しています。

reduceNeighborhood 入力
図 2a. 北カリフォルニアの海岸の NAIP 画像。
reduceNeighborhood の出力
図 2b. 標準偏差レジューサーを使用した reduceNeighborhood() 出力。