-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
81 lines (58 loc) · 2.22 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "20%"
)
```
# bunny <img src="man/figures/logo.png" align="right" />
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- badges: end -->
The goal of `bunny` is to provide useful helper functions for working with `magick`.
## Installation
You can install the released version of bunny from [Github](https://www.github.com) with:
``` r
#install.packages("bunny") # not yet
remotes::install_github("dmi3kno/bunny")
```
## Pixel operations
This is a basic example which shows you how to solve a common problem:
```{r example, message=FALSE}
library(magick)
library(bunny)
## basic example code
frink <- image_read("https://jeroen.github.io/images/frink.png")
image_getpixel(frink, geometry_point(100,100))
```
Other than extracting color from individual pixels, `bunny` can also draw on images:
```{r, fig.height=5}
frink <- image_read("https://jeroen.github.io/images/frink.png")
image_plot(frink, geometry_area(50,35,80,150), "red")
image_plot(frink, geometry_point(70,70), "red")
```
## Hough lines operations
`bunny` can help you tidy up the Hough Lines mvg object, returned by `magick::image_hough_txt()`. Lets detect straight lines in the `bunny` logo.
```{r}
img <- image_read("data-raw/bunny_hex.png")
img_prep <- img %>% image_convert(type="Grayscale") %>%
image_threshold("black") %>%
image_canny() %>%
image_morphology("Close", "Diamond")
img_prep %>%
image_hough_draw(geometry="50x50+200",overlay = TRUE)
```
Hough Lines are retuned in plain text object (`mvg` format). Let's tidy up that text and make it more suitable for analysis. `bunny::tidy_hough_mvg()` returns a list, which, among other things contains data frame describing lines and another data frame describing line intersections.
```{r}
hough <- img_prep %>%
image_hough_txt(geometry="50x50+200") %>%
tidy_hough_mvg()
hough$lines_data
hough$xsect_data
```
Stay tuned for more exciting functions...