The image.LineSegmentDetector R package detects line segments in images.
Read in an image with values in the 0-255 range (pgm image: http://netpbm.sourceforge.net/doc/pgm.html)
library(image.LineSegmentDetector)
library(pixmap)
<- read.pnm(file = system.file("extdata", "le-piree.pgm", package="image.LineSegmentDetector"), cellres = 1)
image plot(image)
<- image_line_segment_detector(image@grey * 255)
linesegments plot(linesegments)
If you have another type of image (jpg, png, …). Convert the image to portable grey format before applying the function
library(magick)
<- image_read(system.file("extdata", "atomium.jpg", package="image.LineSegmentDetector"))
x <- image_data(x, channels = "gray")
mat <- as.integer(mat, transpose = TRUE)
mat <- drop(mat)
mat <- image_line_segment_detector(mat)
linesegments plot(linesegments, lwd = 2)
<- image_draw(x)
plt $lines[, "y1"] <- image_info(x)$height - linesegments$lines[, "y1"]
linesegments$lines[, "y2"] <- image_info(x)$height - linesegments$lines[, "y2"]
linesegmentsplot(linesegments, add = TRUE, col = "red", lwd = 2)
dev.off()
Need support in image recognition? Contact BNOSAC: http://www.bnosac.be