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:

  • added pixset class to represent sets of pixels in an image (implemented as binary images). A test on an image (e.g., im > 0) results in a pixset object. Pixsets come with many convenience functions for plotting, manipulation, morphology, etc. They are described in the "pixsets" vignette.
  • improved reductions (parmax, parmin, etc.). Most are now implemented in C++ and some run in parallel using OpenMP. A median combine operation (parmedian) has been added.
  • added load.video, save.video, make.video functions. Loading and saving videos used to be a bit fragile and platform-dependent, it should now be easier and more robust (also slower, sorry). It’s now possible to load individual frames from a video. You still need ffmpeg.
  • to load images from URLs imager now uses the downloader package, which is more robust than the previous solution
  • it’s now possible to import images from the raster package and from the magick package.
  • unified RGB representations so that every function expects RGB values to be in the [0-1] range. There used to be a conflict in expectations here, with R expecting [0-1] and CImg [0-255]. This might break existing code (albeit in minor ways).
  • new function implot, lets you draw on an image using R’s base graphics.
  • improved interactive functions for grabbing image regions (grabRect, grabLine, etc.)
  • improved grayscale conversion
  • improved plotting. The default is now to have a constant aspect ratio that matches the aspect ratio of the image.
  • save.image now accepts a quality argument when saving JPEGs.
  • native support for TIFF, now supports non-integer values in TIFF files
  • rm.alpha removes alpha channel, flatten.alpha flattens it
  • imfill now accepts colour names, e.g. imfill(10,10,val='red')
  • improved documentation and examples
  • added functions for conversion to/from CIELAB

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.

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)