Site icon R-bloggers

New version of imager package for image processing

[This article was first published on R – dahtah, 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.

A new version of imager is now available on CRAN. This release brings a lot of new features, including a whole new set of functions dealing with pixel sets, better support for videos, new and faster reduction functions.

The most significant change is the introduction of a “pixset” class, which deals with sets of pixels (for instance, the set of all pixels with a certain brightness, the foreground, the left-hand side of an image, an ROI, etc.). The pixset class includes many tools for working with pixsets, described in a new vignette.

The following piece of code illustrates some of the new features. We take a picture of coins on a table (from scikit-image), segment the coins from the background and highlight the largest coin:

library(imager)
library(dplyr)
im <- load.example("coins")
d <- as.data.frame(im)
##Subsamble, fit a linear model to remove trend in illumination, threshold
px <- sample_n(d,1e4) %>% lm(value ~ x*y,data=.)  %>%
    predict(d) %>% { im - . } %>% threshold

##Clean up
px <- clean(px,3) %>% imager::fill(7) 
plot(im)
highlight(px)

## Split into connected components (individual coins)
pxs <- split_connected(px)
## Compute their respective area
area <- sapply(pxs,sum)
## Highlight largest coin in green
highlight(pxs[[which.max(area)]],col="green",lwd=2)

The website’s also been overhauled, and new tutorials are available. These include a tutorial on quad-trees (using recursive data structures to represent an image), imager as image editor (what’s the equivalent of a circular selection in imager? How about the bucket tool?) , image unshredding (how to shuffle an image and put it back together).

See here for a complete list.

Below, the full changelog for imager v0.40:


To leave a comment for the author, please follow the link and comment on their blog: R – dahtah.

R-bloggers.com 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.