Seperti yang disebutkan dalam dokumen Proyeksi, Earth Engine melakukan pengambilan sampel ulang tetangga terdekat secara default selama re-proyeksi. Anda dapat mengubah perilaku ini
dengan metode resample()
atau reduceResolution()
. Secara khusus, saat salah satu
metode ini diterapkan ke gambar input, setiap proyeksi ulang input
yang diperlukan akan dilakukan menggunakan metode agregasi atau pengambilan sampel ulang yang ditunjukkan.
Pengambilan ulang sampel
resample()
menyebabkan metode pengambilan sampel ulang yang ditunjukkan ('bilinear'
atau
'bicubic'
) digunakan pada proyeksi ulang berikutnya. Karena input diminta dalam
proyeksi output, re-proyeksi implisit dapat terjadi sebelum operasi
lain pada input. Karena alasan ini, panggil resample()
langsung pada gambar
input. Perhatikan contoh sederhana berikut:
Editor Kode (JavaScript)
// Load a Landsat image over San Francisco, California, UAS. var landsat = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20160323'); // Set display and visualization parameters. Map.setCenter(-122.37383, 37.6193, 15); var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3}; // Display the Landsat image using the default nearest neighbor resampling. // when reprojecting to Mercator for the Code Editor map. Map.addLayer(landsat, visParams, 'original image'); // Force the next reprojection on this image to use bicubic resampling. var resampled = landsat.resample('bicubic'); // Display the Landsat image using bicubic resampling. Map.addLayer(resampled, visParams, 'resampled');
import ee import geemap.core as geemap
Colab (Python)
# Load a Landsat image over San Francisco, California, UAS. landsat = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20160323') # Set display and visualization parameters. m = geemap.Map() m.set_center(-122.37383, 37.6193, 15) vis_params = {'bands': ['B4', 'B3', 'B2'], 'max': 0.3} # Display the Landsat image using the default nearest neighbor resampling. # when reprojecting to Mercator for the Code Editor map. m.add_layer(landsat, vis_params, 'original image') # Force the next reprojection on this image to use bicubic resampling. resampled = landsat.resample('bicubic') # Display the Landsat image using bicubic resampling. m.add_layer(resampled, vis_params, 'resampled')
Perhatikan bahwa pengambilan sampel ulang 'bicubic'
menghasilkan piksel output yang tampak
halus dibandingkan dengan gambar asli (Gambar 1).
Urutan operasi untuk contoh kode ini digambarkan dalam Gambar 2. Secara khusus, re-proyeksi implisit ke proyeksi maps Mercator dilakukan dengan metode resampling yang ditentukan pada gambar input.
Gambar 2. Diagram alir operasi saat resample()
dipanggil pada gambar
input sebelum ditampilkan di Code Editor. Garis melengkung menunjukkan alur informasi ke reproject: khususnya, proyeksi output, skala, dan metode resampling yang akan digunakan.
Mengurangi Resolusi
Misalkan, alih-alih mengambil sampel ulang selama re-proyeksi, sasaran Anda adalah
menggabungkan piksel ke piksel yang lebih besar dalam proyeksi yang berbeda. Hal ini berguna saat
membandingkan set data gambar pada skala yang berbeda, misalnya piksel 30 meter dari produk berbasis Landsat ke piksel kasar (skala lebih tinggi) dari produk berbasis MODIS. Anda dapat mengontrol proses agregasi ini dengan metode
reduceResolution()
. Seperti resample()
, panggil reduceResolution()
pada input, agar
memengaruhi proyeksi ulang gambar berikutnya. Contoh berikut menggunakan
reduceResolution()
untuk membandingkan data tutupan hutan pada resolusi 30 meter dengan
indeks vegetasi pada resolusi 500 meter:
Editor Kode (JavaScript)
// Load a MODIS EVI image. var modis = ee.Image(ee.ImageCollection('MODIS/061/MOD13A1').first()) .select('EVI'); // Display the EVI image near La Honda, California. Map.setCenter(-122.3616, 37.5331, 12); Map.addLayer(modis, {min: 2000, max: 5000}, 'MODIS EVI'); // Get information about the MODIS projection. var modisProjection = modis.projection(); print('MODIS projection:', modisProjection); // Load and display forest cover data at 30 meters resolution. var forest = ee.Image('UMD/hansen/global_forest_change_2023_v1_11') .select('treecover2000'); Map.addLayer(forest, {max: 80}, 'forest cover 30 m'); // Get the forest cover data at MODIS scale and projection. var forestMean = forest // Force the next reprojection to aggregate instead of resampling. .reduceResolution({ reducer: ee.Reducer.mean(), maxPixels: 1024 }) // Request the data at the scale and projection of the MODIS image. .reproject({ crs: modisProjection }); // Display the aggregated, reprojected forest cover data. Map.addLayer(forestMean, {max: 80}, 'forest cover at MODIS scale');
import ee import geemap.core as geemap
Colab (Python)
# Load a MODIS EVI image. modis = ee.Image(ee.ImageCollection('MODIS/006/MOD13A1').first()).select('EVI') # Display the EVI image near La Honda, California. m.set_center(-122.3616, 37.5331, 12) m.add_layer(modis, {'min': 2000, 'max': 5000}, 'MODIS EVI') # Get information about the MODIS projection. modis_projection = modis.projection() display('MODIS projection:', modis_projection) # Load and display forest cover data at 30 meters resolution. forest = ee.Image('UMD/hansen/global_forest_change_2015').select( 'treecover2000' ) m.add_layer(forest, {'max': 80}, 'forest cover 30 m') # Get the forest cover data at MODIS scale and projection. forest_mean = ( forest # Force the next reprojection to aggregate instead of resampling. .reduceResolution(reducer=ee.Reducer.mean(), maxPixels=1024) # Request the data at the scale and projection of the MODIS image. .reproject(crs=modis_projection) ) # Display the aggregated, reprojected forest cover data. m.add_layer(forest_mean, {'max': 80}, 'forest cover at MODIS scale')
Dalam contoh ini, perhatikan bahwa proyeksi output ditetapkan secara eksplisit dengan
reproject()
. Selama re-proyeksi ke proyeksi sinus MODIS, piksel yang lebih kecil digabungkan dengan pengurangan yang ditentukan (ee.Reducer.mean()
dalam contoh) daripada pengambilan sampel ulang. Urutan
operasi ini diilustrasikan dalam Gambar 3. Meskipun contoh ini menggunakan
reproject()
untuk membantu memvisualisasikan efek reduceResolution()
, sebagian besar skrip
tidak perlu melakukan proyeksi ulang secara eksplisit; lihat peringatan
di sini.
Gambar 3. Diagram alir operasi saat reduceResolution()
dipanggil pada
gambar input sebelum reproject()
. Garis melengkung menunjukkan alur informasi ke reproject: khususnya, proyeksi output, skala, dan metode agregasi piksel yang akan digunakan.
Bobot piksel untuk ReduceResolution
Bobot piksel yang digunakan selama proses agregasi reduceResolution()
didasarkan pada tumpang-tindih antara piksel yang lebih kecil yang digabungkan dan
piksel yang lebih besar yang ditentukan oleh proyeksi output. Hal ini diilustrasikan dalam Gambar
4.
Gambar 4. Piksel input (hitam) dan piksel output (biru) untuk
reduceResolution()
.
Perilaku defaultnya adalah bobot piksel input dihitung sebagai fraksi area piksel output yang tercakup oleh piksel input. Dalam diagram, piksel
output memiliki area a
, bobot piksel input dengan area persimpangan b
dihitung sebagai b/a
, dan bobot piksel input dengan area persimpangan c
dihitung sebagai c/a
. Perilaku ini dapat menghasilkan hasil yang tidak terduga saat menggunakan pengurangan selain pengurangan rata-rata. Misalnya, untuk menghitung area hutan per piksel, gunakan pengurangan rata-rata untuk menghitung fraksi piksel yang tercakup, lalu kalikan dengan area (bukan menghitung area dalam piksel yang lebih kecil, lalu menambahkannya dengan pengurangan jumlah):
Editor Kode (JavaScript)
// Compute forest area per MODIS pixel. var forestArea = forest.gt(0) // Force the next reprojection to aggregate instead of resampling. .reduceResolution({ reducer: ee.Reducer.mean(), maxPixels: 1024 }) // The reduce resolution returns the fraction of the MODIS pixel // that's covered by 30 meter forest pixels. Convert to area // after the reduceResolution() call. .multiply(ee.Image.pixelArea()) // Request the data at the scale and projection of the MODIS image. .reproject({ crs: modisProjection }); Map.addLayer(forestArea, {max: 500 * 500}, 'forested area at MODIS scale');
import ee import geemap.core as geemap
Colab (Python)
# Compute forest area per MODIS pixel. forest_area = ( forest.gt(0) # Force the next reprojection to aggregate instead of resampling. .reduceResolution(reducer=ee.Reducer.mean(), maxPixels=1024) # The reduce resolution returns the fraction of the MODIS pixel # that's covered by 30 meter forest pixels. Convert to area # after the reduceResolution() call. .multiply(ee.Image.pixelArea()) # Request the data at the scale and projection of the MODIS image. .reproject(crs=modis_projection) ) m.add_layer(forest_area, {'max': 500 * 500}, 'forested area at MODIS scale') m