mirror of
https://github.com/ryantimpe/brickr.git
synced 2026-01-06 05:39:34 -06:00
266 lines
26 KiB
HTML
266 lines
26 KiB
HTML
<!DOCTYPE html>
|
||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Mosaics with brickr • brickr</title>
|
||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
|
||
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
|
||
<script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||
<meta property="og:title" content="Mosaics with brickr">
|
||
<meta property="og:description" content="">
|
||
<meta property="og:image" content="http://brickr.org/logo.png">
|
||
<meta name="twitter:card" content="summary">
|
||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||
<![endif]-->
|
||
</head>
|
||
<body>
|
||
<div class="container template-article">
|
||
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
||
<div class="container">
|
||
<div class="navbar-header">
|
||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
|
||
<span class="sr-only">Toggle navigation</span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
</button>
|
||
<span class="navbar-brand">
|
||
<a class="navbar-link" href="../index.html">brickr</a>
|
||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9024</span>
|
||
</span>
|
||
</div>
|
||
|
||
<div id="navbar" class="navbar-collapse collapse">
|
||
<ul class="nav navbar-nav">
|
||
<li>
|
||
<a href="../index.html">
|
||
<span class="fa fa-home fa-lg"></span>
|
||
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../reference/index.html">Reference</a>
|
||
</li>
|
||
<li class="dropdown">
|
||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
|
||
Articles
|
||
|
||
<span class="caret"></span>
|
||
</a>
|
||
<ul class="dropdown-menu" role="menu">
|
||
<li>
|
||
<a href="../articles/graphs.html">ggplot with brickr</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/models-from-other.html">3D Models from mosaics & rayshader</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/models-from-program.html">3D Models programmatically</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/models-from-tables.html">3D models from tables</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/mosaics.html">Mosaics with brickr</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<a href="../news/index.html">Changelog</a>
|
||
</li>
|
||
</ul>
|
||
<ul class="nav navbar-nav navbar-right">
|
||
<li>
|
||
<a href="https://github.com/ryantimpe/brickr">
|
||
<span class="fa fa-github fa-lg"></span>
|
||
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<!--/.nav-collapse -->
|
||
</div>
|
||
<!--/.container -->
|
||
</div>
|
||
<!--/.navbar -->
|
||
|
||
|
||
</header><div class="row">
|
||
<div class="col-md-9 contents">
|
||
<div class="page-header toc-ignore">
|
||
<h1>Mosaics with brickr</h1>
|
||
|
||
|
||
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/mosaics.Rmd"><code>vignettes/mosaics.Rmd</code></a></small>
|
||
<div class="hidden name"><code>mosaics.Rmd</code></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<div id="getting-started" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#getting-started" class="anchor"></a>Getting started</h2>
|
||
<p>You can generate a brickr mosaic object from an image using <code><a href="../reference/image_to_mosaic.html">brickr::image_to_mosaic()</a></code>. Pass this object to <code><a href="../reference/build_mosaic.html">build_mosaic()</a></code> to construct a visualization of the mosaic.</p>
|
||
<p><img src="http://ryantimpe.com/files/mf_unicorn.PNG" width="250"></p>
|
||
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">demo_img =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/tempfile">tempfile</a></span>() </a>
|
||
<a class="sourceLine" id="cb1-2" title="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/download.file">download.file</a></span>(<span class="st">"http://ryantimpe.com/files/mf_unicorn.PNG"</span>, demo_img, <span class="dt">mode=</span><span class="st">"wb"</span>)</a>
|
||
<a class="sourceLine" id="cb1-3" title="3"></a>
|
||
<a class="sourceLine" id="cb1-4" title="4">mosaic <-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb1-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>()</a>
|
||
<a class="sourceLine" id="cb1-6" title="6"></a>
|
||
<a class="sourceLine" id="cb1-7" title="7">mosaic <span class="op">%>%</span><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/g1-1.png" width="700"></p>
|
||
<p>The default is to create a mosaic with 48 knobs (brick studs) on each side. Change this using the <code>img_size</code> input. A single value will create a square mosaic, while an array of two values represent the width and length.</p>
|
||
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb2-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dt">img_size =</span> <span class="dv">32</span>) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb2-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/g2-1.png" width="700"></p>
|
||
</div>
|
||
<div id="colors" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#colors" class="anchor"></a>Colors</h2>
|
||
<p>A key feature in <code><a href="../reference/image_to_mosaic.html">image_to_mosaic()</a></code> is the conversion of the original image into colors produced by LEGO. The default is to map each individual pixel to any of the 41 solid brick colors currently produced by LEGO useing the <a href="https://en.wikipedia.org/wiki/Color_difference#CIE94">CIE94</a> algorithm. These defaults can be changed.</p>
|
||
<div id="color-palettes" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#color-palettes" class="anchor"></a>Color palettes</h3>
|
||
<p>There are currently 2 main ways to control the color palettes to build mosaics in brickr.</p>
|
||
<ul>
|
||
<li>The <code>color_palette</code> input takes a list of pre-defined palettes to create the mosaic.</li>
|
||
<li>The <code>color_table</code> input can take a data frame of specific colors. Usually a subset of the included <code>lego_colors</code> table.</li>
|
||
</ul>
|
||
<div id="default-color-palettes" class="section level4">
|
||
<h4 class="hasAnchor">
|
||
<a href="#default-color-palettes" class="anchor"></a>Default color palettes</h4>
|
||
<p>Each of the 41 colors belongs to one of three categories. These categories are mutually exclusive and can be used together.</p>
|
||
<ul>
|
||
<li>‘universal’ colors are the most common. This list includes white/black/grays/brown and the classic yellow, red, blue, and green colors. All brick sizes should be readily available in these colors.</li>
|
||
<li>‘generic’ colors are commonly used in LEGO products, though it might be more difficult to find every brick in these colors.</li>
|
||
<li>‘special’ colors are typically reserved for certain products and it’s likely that bricks might not be actively produced in these colors.</li>
|
||
</ul>
|
||
<p>Use the <code>color_palette</code> input in the <code><a href="../reference/image_to_mosaic.html">image_to_mosaic()</a></code> function to limit the bricks used to any combination of these three categories.</p>
|
||
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">p1 <-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb3-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_palette =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">'universal'</span>, <span class="st">'generic'</span>)) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb3-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="st">"universal & generic"</span>)</a>
|
||
<a class="sourceLine" id="cb3-4" title="4"></a>
|
||
<a class="sourceLine" id="cb3-5" title="5">p2 <-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb3-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_palette =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">'universal'</span>)) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb3-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="st">"universal"</span>)</a>
|
||
<a class="sourceLine" id="cb3-8" title="8"></a>
|
||
<a class="sourceLine" id="cb3-9" title="9">gridExtra<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/gridExtra/topics/arrangeGrob">grid.arrange</a></span>(p1, p2, <span class="dt">layout_matrix =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">matrix</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">ncol=</span><span class="dv">2</span>))</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/c_palettes-1.png" width="576"></p>
|
||
</div>
|
||
<div id="grayscale" class="section level4">
|
||
<h4 class="hasAnchor">
|
||
<a href="#grayscale" class="anchor"></a>Grayscale</h4>
|
||
<p>For grayscale or black and white mosaics, use <code>color_palette = 'bw'</code>. This creates the mosaic by measuring the brightness of each pixel in the image and mapping it one of the four shades of gray. Use the contrast input to adjust the relative brightness of the pixels.</p>
|
||
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb4-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_palette =</span> <span class="st">'bw'</span>, <span class="dt">contrast =</span> <span class="fl">1.1</span>)<span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb4-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/c_bw-1.png" width="700"></p>
|
||
</div>
|
||
<div id="custom-color-palettes" class="section level4">
|
||
<h4 class="hasAnchor">
|
||
<a href="#custom-color-palettes" class="anchor"></a>Custom color palettes</h4>
|
||
<p>With the <code>color_table</code> input, it is possible to restrict the colors in the mosaic to a custom palette.</p>
|
||
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1"><span class="co">#Remove blue and azure colors from lego_colors</span></a>
|
||
<a class="sourceLine" id="cb5-2" title="2">lego_colors_wo_blue <-<span class="st"> </span>lego_colors <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb5-3" title="3"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(<span class="op">!</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/grep">grepl</a></span>(<span class="st">"blue|azur"</span>, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/chartr">tolower</a></span>(Color)))</a>
|
||
<a class="sourceLine" id="cb5-4" title="4"></a>
|
||
<a class="sourceLine" id="cb5-5" title="5">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb5-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_table =</span> lego_colors_wo_blue)<span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb5-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="st">"Mosaic without blue or azur"</span>)</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/c_custom-1.png" width="700"></p>
|
||
</div>
|
||
</div>
|
||
<div id="color-matching" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#color-matching" class="anchor"></a>Color matching</h3>
|
||
<p>brickr uses the <a href="https://cran.r-project.org/web/packages/farver/index.html"><code>farver</code></a> package to match image colors to the subset of LEGO colors. Technical details of the different algorithms can be found on <a href="https://en.wikipedia.org/wiki/Color_difference">Wikipedia</a>.</p>
|
||
<p>The default algorithm is ‘cie94’, though the other farver options are available using the <code>method</code> input. The farver ‘euclidean’ is not very accurate, so ‘brickr_classic’ returns a manually calculated version for Euclidean RGB distance matching.</p>
|
||
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"cie94"</span>, <span class="st">"cie2000"</span>, <span class="st">"euclidean"</span>, <span class="st">"brickr_classic"</span>) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb6-2" title="2"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map.html">map</a></span>(<span class="op">~</span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb6-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">24</span>, <span class="dt">method =</span>.x) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb6-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> .x )) -><span class="st"> </span>mosaics_by_method</a>
|
||
<a class="sourceLine" id="cb6-5" title="5"></a>
|
||
<a class="sourceLine" id="cb6-6" title="6">gridExtra<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/gridExtra/topics/arrangeGrob">grid.arrange</a></span>(<span class="dt">grobs =</span> mosaics_by_method, <span class="dt">layout_matrix =</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/cbind">rbind</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>,<span class="dv">2</span>),<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">3</span>,<span class="dv">4</span>)))</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/c_methods-1.png" width="480"></p>
|
||
</div>
|
||
<div id="dithering" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#dithering" class="anchor"></a>Dithering</h3>
|
||
<p>When rendering a mosaic from a photographic with many shades of similar colors, using <a href="https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering">dithering</a> by setting <code>dithering = TRUE</code> will help to add texture to the mosaic and avoid large areas of the same color. This works particularly well for large mosaics, but is purely a stylist preference.</p>
|
||
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">gg_img =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/tempfile">tempfile</a></span>() </a>
|
||
<a class="sourceLine" id="cb7-2" title="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/download.file">download.file</a></span>(<span class="st">"http://ryantimpe.com/files/goldengirls.JPG"</span>, gg_img, <span class="dt">mode=</span><span class="st">"wb"</span>)</a>
|
||
<a class="sourceLine" id="cb7-3" title="3"></a>
|
||
<a class="sourceLine" id="cb7-4" title="4"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="ot">FALSE</span>, <span class="ot">TRUE</span>) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb7-5" title="5"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map.html">map</a></span>(<span class="op">~</span>jpeg<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/jpeg/topics/readJPEG">readJPEG</a></span>(gg_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb7-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dt">dithering =</span> .x) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb7-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/paste">paste</a></span>(<span class="st">"dithering ="</span>, .x))) -><span class="st"> </span>mosaics_by_dither</a>
|
||
<a class="sourceLine" id="cb7-8" title="8"></a>
|
||
<a class="sourceLine" id="cb7-9" title="9">gridExtra<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/gridExtra/topics/arrangeGrob">grid.arrange</a></span>(<span class="dt">grobs =</span> mosaics_by_dither, <span class="dt">layout_matrix =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">matrix</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">ncol=</span><span class="dv">2</span>))</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/c_dither-1.png" width="576"></p>
|
||
</div>
|
||
<div id="other-color-options" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#other-color-options" class="anchor"></a>Other color options</h3>
|
||
<p>The input <code>brightness</code> can be used to scale up or down the RGB values of the image before color matching. The default is 1.</p>
|
||
</div>
|
||
</div>
|
||
<div id="d-mosaics" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#d-mosaics" class="anchor"></a>3D Mosaics</h2>
|
||
<p>With <a href="https://www.rayshader.com/">rayshader</a> installed, passing the mosaic object to <code><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic()</a></code> will render a 3D object, stacking layers of bricks on each other to create an elevated mosaic. By default, the lightest color bricks will be on top, but this can be changed using the <code>highest_el = 'dark'</code> option.</p>
|
||
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(demo_img) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb8-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb8-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic</a></span>(<span class="dt">highest_el =</span> <span class="st">"dark"</span>) <span class="op">%>%</span><span class="st"> </span></a>
|
||
<a class="sourceLine" id="cb8-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_type =</span> <span class="st">"plate"</span>)</a>
|
||
<a class="sourceLine" id="cb8-5" title="5"></a>
|
||
<a class="sourceLine" id="cb8-6" title="6">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_camera">render_camera</a></span>(<span class="dt">theta =</span> <span class="dv">15</span>)</a>
|
||
<a class="sourceLine" id="cb8-7" title="7">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
|
||
<p><img src="mosaics_files/figure-html/c_threed-1.png" width="700"></p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
||
<div id="tocnav">
|
||
<h2 class="hasAnchor">
|
||
<a href="#tocnav" class="anchor"></a>Contents</h2>
|
||
<ul class="nav nav-pills nav-stacked">
|
||
<li><a href="#getting-started">Getting started</a></li>
|
||
<li><a href="#colors">Colors</a></li>
|
||
<li><a href="#d-mosaics">3D Mosaics</a></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
<footer><div class="copyright">
|
||
<p>Developed by Ryan Timpe.</p>
|
||
</div>
|
||
|
||
<div class="pkgdown">
|
||
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
|
||
</div>
|
||
</footer>
|
||
</div>
|
||
|
||
|
||
|
||
</body>
|
||
</html>
|