Monsters
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Ooh, see the fire is sweepin’
Our very street today
Burns like a red coal carpet
Mad bull lost its way
(Gimme Shelter, The Rolling Stones)
After following this easy tutorial, you will be able to create tiled images from a photograph. You may want to use your own portrait or some other as I did. I use geom_tile
: one of my preferred geometries of ggplot
, which was the one I used in some other experiments like space invaders or Newton’s fractals. I used original photos from some of the most terrific monsters of the cinema: Frankenstein, Dracula and The Mummy. I love how rough squares create textures and sense of depth. This is Frankenstein after the transformation:
The process is quite simple:
- Load the image and convert it to grayscale. I use
imager
, a very useful and easy to use package for image processing with R. - Reduce the resolution of the image as well as its dimension. Each new (big) pixel is summarized with the mean of the grayscale values of the pixels inside it.
- Divide these average values into a number of groups using
cut
function. - Represent pixels with
ggplot
, usinggeom_tile
. There are two important parameters: size and color of lines of each tile. Both of them depend on the value of the group previously calculated in which falls the tile. The graph is composed layer by layer depending on these gropus.
This is Dracula after being tiled:
And this is The Mummy:
These are the stunning original images (I love them all):
You can find the code here: let me know if you do something with it.
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.