ImageCollection 축소

ImageCollection에서 이미지를 합성하려면 imageCollection.reduce()를 사용하세요. 이렇게 하면 컬렉션의 모든 이미지가 이미지의 최솟값, 최댓값, 평균 또는 표준 편차를 나타내는 단일 이미지로 합성됩니다. 리듀서에 관한 자세한 내용은 리듀서 섹션을 참고하세요. 예를 들어 컬렉션에서 중간값 이미지를 만들려면 다음 단계를 따르세요.

코드 편집기 (JavaScript)

// Load a Landsat 8 collection for a single path-row.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filter(ee.Filter.eq('WRS_PATH', 44))
    .filter(ee.Filter.eq('WRS_ROW', 34))
    .filterDate('2014-01-01', '2015-01-01');

// Compute a median image and display.
var median = collection.median();
Map.setCenter(-122.3578, 37.7726, 12);
Map.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'Median');

Python 설정

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

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 collection for a single path-row.
collection = (
    ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filter(ee.Filter.eq('WRS_PATH', 44))
    .filter(ee.Filter.eq('WRS_ROW', 34))
    .filterDate('2014-01-01', '2015-01-01')
)

# Compute a median image and display.
median = collection.median()
m = geemap.Map()
m.set_center(-122.3578, 37.7726, 12)
m.add_layer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Median')
m

출력 이미지의 각 위치에서 각 밴드의 픽셀 값은 입력 이미지 (컬렉션의 이미지)에서 마스크가 적용되지 않은 모든 픽셀의 중간값입니다. 이전 예에서 median()는 다음 호출을 위한 편의 메서드입니다.

코드 편집기 (JavaScript)

// Reduce the collection with a median reducer.
var median = collection.reduce(ee.Reducer.median());

// Display the median image.
Map.addLayer(median,
             {bands: ['B4_median', 'B3_median', 'B2_median'], max: 0.3},
             'Also median');

Python 설정

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

import ee
import geemap.core as geemap

Colab (Python)

# Reduce the collection with a median reducer.
median = collection.reduce(ee.Reducer.median())

# Display the median image.
m.add_layer(
    median,
    {'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3},
    'Also median',
)
m

편의 메서드 대신 reduce()을 사용하면 밴드 이름이 달라집니다. 특히 리듀서의 이름이 밴드 이름에 추가되었습니다.

reduce()를 사용하여 더 복잡한 감소도 가능합니다. 예를 들어 컬렉션에 대한 장기 선형 추세를 계산하려면 선형 회귀 감소 중 하나를 사용하세요. 다음 코드는 MODIS 향상된 식물지수 (EVI)의 선형 추세를 계산합니다.

코드 편집기 (JavaScript)

// This function adds a band representing the image timestamp.
var addTime = function(image) {
  return image.addBands(image.metadata('system:time_start')
    // Convert milliseconds from epoch to years to aid in
    // interpretation of the following trend calculation.
    .divide(1000 * 60 * 60 * 24 * 365));
};

// Load a MODIS collection, filter to several years of 16 day mosaics,
// and map the time band function over it.
var collection = ee.ImageCollection('MODIS/006/MYD13A1')
  .filterDate('2004-01-01', '2010-10-31')
  .map(addTime);

// Select the bands to model with the independent variable first.
var trend = collection.select(['system:time_start', 'EVI'])
  // Compute the linear trend over time.
  .reduce(ee.Reducer.linearFit());

// Display the trend with increasing slopes in green, decreasing in red.
Map.setCenter(-96.943, 39.436, 5);
Map.addLayer(
    trend,
    {min: 0, max: [-100, 100, 10000], bands: ['scale', 'scale', 'offset']},
    'EVI trend');

Python 설정

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

import ee
import geemap.core as geemap

Colab (Python)

# This function adds a band representing the image timestamp.
def add_time(image):
  return image.addBands(
      image.metadata('system:time_start')
      # Convert milliseconds from epoch to years to aid in
      # interpretation of the following trend calculation.
      .divide(1000 * 60 * 60 * 24 * 365)
  )


# Load a MODIS collection, filter to several years of 16 day mosaics,
# and map the time band function over it.
collection = (
    ee.ImageCollection('MODIS/006/MYD13A1')
    .filterDate('2004-01-01', '2010-10-31')
    .map(add_time)
)

# Select the bands to model with the independent variable first.
trend = collection.select(['system:time_start', 'EVI']).reduce(
    # Compute the linear trend over time.
    ee.Reducer.linearFit()
)

# Display the trend with increasing slopes in green, decreasing in red.
m.set_center(-96.943, 39.436, 5)
m = geemap.Map()
m.add_layer(
    trend,
    {
        'min': 0,
        'max': [-100, 100, 10000],
        'bands': ['scale', 'scale', 'offset'],
    },
    'EVI trend',
)
m

이 예에서 감소의 출력은 선형 회귀의 기울기에 관한 밴드 하나 (scale)와 절편에 관한 밴드 하나 (offset)가 있는 두 개의 밴드 이미지입니다. API 문서를 살펴보고 ImageCollection를 단일 Image로 줄이는 데 사용할 수 있는 리듀서의 목록을 확인하세요.

합성물에는 프로젝션이 없음

이미지 컬렉션을 줄여서 만든 합성 이미지는 요청된 프로젝션에서 픽셀을 생성할 수 있으므로 고정된 출력 프로젝션이 없습니다. 대신 합성물에는 1도 해상도 픽셀이 있는 WGS-84의 기본 프로젝션이 있습니다. 기본 프로젝션이 있는 합성물은 요청된 출력 프로젝션에서 계산됩니다. 요청은 코드 편집기에 합성물을 표시하거나 (코드 편집기에서 배율투영을 설정하는 방법 알아보기) ReduceRegion 또는 Export와 같은 집계에서 투영/배율을 명시적으로 지정하여 발생합니다.