finding contour lines

[This article was first published on bnosac :: open analytical helpers - bnosac :: open analytical helpers, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Finally, the R package you all have been waiting for has arrived – image.ContourDetector developed at It detects contour lines in images alongside the ‘Unsupervised Smooth Contour Detection’ algorithm available at

Have you always wanted to be able to draw like you are in art school? Let me show how to quickly do this.

example contourlines

If you want to reproduce this, the following snippets show how. Steps are as follows

1. Install the packages from CRAN


2. Get an image, put it into grey scale, pass the pixels to the function an off you go.

img <- image_read("")
mat <- image_data(img, channels = "gray")
mat <- as.integer(mat, transpose = TRUE)
mat <- drop(mat)
contourlines <- image_contour_detector(mat)
plt <- plot(contourlines)

3. If you want to have the same image as shown at the top of the article:

Put the 3 images (original, combined, contour lines only) together in 1 plot using the excellent magick R package:

plt <- image_graph(width = image_info(img)$width, height = image_info(img)$height)
plt_combined <- image_graph(width = image_info(img)$width, height = image_info(img)$height)
plot(contourlines, add = TRUE, col = "red", lwd = 5)
combi <- image_append(c(img, plt_combined, plt))
image_write(combi, "example-contourlines.png", format = "png")

To leave a comment for the author, please follow the link and comment on their blog: bnosac :: open analytical helpers - bnosac :: open analytical helpers. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)