가중된 감소

기본적으로 이미지에 적용된 리듀서는 마스크 값에 따라 입력에 가중치를 부여합니다. 이는 clip()와 같은 작업을 통해 생성된 부분 픽셀의 컨텍스트에서 관련이 있습니다. 리듀서에서 unweighted()를 호출하여 이 동작을 조정합니다. 가중치가 적용되지 않은 리듀서를 사용하면 영역의 모든 픽셀에 동일한 가중치가 적용됩니다. 다음 예에서는 픽셀 가중치가 리듀서 출력에 미치는 영향을 보여줍니다.

가중치 감소의 경우 픽셀 교차 가중치는 내부적으로 8비트 정수 (0~255)로 표시됩니다. 이는 부분 픽셀 범위를 256개의 개별 수준으로 양자화합니다. 따라서 대략 1/256 (~0.4%) 미만의 커버리지 비율은 가중치 0 (유효하지 않음)으로 반올림됩니다. 리전의 픽셀에 가중치가 부여되는 방식에 관한 자세한 내용은 리전 축소 가이드를 참고하세요.

코드 편집기(JavaScript)

// Load a Landsat 8 input image.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318');

// Create an arbitrary region.
var geometry = ee.Geometry.Rectangle(-122.496, 37.532, -121.554, 37.538);

// Make an NDWI image.  It will have one band named 'nd'.
var ndwi = image.normalizedDifference(['B3', 'B5']);

// Compute the weighted mean of the NDWI image clipped to the region.
var weighted = ndwi.clip(geometry)
  .reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: geometry,
    scale: 30})
  .get('nd');

// Compute the UN-weighted mean of the NDWI image clipped to the region.
var unweighted = ndwi.clip(geometry)
  .reduceRegion({
    reducer: ee.Reducer.mean().unweighted(),
    geometry: geometry,
    scale: 30})
  .get('nd');

// Observe the difference between weighted and unweighted reductions.
print('weighted:', weighted);
print('unweighted', unweighted);

Python 설정

Python API 및 geemap를 사용한 대화형 개발에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

import ee
import geemap.core as geemap

Colab(Python)

# Load a Landsat 8 input image.
image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')

# Create an arbitrary region.
geometry = ee.Geometry.Rectangle(-122.496, 37.532, -121.554, 37.538)

# Make an NDWI image.  It will have one band named 'nd'.
ndwi = image.normalizedDifference(['B3', 'B5'])

# Compute the weighted mean of the NDWI image clipped to the region.
weighted = (
    ndwi.clip(geometry)
    .reduceRegion(reducer=ee.Reducer.mean(), geometry=geometry, scale=30)
    .get('nd')
)

# Compute the UN-weighted mean of the NDWI image clipped to the region.
unweighted = (
    ndwi.clip(geometry)
    .reduceRegion(
        reducer=ee.Reducer.mean().unweighted(), geometry=geometry, scale=30
    )
    .get('nd')
)

# Observe the difference between weighted and unweighted reductions.
display('weighted:', weighted)
display('unweighted', unweighted)

결과의 차이는 리듀서에서 unweighted()를 호출한 결과 영역의 가장자리에 있는 픽셀이 가중치 1을 받기 때문입니다.

명시적으로 가중치가 부여된 출력을 얻으려면 리듀서에서 호출된 splitWeights()를 사용하여 가중치를 명시적으로 설정하는 것이 좋습니다. splitWeights()에 의해 수정된 리듀서는 두 개의 입력을 사용하며, 두 번째 입력은 가중치입니다. 다음 예에서는 클라우드 점수 (클라우드가 많을수록 가중치가 낮음)로 가중치를 부여하여 지역의 가중 평균 정규 식생 지수 (NDVI)를 계산하여 splitWeights()를 보여줍니다.

코드 편집기(JavaScript)

// Load an input Landsat 8 image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_186059_20130419');

// Compute cloud score and reverse it such that the highest
// weight (100) is for the least cloudy pixels.
var cloudWeight = ee.Image(100).subtract(
  ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']));

// Compute NDVI and add the cloud weight band.
var ndvi = image.normalizedDifference(['B5', 'B4']).addBands(cloudWeight);

// Define an arbitrary region in a cloudy area.
var region = ee.Geometry.Rectangle(9.9069, 0.5981, 10.5, 0.9757);

// Use a mean reducer.
var reducer = ee.Reducer.mean();

// Compute the unweighted mean.
var unweighted = ndvi.select(['nd']).reduceRegion(reducer, region, 30);

// compute mean weighted by cloudiness.
var weighted = ndvi.reduceRegion(reducer.splitWeights(), region, 30);

// Observe the difference as a result of weighting by cloudiness.
print('unweighted:', unweighted);
print('weighted:', weighted);

Python 설정

Python API 및 geemap를 사용한 대화형 개발에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

import ee
import geemap.core as geemap

Colab(Python)

# Load an input Landsat 8 image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_186059_20130419')

# Compute cloud score and reverse it such that the highest
# weight (100) is for the least cloudy pixels.
cloud_weight = ee.Image(100).subtract(
    ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud'])
)

# Compute NDVI and add the cloud weight band.
ndvi = image.normalizedDifference(['B5', 'B4']).addBands(cloud_weight)

# Define an arbitrary region in a cloudy area.
region = ee.Geometry.Rectangle(9.9069, 0.5981, 10.5, 0.9757)

# Use a mean reducer.
reducer = ee.Reducer.mean()

# Compute the unweighted mean.
unweighted = ndvi.select(['nd']).reduceRegion(reducer, region, 30)

# compute mean weighted by cloudiness.
weighted = ndvi.reduceRegion(reducer.splitWeights(), region, 30)

# Observe the difference as a result of weighting by cloudiness.
display('unweighted:', unweighted)
display('weighted:', weighted)

reduceRegion()를 호출하기 전에 cloudWeight를 밴드로 추가해야 합니다. 그 결과 흐린 픽셀의 가중치를 줄여 추정된 평균 NDVI가 높아졌습니다.