影像相邻像素计数
主要功能
将输入影像波段1二分为两部分,然后统计同类相邻像素个数
代码
// Image.ConnectedPixelCount example.
// Split pixels of band 01 into "bright" (arbitrarily defined as
// reflectance > 0.3) and "dim". Highlight small (<30 pixels)
// standalone islands of "bright" or "dim" type.
var img = ee.Image('MODIS/006/MOD09GA/2012_03_09')
.select('sur_refl_b01')
.multiply(0.0001);
// Create a threshold image.
var bright = img.gt(0.3);
// Compute connected pixel counts; stop searching for connected pixels
// once the size of the connected neightborhood reaches 30 pixels, and
// use 8-connected rules.
var conn = bright.connectedPixelCount({
maxSize: 30,
eightConnected: true
});
// Make a binary image of small clusters.
var smallClusters = conn.lt(30);
Map.setCenter(-107.24304, 35.78663, 8);
Map.addLayer(img, {min: 0, max: 1}, 'original');
Map.addLayer(smallClusters.updateMask(smallClusters),
{min: 0, max: 1, palette: 'FF0000'}, 'cc');
步骤分析
- 创建ee对象,获取MODIS数据,选择波段一,乘以系数0.0001
- 二分波段一,设置大于0.3为明亮部分
- 统计明亮部分,相邻像素个数
- 筛选统计结果,获得少于30个像素的部分
- 设置地图中心,缩放等级
- 添加筛选结果图层,只显示小于30个像元部分
主要方法
- ee.Image.connectedPixelCount()
Generate an image where each pixel contains the number of 4- or 8-connected neighbors (including itself).
Arguments:
this:input (Image): The input image.
maxSize (Integer, default: 100): The maximum size of the neighborhood in pixels.
eightConnected (Boolean, default: true): Whether to use 8-connected rather 4-connected rules.
Returns: Image
生成每一个像素的4邻域或者8邻域的像素个数统计(包含像素本身)。
输入参数:输入影像对象,maxSize(统计的像素个数阈值),八邻域(布尔值,默认为真)
网友评论