官方实例
官方实例2
实例3
DIY
# Sun Sep 27 13:10:56 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.2 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
install.packages('image.LineSegmentDetector')
rm(list=ls());gc()
require(image.LineSegmentDetector)
# image.LineSegmentDetector包,检测图像中的线段
# LSD是线性时间线段检测器,可提供亚像素准确的结果。 它设计为可在任何数字图像上工作而无需调整参数。 它控制自己的错误检测次数:平均而言,每个图像允许一个错误警报。 该方法基于Burns,Hanson和Riseman的方法,并根据Desolneux,Moisan和Morel的理论使用了一种相反的验证方法。
# http://www.ipol.im/pub/art/2012/gjmr-lsd/?utm_source=doi
#
# image_line_segment_detector(
# x,
# scale = 0.8,
# sigma_scale = 0.6,
# quant = 2,
# ang_th = 22.5,
# log_eps = 0,
# density_th = 0.7,
# n_bins = 1024,
# union = FALSE,
# union_min_length = 5,
# union_max_distance = 5,
# union_ang_th = 7,
# union_use_NFA = FALSE,
# union_log_eps = 0
# )
# Arguments
# x
# a matrix of image pixel values in the 0-255 range.
#
# scale
# 正数值。 当不同于1.0时,LSD将在检测线段之前通过高斯滤波按“比例”因子对输入图像进行缩放。
# 示例:如果scale = 0.8,则在应用线段检测器之前,
# 将对输入图像进行二次采样,使其尺寸为其大小的80%。 建议值:0.8
#
# sigma_scale
# 正数值。 当scale!= 1.0时,高斯滤波器的sigma为:
# 如果scale <1.0,则sigma = sigma_scale / scale;如果scale> = 1.0,则sigma = sigma_scale。 建议值:0.6
#
# quant
# 正数值。 绑定到梯度范数上的量化误差。 示例:如果将灰度级量化为整数步,则由于量化而导致的梯度(由有限差分计算)误差将以2.0为界,因为最坏的情况是误差为1和-1时,误差为2.0。 建议值:2.0
#
# ang_th
# 0到180范围内的正数值。 区域增长算法中的渐变角度公差(以度为单位)。 建议值:22.5
#
# log_eps
# 检测阈值,如果-log10(NFA)> log_eps,则接受。 值越大,检测器越严格,将导致更少的检测。 (请注意,“减号”使此行为与NFA的行为相反。) 建议值:0.0。
#
# density_th
# 0-1范围内的正数值。 矩形中“支撑”点的最小比例。 建议值:0.7。
#
# n_bins
# 正整数值。 梯度模量的伪排序中使用的仓数。 建议值:1024
#
# union
# 逻辑指示是否需要通过并集结束分段发布过程映像。 默认为FALSE。
#
# union_min_length
# 具有要合并的段的最小长度的数值
#
# union_max_distance
# 数值,我们将合并的两条线之间的最大距离
#
# union_ang_th
# 带有角度阈值的数值,以便进行并集
#
# union_use_NFA
# 逻辑指示使用NFA进行合并
#
# union_log_eps
# 联合检测阈值
# Sun Sep 27 16:12:51 2020 ----exp--------------------------
library(pixmap)
imagelocation <- system.file("extdata", "chairs.pgm", package="image.LineSegmentDetector")
image <- read.pnm(file = imagelocation, cellres = 1)
x <- image@grey * 255
linesegments <- image_line_segment_detector(x)
linesegments
plot(image)
plot(linesegments, add = TRUE, col = "red")
imagelocation <- system.file("extdata", "le-piree.pgm", package="image.LineSegmentDetector")
image <- read.pnm(file = imagelocation, cellres = 1)
linesegments <- image_line_segment_detector(image@grey * 255)
plot(image)
plot(linesegments)
# Sun Sep 27 16:14:40 2020 --灰度或RGB图像
library(magick)
x <- image_read(system.file("extdata", "atomium.jpg", package="image.LineSegmentDetector"))
mat <- image_data(x, channels = "gray")
mat <- as.integer(mat, transpose = TRUE)
mat <- drop(mat)
linesegments <- image_line_segment_detector(mat)
plot(linesegments, lwd = 2)
# Sun Sep 27 16:15:01 2020 --DIY----------------------------
'https://s1.ax1x.com/2020/09/26/0FPUFf.png' %>%
image_read() %>%
image_data(channels = 'gray') %>%
as.integer(transpose=TRUE) %>%
drop() %>%
image_line_segment_detector() %>%
plot()