สถิติของพื้นที่ใกล้เคียงของรูปภาพ

คุณยังระบุพื้นที่ใกล้เคียงที่จะใช้ตัวลดแทนการระบุพื้นที่ที่จะทำการลดได้ด้วย หากต้องการลดพื้นที่ใกล้เคียงของรูปภาพ ให้ใช้ image.reduceNeighborhood() ในกรณีนี้ การลดขนาดจะเกิดขึ้นในกรอบเลื่อนเหนือรูปภาพอินพุต โดยระบุขนาดและรูปร่างของกรอบด้วย ee.Kernel เอาต์พุตของ reduceNeighborhood() จะเป็นอีกรูปภาพหนึ่ง โดยค่าพิกเซลแต่ละค่าแสดงถึงเอาต์พุตของการลดขนาดในบริเวณรอบๆ พิกเซลนั้นในรูปภาพอินพุต รูปที่ 1 แสดงการลดประเภทนี้

reduceNeighborhood diagram
รูปที่ 1 ภาพ reduceNeighborhood() ซึ่งใช้ตัวลดในเคอร์เนล

เช่น ลองใช้ภาพจากโปรแกรมภาพเกษตรกรรมแห่งชาติ (NAIP) เพื่อประเมินความแตกต่างของภูมิทัศน์ที่เกิดจากการตัดไม้ในป่าสนแคลิฟอร์เนีย กล่าวโดยละเอียดคือ ใช้ค่าความเบี่ยงเบนมาตรฐาน (SD) ในบริเวณใกล้เคียงเพื่อแสดงความแตกต่างของพื้นผิวระหว่างพื้นที่ที่มีการบันทึก (SW ของรูปภาพในรูปที่ 2) กับพื้นที่ที่ได้รับการคุ้มครอง (NE ของรูปภาพในรูปที่ 2) เช่น หากต้องการดูพื้นผิวของรูปภาพดัชนีการปกคลุมพืชพันธุ์ (NDVI) ที่ปรับค่าตามมาตรฐานของ NAIP ให้ใช้ reduceNeighborhood() เพื่อคํานวณ SD ในบริเวณใกล้เคียงที่กําหนดโดย Kernel ดังนี้

เครื่องมือแก้ไขโค้ด (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

พิกเซลที่มีค่า Kernel ที่ไม่ใช่ 0 จะรวมอยู่ในการคำนวณ ระบบจะใช้น้ำหนักของ Kernel โดยค่าเริ่มต้น แต่คุณเปลี่ยนลักษณะการทำงานนั้นได้โดยใช้อาร์กิวเมนต์ inputWeight รูปภาพอินพุตและreduceNeighborhood() เอาต์พุตจะแสดงเปรียบเทียบกันในรูปที่ 2

reduceNeighborhood input
รูปที่ 2ก. ภาพ NAIP ของชายฝั่งแคลิฟอร์เนียตอนเหนือ
reduceNeighborhood output
รูปที่ 2ข. reduceNeighborhood() เอาต์พุตโดยใช้ตัวลดค่าเบี่ยงเบนมาตรฐาน