EZ | Convolutions | GEE - 12

Convolutions


卷積

想要對(duì)圖像執(zhí)行線性卷積操作,使用image.convolve()函數(shù)。該函數(shù)只有一個(gè)參數(shù),稱之為ee.Kernel,它由形狀和kernel中的權(quán)重共同決定,輸出的圖像中每個(gè)像素值都由內(nèi)核值和輸入圖像像素值的線性組合共同確定。內(nèi)核分別應(yīng)用在每個(gè)波段,例如,當(dāng)需要使用平滑內(nèi)核過濾掉高頻信息,可做如下操作:

// Load and display an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');
Map.setCenter(-121.9785, 37.8694, 11);
Map.addLayer(image, {bands: ['B5', 'B4', 'B3'], max: 0.5}, 'input image');

// Define a boxcar or low-pass kernel.
var boxcar = ee.Kernel.square({
  radius: 7, units: 'pixels', normalize: true
});

// Smooth the image by convolving with the boxcar kernel.
var smooth = image.convolve(boxcar);
Map.addLayer(smooth, {bands: ['B5', 'B4', 'B3'], max: 0.5}, 'smoothed');

使用低通的濾波器進(jìn)行卷積,輸出圖如Fig.1所示。觀察內(nèi)核的參數(shù)明確其尺寸和系數(shù)。一般的,將units設(shè)置為像素,radius指定為內(nèi)核覆蓋的中心的像素?cái)?shù)。如果normalize設(shè)置為true,則內(nèi)核系數(shù)之和為1,如果對(duì)幅度進(jìn)行了設(shè)置,則內(nèi)核系數(shù)將乘上這個(gè)值。如果內(nèi)核系數(shù)中存在負(fù)值,則可以將normalize設(shè)置為true,總和為零。

Fig.1

使用其它內(nèi)核來實(shí)現(xiàn)所需要的處理效果,這一例子使用拉普拉斯算子內(nèi)核進(jìn)行邊界檢測(cè):

// Define a Laplacian, or edge-detection kernel.
var laplacian = ee.Kernel.laplacian8({ normalize: false });

// Apply the edge-detection kernel.
var edgy = image.convolve(laplacian);
Map.addLayer(edgy,
             {bands: ['B5', 'B4', 'B3'], max: 0.5, format: 'png'},
             'edges');

請(qǐng)注意可視化參數(shù)的格式說明符,為了提高運(yùn)行效率,GEE將會(huì)以JPEG格式將圖層傳遞到代碼編輯器中,但邊界則使用PNG格式,用以處理圖像邊界像素的透明度。當(dāng)看起來不夠連續(xù)時(shí),格式設(shè)置為PNG會(huì)一致顯示。使用拉普拉斯進(jìn)行邊界檢測(cè),結(jié)果如下圖:

Fig.2

還有其他邊緣檢測(cè)的內(nèi)核,例如Sobel、Prewitt、Roberts等等,可以通過kernel.rotate()進(jìn)行改變,其他的低通內(nèi)核還包括高斯核核具有均勻權(quán)重的各種尺寸和形狀的內(nèi)核,想要?jiǎng)?chuàng)建具有任意定義權(quán)重和形狀的內(nèi)核,使用ee.Kernel.fixed ()函數(shù)進(jìn)行設(shè)置。下面的例子設(shè)置了一個(gè)9*9的內(nèi)核:

// Create a list of weights for a 9x9 kernel.
var list = [1, 1, 1, 1, 1, 1, 1, 1, 1];
// The center of the kernel is zero.
var centerList = [1, 1, 1, 1, 0, 1, 1, 1, 1];
// Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix.
var lists = [list, list, list, list, centerList, list, list, list, list];
// Create the kernel from the weights.
var kernel = ee.Kernel.fixed(9, 9, lists, -4, -4, false);
print(kernel);

\tag{此頁面最后更新于2019年3月18日}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容