Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dmi3kno/bunny

Magick Helper
https://github.com/dmi3kno/bunny

Last synced: 3 months ago
JSON representation

Magick Helper

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "20%"
)
```
# bunny

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

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...