Image Manipulation in R, Part 1

[This article was first published on is.R(), 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.

So, you know how to load PNG files, access their innards, and plot them as points in a scatter plot. But, is it possible to use R to do some of the awesome things you can do with Mathematica? Well, in this series of posts, I’ll introduce just a few of the things we can do with images in R — we can’t do everything that Mathematica does (at least not out of the box), and it’s not nearly as straightforward, or as fast, but if you are an R native like myself, there is still a lot you can do!

For example, the Gist below shows you how to load a .JPG file (from a URL), and convert it to a data.frame with pixel locations and colors. Then, there are a few examples of some of the very basic things you can do with that pixel data.frame, such as “make it look impressionistic” (above), filter colors in certain regions (below), and “snap” pixel colors to a rounded subset of the possible gamut (further below). Some of these are more interesting than others, but much cooler stuff is coming later in this series.

Note that the allImageURLs object is seeded with 21 URLs which are useful for the examples, but that you can easily pass your own URL to the imageLoader() function. Enjoy!

To leave a comment for the author, please follow the link and comment on their blog: is.R().

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)