勾配

image.gradient() を使用して、画像の各バンドの勾配を計算できます。たとえば、次のコードは Landsat 8 パンクロマティック バンドの勾配の振幅と方向を計算します。

コードエディタ(JavaScript)

// Load a Landsat 8 image and select the panchromatic band.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318').select('B8');

// Compute the image gradient in the X and Y directions.
var xyGrad = image.gradient();

// Compute the magnitude of the gradient.
var gradient = xyGrad.select('x').pow(2)
          .add(xyGrad.select('y').pow(2)).sqrt();

// Compute the direction of the gradient.
var direction = xyGrad.select('y').atan2(xyGrad.select('x'));

// Display the results.
Map.setCenter(-122.054, 37.7295, 10);
Map.addLayer(direction, {min: -2, max: 2, format: 'png'}, 'direction');
Map.addLayer(gradient, {min: -7, max: 7, format: 'png'}, 'gradient');

gradient() は、X 方向のグラデーションと Y 方向のグラデーションの 2 つのバンドを出力します。例に示すように、2 つの方向を組み合わせて、勾配の振幅と方向を取得できます。マグニチュードは図 1 のようになります。

gradient_sf
図 1. 米国カリフォルニア州サンフランシスコ ベイエリア上空の Landsat 8 画像のパノラマ グラデーションの振幅。