그래디언트

image.gradient()를 사용하여 이미지의 각 밴드의 그라데이션을 계산할 수 있습니다. 예를 들어 다음 코드는 Landsat 8 panchromatic 밴드의 기울기 크기와 방향을 계산합니다.

코드 편집기 (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 방향의 그라데이션이라는 두 개의 밴드를 출력합니다. 예에서 볼 수 있듯이 두 방향을 결합하여 기울기 크기와 방향을 얻을 수 있습니다. 크기는 그림 1과 같이 표시됩니다.

gradient_sf
그림 1. 미국 캘리포니아 샌프란시스코만 지역의 Landsat 8 이미지에 대한 전천후 그라데이션 크기입니다.