GEE案例

GEE形态学处理

2019-01-03  本文已影响0人  赤豆冰棍

形态学处理实现(膨胀,腐蚀等)

主要功能

对MODIS数据的土地覆被图斑完成形态学处理

代码

// Morphological processing of land cover.  This example
// includes spatial smoothing (neighborhood mode) followed by
// dilation, erosion and dilation again.  Reprojection is
// used to force these operations to be performed at the
// native scale of the input (rather than variable pixel
// sizes based on zoom level).

// Force projection of 500 meters/pixel, which is the native MODIS resolution.
var SCALE = 500;

// Load a 2001 MODIS land cover image.
var image1 = ee.Image('MODIS/051/MCD12Q1/2001_01_01');
// Select the classification band of interest.
var image2 = image1.select(['Land_Cover_Type_1']);
// Reproject to WGS84 to force the image to be reprojected on load.
// This is just for display purposes, to visualize the input to
// the following operations.  The next reproject is sufficient
// to force the computation to occur at native scale.
var image3 = image2.reproject('EPSG:4326', null, SCALE);
// Smooth with a mode filter.
var image4 = image3.focal_mode();
// Use erosion and dilation to get rid of small islands.
var image5 = image4.focal_max(3).focal_min(5).focal_max(3);
// Reproject to force the operations to be performed at SCALE.
var image6 = image5.reproject('EPSG:4326', null, SCALE);

// Define display paramaters with appropriate colors for the MODIS
// land cover classification image.
var PALETTE = [
    'aec3d4', // water
    '152106', '225129', '369b47', '30eb5b', '387242', // forest
    '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40', // shrub, grass, savannah
    '111149', // wetlands
    'cdb33b', // croplands
    'cc0013', // urban
    '33280d', // crop mosaic
    'd7cdcc', // snow and ice
    'f7e084', // barren
    '6f6f6f'  // tundra
].join(',');

var vis_params = {min: 0, max: 17, palette: PALETTE};

// Display each step of the computation.
Map.setCenter(-113.41842, 40.055489, 6);
Map.addLayer(image2, vis_params, 'IGBP classification');
Map.addLayer(image3, vis_params, 'Reprojected');
Map.addLayer(image4, vis_params, 'Mode');
Map.addLayer(image5, vis_params, 'Smooth');
Map.addLayer(image6, vis_params, 'Smooth');

步骤分析

  1. 定义重投影像素分辨率为500,这是MODIS影像的默认大小
  2. 创建ee对象,获取MODIS数据,选择Land_Cover_Type_1波段
  3. 重投影
  4. 平滑处理
  5. 膨胀腐蚀操作,剔除细小图斑
  6. 重投影5步骤结果
  7. 添加一个色板,用于显示不同土地覆被类型
  8. 设置地图中心,缩放等级
  9. 添加形态学操作结果图层,设置显示参数

主要方法

  1. ee.Image.reproject()

Force an image to be computed in a given projection and resolution.
Arguments:
this:image (Image):
The Image to reproject.
crs (Projection):
The CRS to project the image to.
crsTransform (List, default: null):
The list of CRS transform values. This is a row-major ordering of the 3x2 transform matrix. This option is mutually exclusive with the scale option, and replaces any transform already on the projection.
scale (Float, default: null):
If scale is specified, then the projection is scaled by dividing the specified scale value by the nominal size of a meter in the specified projection. If scale is not specified, then the scale of the given projection will be used.
Returns: Image

强制实现一个影像对象重投影。输入参数:输入影像对象,crs(投影),crsTransform(列表,默认为空),尺度参数(重采样分辨率)浮点型,默认使用原始大小

  1. ee.Image.focal_mode()
    Applies a morphological reducer() filter to each band of an image using a named or custom kernel.
    Arguments:
    this:image (Image):
    The image to which to apply the operations.
    radius (Float, default: 1.5):
    The radius of the kernel to use.
    kernelType (String, default: "circle"):
    The type of kernel to use. Options include: 'circle', 'square', 'cross', 'plus', octagon' and 'diamond'.
    units (String, default: "pixels"):
    If a kernel is not specified, this determines whether the kernel is in meters or pixels.
    iterations (Integer, default: 1):
    The number of times to apply the given kernel.
    kernel (Kernel, default: null):
    A custom kernel. If used, kernelType and radius are ignored.
    Returns: Image

对输入影像对象的每一个波段执行形态学reducer()操作,类似于滤波操作,使用核名称或自定义核。
输入参数:输入影像对象,半径(浮点型,默认1.5),核类型(字符串型,默认:圆形,可选:圆形,正方形,十字,plus,八角形,菱形),单位(默认1像素'pixels',也可以指定为米'meters'),循环次数(整形,默认为1),核心(自定义核心,若使用,则核心类型和半径可以不指定)

  1. ee.Image.focal_max();ee.Image.focal_min()
    Applies a morphological reducer() filter to each band of an image using a named or custom kernel.
    Arguments:
    this:image (Image):
    The image to which to apply the operations.
    radius (Float, default: 1.5):
    The radius of the kernel to use.
    kernelType (String, default: "circle"):
    The type of kernel to use. Options include: 'circle', 'square', 'cross', 'plus', octagon' and 'diamond'.
    units (String, default: "pixels"):
    If a kernel is not specified, this determines whether the kernel is in meters or pixels.
    iterations (Integer, default: 1):
    The number of times to apply the given kernel.
    kernel (Kernel, default: null):
    A custom kernel. If used, kernelType and radius are ignored.
    Returns: Image

与2中参数相同,实现影像对象腐蚀膨胀操作。膨胀其实就是求局部最大值,腐蚀是求局部最小值。
本例中,var image5 = image4.focal_max(3).focal_min(5).focal_max(3);

  1. ee.List.join()
    Returns a string containing the elements of the list joined together with the specified separator between elements.
    Arguments:
    this:list (List)
    separator (String, default: "")
    Returns: String

使用指定分隔字符来连接一个列表的所有元素,返回一个字符串

上一篇下一篇

猜你喜欢

热点阅读