邊緣偵測

邊緣偵測可用於多種圖像處理工作。除了「 卷積」一節所述的邊緣偵測核,Earth Engine 還有幾種專門的邊緣偵測演算法。Canny 邊緣偵測演算法(Canny 1986) 使用四個獨立的篩選器來識別對角、垂直和水平邊緣。計算會擷取水平和垂直方向的第一個導數值,並計算漸層大小。系統會抑制較小幅度的漸層。如要消除高頻雜訊,可視需要使用高斯核來預先篩選圖片。例如:

程式碼編輯器 (JavaScript)

// Load a Landsat 8 image, select the panchromatic band.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318').select('B8');

// Perform Canny edge detection and display the result.
var canny = ee.Algorithms.CannyEdgeDetector({
  image: image, threshold: 10, sigma: 1
});
Map.setCenter(-122.054, 37.7295, 10);
Map.addLayer(canny, {}, 'canny');

請注意,threshold 參數會決定最小漸層大小,而 sigma 參數則是高斯預先篩選器的標準差 (SD),用於移除高頻雜訊。針對從邊緣偵測器擷取的線條,Earth Engine 會實作 Hough 轉換 (Duda and Hart 1972)。接續先前的範例,使用以下方法從 Canny 偵測器中擷取線條:

程式碼編輯器 (JavaScript)

// Perform Hough transform of the Canny result and display.
var hough = ee.Algorithms.HoughTransform(canny, 256, 600, 100);
Map.addLayer(hough, {}, 'hough');

Earth Engine 中的另一個專用演算法是 zeroCrossing()。零交點的定義是指右側、底部或對角右下方像素的符號相反的任何像素。如果這些像素中有任何一個的符號相反,則會將目前的像素設為 1 (零交點);否則會設為零。如要偵測邊緣,可以將零交點演算法套用至圖片二階導數的估計值。以下示範如何使用 zeroCrossing() 進行邊緣偵測:

程式碼編輯器 (JavaScript)

// Load a Landsat 8 image, select the panchromatic band.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318').select('B8');
Map.addLayer(image, {max: 12000});

// Define a "fat" Gaussian kernel.
var fat = ee.Kernel.gaussian({
  radius: 3,
  sigma: 3,
  units: 'pixels',
  normalize: true,
  magnitude: -1
});

// Define a "skinny" Gaussian kernel.
var skinny = ee.Kernel.gaussian({
  radius: 3,
  sigma: 1,
  units: 'pixels',
  normalize: true,
});

// Compute a difference-of-Gaussians (DOG) kernel.
var dog = fat.add(skinny);

// Compute the zero crossings of the second derivative, display.
var zeroXings = image.convolve(dog).zeroCrossing();
Map.setCenter(-122.054, 37.7295, 10);
Map.addLayer(zeroXings.selfMask(), {palette: 'FF0000'}, 'zero crossings');

加州舊金山機場附近區域的零交點輸出內容應類似圖 1 所示。

SFO 零交叉
圖 1. 零交點輸出 (紅色),背景為加州舊金山機場附近區域的 Landsat 8 全色波段 (右圖)。