Description Usage Arguments Value Examples
View source: R/canny_edges_detector.R
Canny Edge Detector for Images. See https://en.wikipedia.org/wiki/Canny_edge_detector. Adapted from https://github.com/Neseb/canny.
1 | image_canny_edge_detector(x, s = 2, low_thr = 3, high_thr = 10, accGrad = TRUE)
|
x |
a matrix of image pixel values in the 0-255 range. |
s |
sigma, the Gaussian filter variance. Defaults to 2. |
low_thr |
lower threshold value of the algorithm. Defaults to 3. |
high_thr |
upper threshold value of the algorithm. Defaults to 10 |
accGrad |
logical indicating to trigger higher-order gradient |
a list with element edges which is a matrix with values 0 or 255 indicating
in the same dimension of x
. Next to that
the list also contains the input parameters s, low_thr, high_thr and accGrad,
the number of rows (nx) and columns of the image (ny) and the number of pixels which
have value 255 (pixels_nonzero).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | if(requireNamespace("pixmap") && requireNamespace("magick")){
library(pixmap)
imagelocation <- system.file("extdata", "chairs.pgm", package="image.CannyEdges")
image <- read.pnm(file = imagelocation, cellres = 1)
x <- image@grey * 255
edges <- image_canny_edge_detector(x)
edges
plot(edges)
##
## image_canny_edge_detector expects a matrix as input
## if you have a jpg/png/... convert it to pgm first or take the r/g/b channel
library(magick)
x <- image_read(system.file("extdata", "atomium.jpg", package="image.CannyEdges"))
x
image <- image_data(x, channels = "Gray")
image <- as.integer(image, transpose = TRUE)
edges <- image_canny_edge_detector(image)
plot(edges)
f <- tempfile(fileext = ".pgm")
library(magick)
x <- image_read(system.file("extdata", "atomium.jpg", package="image.CannyEdges"))
x <- image_convert(x, format = "pgm", depth = 8)
image_write(x, path = f, format = "pgm")
image <- read.pnm(f, cellres = 1)
edges <- image_canny_edge_detector(image@grey * 255)
plot(edges)
file.remove(f)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.