GEE霍夫变换(hough transform)
2019-01-04 本文已影响0人
赤豆冰棍
霍夫变换
主要功能
使用霍夫变换,检测直线特征
代码
// An example finding linear features using the HoughTransform.
// Load an image and compute NDVI.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_033032_20170719');
var ndvi = image.normalizedDifference(['B5', 'B4']);
// Apply a Canny edge detector.
var canny = ee.Algorithms.CannyEdgeDetector({
image: ndvi,
threshold: 0.4
}).multiply(255);
// Apply the Hough transform.
var h = ee.Algorithms.HoughTransform({
image: canny,
gridSize: 256,
inputThreshold: 50,
lineThreshold: 100
});
// Display.
Map.setCenter(-103.80140, 40.21729, 13);
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'source_image');
Map.addLayer(canny.updateMask(canny), {min: 0, max: 1, palette: 'blue'}, 'canny');
Map.addLayer(h.updateMask(h), {min: 0, max: 1, palette: 'red'}, 'hough');
步骤分析
- 创建ee对象,获取LC08数据
- 计算NDVI
- canny边缘检测
- 霍夫变换
- 设置地图中心,缩放等级
- 添加原始数据图层
- 显示canny边缘检测结果
- 显示霍夫变换检测结果
主要方法
- ee.Algorithms.HoughTransform()
Applies the Hough transform to an image. For every input band, outputs a band where lines are detected by thresholding the Hough transform with a value of lineThreshold. The output band is named [input]_lines, where [input] is the name of the original band. The defaults provided for the parameters are intended as a starting point for use with UINT8 images.
Arguments:
image (Image):
The image to which to apply the transform.
gridSize (Integer, default: 256):
Grid size.
inputThreshold (Float, default: 64):
Value threshold for input image. Pixels equal to or above this value are considered active.
lineThreshold (Float, default: 72):
Threshold for line detection. Values equal to or above this threshold on the Hough transform are considered to be detected lines.
smooth (Boolean, default: true):
Whether to smooth the Hough transform before line detection.
Returns: Image
对输入影像对象执行霍夫变换。默认参数是针对无符号八位整型数据的。
输入参数:输入影像对象,gridSize(格网大小,默认是256整数),inputThreshold(检测阈值),lineThreshold(线检测阈值),smooth(布尔型,默认为真)