-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
153 lines (105 loc) · 3.21 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
output: github_document
---
[![Travis-CI Build Status](https://travis-ci.org/ThinkRstat/collage.svg?branch=master)](https://travis-ci.org/ThinkRstat/collage)
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
```{r echo = FALSE}
library(tibble)
```
Meet Tigrou
![](inst/tigrou/tigrou.jpg)
```{r}
library(collage)
library(magick)
tigrou <- image_read( system.file("tigrou", "tigrou.jpg", package = "collage") )
```
## collage
Tigrou with every 25x25 replaced by another kitty
```{r}
collage( tigrou, tiles = kittens, size = 25)
```
```{r echo = FALSE}
image_write( collage( tigrou, tiles = kittens, size = 25), path = "images/collage.png" )
```
![](images/collage.png)
with every 10x10 replaced by a useR 2017 attendee:
```{r}
collage( tigrou, tiles = useR2017, size = 10)
```
```{r echo = FALSE}
image_write( collage( tigrou, tiles = useR2017, size = 10), path = "images/collage_useR.png" )
```
![](images/collage_useR.png)
## collage_quality
A measure of the quality of the tiles.
```{r}
collage_quality( tigrou, tiles = kittens, size = 25)
```
```{r echo = FALSE}
image_write( collage_quality( tigrou, tiles = kittens, size = 25), path = "images/collage_quality.png" )
```
![](images/collage_quality.png)
## collage_grid
Showing the grid
```{r}
collage_grid( tigrou, size = 25)
```
```{r echo = FALSE}
image_write( collage_grid( tigrou, size = 25), path = "images/collage_grid.png" )
```
![](images/collage_grid.png)
## tiles
The tiles argument of these functions expect a tibble similar to the `kittens` (or `puppies`) that is shipped
with the package:
```{r}
kittens
puppies
```
Each row represent a tile, which has a given color (identified by the `red`, `green`, `blue` and `alpha` columns).
The `tile` column is a list column holding the data for the tiles.
```{r}
kittens$tile[[1]]
```
The `tiles` function can make one of these tiles tibbles:
```{r}
files <- list.files( system.file("base", package = "collage"), pattern = "jpg$", full.names = TRUE )
samples <- tiles( files, size = 25 )
samples
```
## tiles_mono
The `tiles_mono` function generates monochromatic tiles. For example, here is Tigrou
with each 25x25 square replaced by the closest R color.
```{r}
rtiles <- tiles_mono(colors())
collage( tigrou, tiles = rtiles, size = 25)
```
```{r echo = FALSE}
image_write( collage( tigrou, tiles = rtiles, size = 25), path = "images/collage_rcolors.png" )
```
![](images/collage_rcolors.png)
## tiles_animals
The `tiles_animals` function scraps data. For example, the `kittens` and
`puppies` have been generated with :
```{r, eval=FALSE}
kittens <- tiles_animals(what = "bebe,chats", pages = 1:20)
puppies <- tiles_animals(what = "bebe,chiens", pages = 1:20)
```
## histograms
Histograms are a tool used in photography to visualise brightness of images. `image_histogram_data`
measures the number of pixels for each tone (from 0 to 255) in a picture.
```{r}
image_histogram_data(tigrou)
```
Then `image_histogram_brightness` and `image_histogram_rgb` shows brightness and individual
channel histograms:
```{r histograms}
image_histogram_brightness(tigrou)
image_histogram_rgb(tigrou)
```