Skip to content

Commit

Permalink
add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
yufree committed Apr 15, 2020
1 parent 6ea907f commit d1d2c64
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ LazyData: true
LinkingTo: Rcpp
Imports: Rcpp, imager, stats
RoxygenNote: 7.1.0
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
10 changes: 6 additions & 4 deletions R/io.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ getdepthmap <- function(path, cutoff = 0.5){

#' read in image and change them into magic eye
#' @param img cimg object
#' @param len length of pattern square,default 50.
#' @param shift shift of magic eye, default 0.15
#' @return NULL
#' @export

getme <- function(img,shift=0.15){
getme <- function(img,len = 50, shift=0.15){
d <- dim(img)
mask <- matrix(as.numeric(img),d[1],d[2])
i <- imager::as.cimg(mask,dim=c(d[1],d[2],d[3],1))
c1 <- matrix(stats::runif(50*50,0,1),50,50)
c1 <- matrix(stats::runif(len*len,0,1),len,len)
o <- getmagiceye(t(mask), c1, shift)
o <- t(o)
o <- imager::as.cimg(o,dim=c(d[1],d[2],d[3],1))
Expand All @@ -32,11 +33,12 @@ getme <- function(img,shift=0.15){

#' read in text
#' @param text text
#' @param cex default 20
#' @return NULL
#' @export

getmet <- function(text = 'yufree'){
getmet <- function(text = 'yufree',cex = 20){
bg <- imager::imfill(1000,1000,val=1)
o <- imager::implot(bg,text(500,500,text,cex=20))
o <- imager::implot(bg,text(500,500,text,cex=cex))
return(1-o)
}
4 changes: 3 additions & 1 deletion man/getme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/getmet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
54 changes: 54 additions & 0 deletions vignettes/MagicEye.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "Magic Eye in R"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Magic Eye in R}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup}
library(magiceyer)
```

You could use this package to generate autostereograms.

## How

- You need an image as the shape hidden in the magic eye

- Convert the image into the depthmap

- You need to define shift. 0.1-0.2 should be fine.

- Generate the autostereograms

```{r demo}
image <- getdepthmap("https://cran.r-project.org/Rlogo.jpg")
plot(image)
me <- getme(image,len = 10)
plot(me)
```

You could also generate text as hidden information in the autostereograms

```{r text}
met <- getmet(text = "Don't Panic",cex = 15)
me <- getme(met)
plot(me)
```

## Why

- [Wiki](https://en.wikipedia.org/wiki/Magic_Eye)

- [History](https://eyeondesign.aiga.org/the-hidden-history-of-magic-eye-the-optical-illusion-that-briefly-took-over-the-world/)

- [Python](https://flothesof.github.io/making-stereograms-Python.html)

0 comments on commit d1d2c64

Please sign in to comment.