이미지 이웃 통계

감소를 실행할 영역을 지정하는 대신 감소기를 적용할 이웃을 지정할 수도 있습니다. 이미지 이웃을 줄이려면 image.reduceNeighborhood()를 사용하세요. 이 경우 ee.Kernel로 지정된 창 크기와 모양을 사용하여 입력 이미지의 슬라이딩 창에서 감소가 발생합니다. reduceNeighborhood()의 출력은 다른 이미지이며 각 픽셀 값은 입력 이미지의 해당 픽셀 주변 영역에서 감소의 출력을 나타냅니다. 그림 1은 이러한 유형의 감소를 보여줍니다.

reduceNeighborhood 다이어그램
그림 1. 커널에 리듀서가 적용된 reduceNeighborhood()의 그림입니다.

예를 들어 National Agriculture Imagery Program (NAIP) 이미지를 사용하여 캘리포니아 레드우드 숲에서 벌목으로 인한 경관 차이를 수치화할 수 있습니다. 특히 이웃의 표준 편차 (SD)를 사용하여 기록된 영역 (그림 2의 이미지에서 남서쪽)과 보호된 영역(그림 2의 이미지에서 북동쪽) 간의 질감 차이를 나타냅니다. 예를 들어 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

0이 아닌 커널 값이 있는 모든 픽셀이 계산에 포함됩니다. 커널 가중치는 기본적으로 사용되지만 inputWeight 인수로 이 동작을 변경할 수 있습니다. 입력 이미지와 reduceNeighborhood() 출력이 그림 2에 비교되어 있습니다.

reduceNeighborhood 입력
그림 2a. 북부 캘리포니아 해안의 NAIP 이미지
reduceNeighborhood 출력
그림 2b. 표준 편차 감소기를 사용하는 reduceNeighborhood() 출력입니다.