Skip to content

Instantly share code, notes, and snippets.

@Valexandre
Created October 9, 2019 13:06
Show Gist options
  • Save Valexandre/66bc6810dc2307145fbde8a5c2d9998b to your computer and use it in GitHub Desktop.
Save Valexandre/66bc6810dc2307145fbde8a5c2d9998b to your computer and use it in GitHub Desktop.
library(imager)
library(tidyverse)
URL1<-"1280px-CLaude_Monet_037.jpg"
IMAGE <- imager::load.image(URL1)
df1 <- as.data.frame(IMAGE,wide="c") %>% mutate(rgb.val=rgb(c.1,c.2,c.3))
df1<-df1%>%mutate(xNtile=ntile(x,60),
yNtile=ntile(y,60))%>%
group_by(xNtile,y)%>%
mutate(Xrang=rank(-x),
Xseuil=min(x))%>%
ungroup()%>%
group_by(yNtile,x)%>%
mutate(Yrang=rank(-y),
Yseuil=min(y))
df1$testX<-df1$Xrang+df1$Xseuil
df1$testy<-df1$Yrang+df1$Yseuil
df1%>%group_by(yNtile,x)%>%tally()
width<-max(df1$x)
height<-max(df1$y)
jpeg(filename = "MonetDechire.jpg", width=width, height = height, quality=100, units = "px",type="cairo")
ggplot(df1,aes(testX,testy))+geom_raster(aes(fill=rgb.val),alpha=1)+scale_fill_identity()+scale_y_reverse()+coord_fixed(ratio=1)+theme_void()
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment